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>
14 #include "text-item.hh"
15 #include "font-interface.hh"
16 #include "virtual-font-metric.hh"
17 #include "output-def.hh"
18 #include "modified-font-metric.hh"
19 #include "ly-module.hh"
21 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 4)
23 Text_interface::interpret_string (SCM paper_smob,
24 SCM props, SCM input_encoding, SCM markup)
26 Output_def *paper = unsmob_output_def (paper_smob);
28 SCM_ASSERT_TYPE (paper, paper_smob, SCM_ARG1,
29 __FUNCTION__, "Paper definition");
30 SCM_ASSERT_TYPE (scm_is_string (markup), markup, SCM_ARG3,
31 __FUNCTION__, "string");
32 SCM_ASSERT_TYPE (input_encoding == SCM_EOL || scm_is_symbol (input_encoding),
33 input_encoding, SCM_ARG2, __FUNCTION__, "symbol");
35 String str = ly_scm2string (markup);
36 if (!scm_is_symbol (input_encoding))
38 SCM enc = paper->lookup_variable (ly_symbol2scm ("inputencoding"));
39 if (scm_is_string (enc))
40 input_encoding = scm_string_to_symbol (enc);
41 else if (scm_is_symbol (enc))
45 Font_metric *fm = select_encoded_font (paper, props, input_encoding);
49 if (Modified_font_metric* mf = dynamic_cast<Modified_font_metric*> (fm))
51 lst = scm_list_3 (ly_symbol2scm ("text"),
55 b = mf->text_dimension (str);
60 programming_error ("Must have Modified_font_metric for text.");
61 scm_display (fm->description_, scm_current_error_port ());
64 return Stencil (b, lst).smobbed_copy ();
68 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3)
70 Text_interface::interpret_markup (SCM paper_smob, SCM props, SCM markup)
72 if (scm_is_string (markup))
73 return interpret_string (paper_smob, props, SCM_EOL, markup);
74 else if (ly_c_pair_p (markup))
76 SCM func = ly_car (markup);
77 SCM args = ly_cdr (markup);
78 if (!markup_p (markup))
79 programming_error ("Markup head has no markup signature.");
81 return scm_apply_2 (func, paper_smob, props, args);
86 MAKE_SCHEME_CALLBACK (Text_interface,print,1);
88 Text_interface::print (SCM grob)
90 Grob *me = unsmob_grob (grob);
92 SCM t = me->get_property ("text");
93 SCM chain = Font_interface::text_font_alist_chain (me);
94 return interpret_markup (me->get_paper ()->self_scm (), chain, t);
97 /* Ugh. Duplicated from Scheme. */
99 Text_interface::markup_p (SCM x)
101 return (scm_is_string (x)
104 != scm_object_property (ly_car (x),
105 ly_symbol2scm ("markup-signature"))));
108 ADD_INTERFACE (Text_interface,"text-interface",
109 "A scheme markup text, see @usermanref{Text-markup}.",
110 "text baseline-skip word-space");