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 "font-interface.hh"
17 #include "virtual-font-metric.hh"
18 #include "output-def.hh"
19 #include "modified-font-metric.hh"
20 #include "ly-module.hh"
22 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 4)
24 Text_interface::interpret_string (SCM layout_smob,
25 SCM props, SCM input_encoding, SCM markup)
27 Output_def *layout = unsmob_output_def (layout_smob);
29 SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
30 __FUNCTION__, "Layout definition");
31 SCM_ASSERT_TYPE (scm_is_string (markup), markup, SCM_ARG3,
32 __FUNCTION__, "string");
33 SCM_ASSERT_TYPE (input_encoding == SCM_EOL || scm_is_symbol (input_encoding),
34 input_encoding, SCM_ARG2, __FUNCTION__, "symbol");
36 String str = ly_scm2string (markup);
37 if (!scm_is_symbol (input_encoding))
39 SCM enc = layout->lookup_variable (ly_symbol2scm ("inputencoding"));
40 if (scm_is_string (enc))
41 input_encoding = scm_string_to_symbol (enc);
42 else if (scm_is_symbol (enc))
46 Font_metric *fm = select_encoded_font (layout, props, input_encoding);
50 if (Modified_font_metric* mf = dynamic_cast<Modified_font_metric*> (fm))
52 lst = scm_list_3 (ly_symbol2scm ("text"),
56 b = mf->text_dimension (str);
61 programming_error ("Must have Modified_font_metric for text.");
62 scm_display (fm->description_, scm_current_error_port ());
65 return Stencil (b, lst).smobbed_copy ();
69 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3)
71 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
73 if (scm_is_string (markup))
74 return interpret_string (layout_smob, props, SCM_EOL, markup);
75 else if (scm_is_pair (markup))
77 SCM func = scm_car (markup);
78 SCM args = scm_cdr (markup);
79 if (!markup_p (markup))
80 programming_error ("Markup head has no markup signature.");
82 return scm_apply_2 (func, layout_smob, props, args);
87 MAKE_SCHEME_CALLBACK (Text_interface,print,1);
89 Text_interface::print (SCM grob)
91 Grob *me = unsmob_grob (grob);
93 SCM t = me->get_property ("text");
94 SCM chain = Font_interface::text_font_alist_chain (me);
95 return interpret_markup (me->get_layout ()->self_scm (), chain, t);
98 /* Ugh. Duplicated from Scheme. */
100 Text_interface::markup_p (SCM x)
102 return (scm_is_string (x)
105 != scm_object_property (scm_car (x),
106 ly_symbol2scm ("markup-signature"))));
109 ADD_INTERFACE (Text_interface,"text-interface",
110 "A scheme markup text, see @usermanref{Text-markup}.",
111 "text baseline-skip word-space");