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"
22 #include "ly-module.hh"
25 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 4)
27 Text_interface::interpret_string (SCM layout_smob,
28 SCM props, SCM input_encoding, SCM markup)
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);
40 if (output_format_global != "tex"
41 && output_format_global != "texstr")
43 Font_metric *fm = select_pango_font (layout, props);
44 return fm->text_stencil (str).smobbed_copy ();
48 SCM_ASSERT_TYPE (input_encoding == SCM_EOL || scm_is_symbol (input_encoding),
49 input_encoding, SCM_ARG2, __FUNCTION__, "symbol");
51 if (!scm_is_symbol (input_encoding))
53 SCM enc = layout->lookup_variable (ly_symbol2scm ("inputencoding"));
54 if (scm_is_string (enc))
55 input_encoding = scm_string_to_symbol (enc);
56 else if (scm_is_symbol (enc))
60 Font_metric *fm = select_encoded_font (layout, props, input_encoding);
62 return fm->text_stencil (str).smobbed_copy();
65 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3)
67 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
69 if (scm_is_string (markup))
70 return interpret_string (layout_smob, props, SCM_EOL, markup);
71 else if (scm_is_pair (markup))
73 SCM func = scm_car (markup);
74 SCM args = scm_cdr (markup);
75 if (!markup_p (markup))
76 programming_error ("Markup head has no markup signature.");
78 return scm_apply_2 (func, layout_smob, props, args);
82 programming_error ("Is not a markup: ");
83 scm_display (markup, scm_current_error_port());
86 b[X_AXIS].set_empty();
87 b[Y_AXIS].set_empty();
89 Stencil s(b, SCM_EOL);
90 return s.smobbed_copy();
94 MAKE_SCHEME_CALLBACK (Text_interface,print,1);
96 Text_interface::print (SCM grob)
98 Grob *me = unsmob_grob (grob);
100 SCM t = me->get_property ("text");
101 SCM chain = Font_interface::text_font_alist_chain (me);
102 return interpret_markup (me->get_layout ()->self_scm (), chain, t);
105 /* Ugh. Duplicated from Scheme. */
107 Text_interface::markup_p (SCM x)
109 return (scm_is_string (x)
112 != scm_object_property (scm_car (x),
113 ly_symbol2scm ("markup-signature"))));
116 ADD_INTERFACE (Text_interface,"text-interface",
117 "A scheme markup text, see @usermanref{Text-markup}.",
118 "text baseline-skip word-space");