2 text-interface.cc -- implement Text_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2006 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 (Text_interface, interpret_markup, 3);
43 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
45 if (scm_is_string (markup))
46 return interpret_string (layout_smob, props, markup);
47 else if (scm_is_pair (markup))
49 SCM func = scm_car (markup);
50 SCM args = scm_cdr (markup);
51 if (!is_markup (markup))
52 programming_error ("markup head has no markup signature");
54 return scm_apply_2 (func, layout_smob, props, args);
58 programming_error ("Object is not a markup. ");
59 scm_puts ("This object should be a markup: ", scm_current_error_port ());
60 scm_display (markup, scm_current_error_port ());
61 scm_puts ("\n", 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->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,
95 "A scheme markup text, see @usermanref{Text markup}.",