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"
22 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3);
24 Text_interface::interpret_string (SCM layout_smob,
28 Output_def *layout = unsmob_output_def (layout_smob);
30 SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
31 __FUNCTION__, "Layout definition");
32 SCM_ASSERT_TYPE (scm_is_string (markup), markup, SCM_ARG3,
33 __FUNCTION__, "string");
35 string str = ly_scm2string (markup);
37 Font_metric *fm = select_encoded_font (layout, props);
38 return fm->word_stencil (str).smobbed_copy ();
41 MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Text_interface, interpret_markup, 3, 0,
42 "Convert a text markup into a stencil. "
43 "Takes 3 arguments, @var{layout}, @var{props} and @var{markup}. "
45 "@var{layout} is a @code{\\layout} block; it may be obtained from a grob with "
46 "@code{ly:grob-layout}. @var{props} is a alist chain, ie. a list of alists. "
47 "This is typically obtained with "
48 "@code{(ly:grob-alist-chain (ly:layout-lookup layout 'text-font-defaults))}. "
49 "@var{markup} is the markup text to be processed. "
52 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
54 if (scm_is_string (markup))
55 return interpret_string (layout_smob, props, markup);
56 else if (scm_is_pair (markup))
58 SCM func = scm_car (markup);
59 SCM args = scm_cdr (markup);
60 if (!is_markup (markup))
61 programming_error ("markup head has no markup signature");
63 return scm_apply_2 (func, layout_smob, props, args);
67 programming_error ("Object is not a markup. ");
68 scm_puts ("This object should be a markup: ", scm_current_error_port ());
69 scm_display (markup, scm_current_error_port ());
70 scm_puts ("\n", scm_current_error_port ());
73 b[X_AXIS].set_empty ();
74 b[Y_AXIS].set_empty ();
76 Stencil s (b, SCM_EOL);
77 return s.smobbed_copy ();
81 MAKE_SCHEME_CALLBACK (Text_interface, print, 1);
83 Text_interface::print (SCM grob)
85 Grob *me = unsmob_grob (grob);
87 SCM t = me->get_property ("text");
88 SCM chain = Font_interface::text_font_alist_chain (me);
89 return interpret_markup (me->layout ()->self_scm (), chain, t);
92 /* Ugh. Duplicated from Scheme. */
94 Text_interface::is_markup (SCM x)
96 return (scm_is_string (x)
99 != scm_object_property (scm_car (x),
100 ly_symbol2scm ("markup-signature"))));
103 ADD_INTERFACE (Text_interface,
104 "A scheme markup text, see @usermanref{Text markup} and "
105 "@usermanref{New markup command definition}. "
107 "There are two important commands: ly:text-interface::print, which is a "
108 "grob callback, and ly:text-interface::interpret-markup ",