2 text-item.cc -- implement Text_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "text-item.hh"
16 #include "pango-font.hh"
19 #include "font-interface.hh"
20 #include "output-def.hh"
21 #include "modified-font-metric.hh"
24 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3)
26 Text_interface::interpret_string (SCM layout_smob,
30 Output_def *layout = unsmob_output_def (layout_smob);
32 SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
33 __FUNCTION__, "Layout definition");
34 SCM_ASSERT_TYPE (scm_is_string (markup), markup, SCM_ARG3,
35 __FUNCTION__, "string");
37 String str = ly_scm2string (markup);
39 Font_metric *fm = select_encoded_font (layout, props);
40 return fm->text_stencil (str).smobbed_copy ();
44 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3)
46 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
48 if (scm_is_string (markup))
49 return interpret_string (layout_smob, props, markup);
50 else if (scm_is_pair (markup))
52 SCM func = scm_car (markup);
53 SCM args = scm_cdr (markup);
54 if (!markup_p (markup))
55 programming_error ("Markup head has no markup signature.");
57 return scm_apply_2 (func, layout_smob, props, args);
61 programming_error ("Is not a markup: ");
62 scm_display (markup, scm_current_error_port());
65 b[X_AXIS].set_empty();
66 b[Y_AXIS].set_empty();
68 Stencil s(b, SCM_EOL);
69 return s.smobbed_copy();
73 MAKE_SCHEME_CALLBACK (Text_interface,print,1);
75 Text_interface::print (SCM grob)
77 Grob *me = unsmob_grob (grob);
79 SCM t = me->get_property ("text");
80 SCM chain = Font_interface::text_font_alist_chain (me);
81 return interpret_markup (me->get_layout ()->self_scm (), chain, t);
84 /* Ugh. Duplicated from Scheme. */
86 Text_interface::markup_p (SCM x)
88 return (scm_is_string (x)
91 != scm_object_property (scm_car (x),
92 ly_symbol2scm ("markup-signature"))));
95 ADD_INTERFACE (Text_interface,"text-interface",
96 "A scheme markup text, see @usermanref{Text-markup}.",
97 "text baseline-skip word-space");