]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-interface.cc
c249052da58a9429d67050fc66e2496fb0848bfa
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "text-interface.hh"
11
12
13 #include "main.hh"
14 #include "config.hh"
15 #include "pango-font.hh"
16 #include "warn.hh"
17 #include "grob.hh"
18 #include "font-interface.hh"
19 #include "output-def.hh"
20 #include "modified-font-metric.hh"
21
22 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3);
23 SCM
24 Text_interface::interpret_string (SCM layout_smob,
25                                   SCM props,
26                                   SCM markup)
27 {
28   Output_def *layout = unsmob_output_def (layout_smob);
29
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");
34
35   string str = ly_scm2string (markup);
36
37   Font_metric *fm = select_encoded_font (layout, props);
38   return fm->word_stencil (str).smobbed_copy ();
39 }
40
41 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3);
42 SCM
43 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
44 {
45   if (scm_is_string (markup))
46     return interpret_string (layout_smob, props, markup);
47   else if (scm_is_pair (markup))
48     {
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");
53
54       return scm_apply_2 (func, layout_smob, props, args);
55     }
56   else
57     {
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 ());
62
63       Box b;
64       b[X_AXIS].set_empty ();
65       b[Y_AXIS].set_empty ();
66
67       Stencil s (b, SCM_EOL);
68       return s.smobbed_copy ();
69     }
70 }
71
72 MAKE_SCHEME_CALLBACK (Text_interface, print, 1);
73 SCM
74 Text_interface::print (SCM grob)
75 {
76   Grob *me = unsmob_grob (grob);
77
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);
81 }
82
83 /* Ugh. Duplicated from Scheme.  */
84 bool
85 Text_interface::is_markup (SCM x)
86 {
87   return (scm_is_string (x)
88           || (scm_is_pair (x)
89               && SCM_BOOL_F
90               != scm_object_property (scm_car (x),
91                                       ly_symbol2scm ("markup-signature"))));
92 }
93
94 ADD_INTERFACE (Text_interface, "text-interface",
95                "A scheme markup text, see @usermanref{Text markup}.",
96                "baseline-skip "
97                "text "
98                "word-space "
99                "text-direction "
100                );
101