2 text-item.cc -- implement Text_item
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>
13 #include "text-item.hh"
14 #include "font-interface.hh"
15 #include "virtual-font-metric.hh"
16 #include "paper-def.hh"
17 #include "scaled-font-metric.hh"
19 MAKE_SCHEME_CALLBACK (Text_item, interpret_string, 4)
21 Text_item::interpret_string (SCM paper, SCM props, SCM encoding, SCM markup)
23 Paper_def *pap = unsmob_paper (paper);
25 SCM_ASSERT_TYPE(pap, paper, SCM_ARG1, __FUNCTION__, "Paper definition");
26 SCM_ASSERT_TYPE(ly_c_string_p (markup), markup, SCM_ARG3, __FUNCTION__, "string");
27 SCM_ASSERT_TYPE(encoding == SCM_EOL
28 || ly_c_symbol_p (encoding), encoding, SCM_ARG2, __FUNCTION__, "symbol");
30 String str = ly_scm2string (markup);
31 Font_metric *fm = select_encoded_font (pap, props, encoding);
35 if (Modified_font_metric* mf = dynamic_cast<Modified_font_metric*> (fm))
37 lst = scm_list_3 (ly_symbol2scm ("text"),
41 b = mf->text_dimension (str);
46 programming_error ("Must have Modified_font_metric for text.");
49 return Stencil (b, lst).smobbed_copy ();
53 MAKE_SCHEME_CALLBACK (Text_item, interpret_markup, 3)
55 Text_item::interpret_markup (SCM paper, SCM props, SCM markup)
57 if (ly_c_string_p (markup))
58 return interpret_string (paper, props, SCM_EOL, markup);
59 else if (ly_c_pair_p (markup))
61 SCM func = ly_car (markup);
62 SCM args = ly_cdr (markup);
63 if (!markup_p (markup))
64 programming_error ("Markup head has no markup signature.");
66 return scm_apply_2 (func, paper, props, args);
71 MAKE_SCHEME_CALLBACK (Text_item,print,1);
73 Text_item::print (SCM grob)
75 Grob *me = unsmob_grob (grob);
77 SCM t = me->get_property ("text");
78 SCM chain = Font_interface::text_font_alist_chain (me);
79 return interpret_markup (me->get_paper ()->self_scm (), chain, t);
84 Ugh. Duplicated from Scheme.
87 Text_item::markup_p (SCM x)
92 && SCM_BOOL_F != scm_object_property (ly_car (x), ly_symbol2scm ("markup-signature")));
95 ADD_INTERFACE (Text_item,"text-interface",
96 "A scheme markup text, see @usermanref{Text-markup}.",
97 "text baseline-skip word-space");