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"
17 #include "pango-font.hh"
20 #include "font-interface.hh"
21 #include "output-def.hh"
22 #include "modified-font-metric.hh"
24 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3);
26 Text_interface::interpret_string (SCM layout_smob,
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);
39 Font_metric *fm = select_encoded_font (layout, props);
40 return fm->text_stencil (str).smobbed_copy ();
43 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3);
45 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
47 if (scm_is_string (markup))
48 return interpret_string (layout_smob, props, markup);
49 else if (scm_is_pair (markup))
51 SCM func = scm_car (markup);
52 SCM args = scm_cdr (markup);
53 if (!is_markup (markup))
54 programming_error ("markup head has no markup signature");
56 return scm_apply_2 (func, layout_smob, props, args);
60 programming_error ("not a markup: ");
61 scm_display (markup, scm_current_error_port ());
64 b[X_AXIS].set_empty ();
65 b[Y_AXIS].set_empty ();
67 Stencil s (b, SCM_EOL);
68 return s.smobbed_copy ();
72 MAKE_SCHEME_CALLBACK (Text_interface, print, 1);
74 Text_interface::print (SCM grob)
76 Grob *me = unsmob_grob (grob);
78 SCM t = me->get_property ("text");
79 SCM chain = Font_interface::text_font_alist_chain (me);
80 return interpret_markup (me->get_layout ()->self_scm (), chain, t);
83 /* Ugh. Duplicated from Scheme. */
85 Text_interface::is_markup (SCM x)
87 return (scm_is_string (x)
90 != scm_object_property (scm_car (x),
91 ly_symbol2scm ("markup-signature"))));
94 ADD_INTERFACE (Text_interface, "text-interface",
95 "A scheme markup text, see @usermanref{Text markup}.",