2 text-interface.cc -- implement Text_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "text-interface.hh"
15 #include "pango-font.hh"
18 #include "font-interface.hh"
19 #include "output-def.hh"
20 #include "modified-font-metric.hh"
23 replace_whitespace (string *str)
26 vsize n = str->size ();
33 if ((cur & 0x11100000) == 0x11100000)
35 else if ((cur & 0x11000000) == 0x11000000)
37 else if (cur & 0x10000000)
38 programming_error ("invalid utf-8 string");
40 /* avoid the locale-dependent isspace */
41 if (cur == '\n' || cur == '\t' || cur == '\v')
48 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3);
50 Text_interface::interpret_string (SCM layout_smob,
54 LY_ASSERT_SMOB (Output_def, layout_smob, 1);
55 LY_ASSERT_TYPE (scm_is_string, markup, 3);
57 string str = ly_scm2string (markup);
58 Output_def *layout = unsmob_output_def (layout_smob);
59 Font_metric *fm = select_encoded_font (layout, props);
61 replace_whitespace (&str);
62 return fm->word_stencil (str).smobbed_copy ();
65 MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Text_interface, interpret_markup, 3, 0,
66 "Convert a text markup into a stencil."
67 " Takes three arguments, @var{layout}, @var{props}, and @var{markup}.\n"
69 "@var{layout} is a @code{\\layout} block; it may be obtained from a grob with"
70 " @code{ly:grob-layout}. @var{props} is a alist chain, ie. a list of alists."
71 " This is typically obtained with"
72 " @code{(ly:grob-alist-chain (ly:layout-lookup layout 'text-font-defaults))}."
73 " @var{markup} is the markup text to be processed.");
75 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
77 if (scm_is_string (markup))
78 return interpret_string (layout_smob, props, markup);
79 else if (scm_is_pair (markup))
81 SCM func = scm_car (markup);
82 SCM args = scm_cdr (markup);
83 if (!is_markup (markup))
84 programming_error ("markup head has no markup signature");
86 return scm_apply_2 (func, layout_smob, props, args);
90 programming_error ("Object is not a markup. ");
91 scm_puts ("This object should be a markup: ", scm_current_error_port ());
92 scm_display (markup, scm_current_error_port ());
93 scm_puts ("\n", scm_current_error_port ());
96 b[X_AXIS].set_empty ();
97 b[Y_AXIS].set_empty ();
99 Stencil s (b, SCM_EOL);
100 return s.smobbed_copy ();
104 MAKE_SCHEME_CALLBACK (Text_interface, print, 1);
106 Text_interface::print (SCM grob)
108 Grob *me = unsmob_grob (grob);
110 SCM t = me->get_property ("text");
111 SCM chain = Font_interface::text_font_alist_chain (me);
112 return interpret_markup (me->layout ()->self_scm (), chain, t);
115 /* Ugh. Duplicated from Scheme. */
117 Text_interface::is_markup (SCM x)
119 return (scm_is_string (x)
122 != scm_object_property (scm_car (x),
123 ly_symbol2scm ("markup-signature"))));
127 Text_interface::is_markup_list (SCM x)
129 SCM music_list_p = ly_lily_module_constant ("markup-list?");
130 return scm_is_true (scm_call_1 (music_list_p, x));
134 ADD_INTERFACE (Text_interface,
135 "A scheme markup text, see @ruser{Text markup} and "
136 "@ruser{New markup command definition}. "
138 "There are two important commands: ly:text-interface::print, which is a "
139 "grob callback, and ly:text-interface::interpret-markup ",