2 text-interface.cc -- implement Text_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "text-interface.hh"
16 #include "pango-font.hh"
19 #include "font-interface.hh"
20 #include "output-def.hh"
21 #include "modified-font-metric.hh"
23 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3);
25 Text_interface::interpret_string (SCM layout_smob,
29 Output_def *layout = unsmob_output_def (layout_smob);
31 SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
32 __FUNCTION__, "Layout definition");
33 SCM_ASSERT_TYPE (scm_is_string (markup), markup, SCM_ARG3,
34 __FUNCTION__, "string");
36 String str = ly_scm2string (markup);
38 Font_metric *fm = select_encoded_font (layout, props);
39 return fm->text_stencil (str).smobbed_copy ();
42 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3);
44 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
46 if (scm_is_string (markup))
47 return interpret_string (layout_smob, props, markup);
48 else if (scm_is_pair (markup))
50 SCM func = scm_car (markup);
51 SCM args = scm_cdr (markup);
52 if (!is_markup (markup))
53 programming_error ("markup head has no markup signature");
55 return scm_apply_2 (func, layout_smob, props, args);
59 programming_error ("not a markup: ");
60 scm_display (markup, scm_current_error_port ());
63 b[X_AXIS].set_empty ();
64 b[Y_AXIS].set_empty ();
66 Stencil s (b, SCM_EOL);
67 return s.smobbed_copy ();
71 MAKE_SCHEME_CALLBACK (Text_interface, print, 1);
73 Text_interface::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_layout ()->self_scm (), chain, t);
82 /* Ugh. Duplicated from Scheme. */
84 Text_interface::is_markup (SCM x)
86 return (scm_is_string (x)
89 != scm_object_property (scm_car (x),
90 ly_symbol2scm ("markup-signature"))));
93 ADD_INTERFACE (Text_interface, "text-interface",
94 "A scheme markup text, see @usermanref{Text markup}.",
95 "text baseline-skip word-space");