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>
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_item, interpret_string, 4)
23 Text_item::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 (ly_c_string_p (markup), markup, SCM_ARG3,
31 __FUNCTION__, "string");
32 SCM_ASSERT_TYPE (input_encoding == SCM_EOL || ly_c_symbol_p (input_encoding),
33 input_encoding, SCM_ARG2, __FUNCTION__, "symbol");
35 String str = ly_scm2string (markup);
36 if (!ly_c_symbol_p (input_encoding))
38 /* FIXME: input_encoding is set in *book*_paper
42 1. produce a bookpaper from a paper.
43 2. add BOOKPAPER parameter to all callers, ie, all MARKUPs. */
45 programming_error ("FIXME: looking up input_encoding in paper");
46 programming_error ("as a workaround, set inputencoding in your \\paper block");
47 SCM var = ly_module_lookup (paper->scope_,
48 ly_symbol2scm ("inputencoding"));
49 if (var != SCM_BOOL_F)
50 input_encoding = scm_variable_ref (var);
54 Font_metric *fm = select_encoded_font (paper, props, input_encoding);
58 if (Modified_font_metric* mf = dynamic_cast<Modified_font_metric*> (fm))
60 lst = scm_list_3 (ly_symbol2scm ("text"),
64 b = mf->text_dimension (str);
69 programming_error ("Must have Modified_font_metric for text.");
70 scm_display (fm->description_, scm_current_error_port ());
73 return Stencil (b, lst).smobbed_copy ();
77 MAKE_SCHEME_CALLBACK (Text_item, interpret_markup, 3)
79 Text_item::interpret_markup (SCM paper_smob, SCM props, SCM markup)
81 if (ly_c_string_p (markup))
82 return interpret_string (paper_smob, props, SCM_EOL, markup);
83 else if (ly_c_pair_p (markup))
85 SCM func = ly_car (markup);
86 SCM args = ly_cdr (markup);
87 if (!markup_p (markup))
88 programming_error ("Markup head has no markup signature.");
90 return scm_apply_2 (func, paper_smob, props, args);
95 MAKE_SCHEME_CALLBACK (Text_item,print,1);
97 Text_item::print (SCM grob)
99 Grob *me = unsmob_grob (grob);
101 SCM t = me->get_property ("text");
102 SCM chain = Font_interface::text_font_alist_chain (me);
103 return interpret_markup (me->get_paper ()->self_scm (), chain, t);
106 /* Ugh. Duplicated from Scheme. */
108 Text_item::markup_p (SCM x)
110 return (ly_c_string_p (x)
113 != scm_object_property (ly_car (x),
114 ly_symbol2scm ("markup-signature"))));
117 ADD_INTERFACE (Text_item,"text-interface",
118 "A scheme markup text, see @usermanref{Text-markup}.",
119 "text baseline-skip word-space");