]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-interface.cc
* input/regression/markup-arrows.ly: new file.
[lilypond.git] / lily / text-interface.cc
1 /*
2   text-interface.cc -- implement Text_interface
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "text-interface.hh"
11
12 #include <math.h>
13
14 #include "main.hh"
15 #include "config.hh"
16 #include "pango-font.hh"
17 #include "warn.hh"
18 #include "grob.hh"
19 #include "font-interface.hh"
20 #include "output-def.hh"
21 #include "modified-font-metric.hh"
22
23 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3);
24 SCM
25 Text_interface::interpret_string (SCM layout_smob,
26                                   SCM props,
27                                   SCM markup)
28 {
29   Output_def *layout = unsmob_output_def (layout_smob);
30
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");
35
36   String str = ly_scm2string (markup);
37
38   Font_metric *fm = select_encoded_font (layout, props);
39   return fm->text_stencil (str).smobbed_copy ();
40 }
41
42 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3);
43 SCM
44 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
45 {
46   if (scm_is_string (markup))
47     return interpret_string (layout_smob, props, markup);
48   else if (scm_is_pair (markup))
49     {
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");
54
55       return scm_apply_2 (func, layout_smob, props, args);
56     }
57   else
58     {
59       programming_error ("not a markup: ");
60       scm_display (markup, scm_current_error_port ());
61       assert (false);
62       Box b;
63       b[X_AXIS].set_empty ();
64       b[Y_AXIS].set_empty ();
65
66       Stencil s (b, SCM_EOL);
67       return s.smobbed_copy ();
68     }
69 }
70
71 MAKE_SCHEME_CALLBACK (Text_interface, print, 1);
72 SCM
73 Text_interface::print (SCM grob)
74 {
75   Grob *me = unsmob_grob (grob);
76
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);
80 }
81
82 /* Ugh. Duplicated from Scheme.  */
83 bool
84 Text_interface::is_markup (SCM x)
85 {
86   return (scm_is_string (x)
87           || (scm_is_pair (x)
88               && SCM_BOOL_F
89               != scm_object_property (scm_car (x),
90                                       ly_symbol2scm ("markup-signature"))));
91 }
92
93 ADD_INTERFACE (Text_interface, "text-interface",
94                "A scheme markup text, see @usermanref{Text markup}.",
95                "text baseline-skip word-space");
96