]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-item.cc
* scm/music-functions.scm (has-request-chord): don't use
[lilypond.git] / lily / text-item.cc
1 /*   
2   text-item.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-item.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
24 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3)
25 SCM
26 Text_interface::interpret_string (SCM layout_smob,
27                                   SCM props,
28                                   SCM markup)
29 {
30   Output_def *layout = unsmob_output_def (layout_smob);
31   
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");
36
37   String str = ly_scm2string (markup);
38
39   Font_metric *fm = select_encoded_font (layout, props);
40   return fm->text_stencil (str).smobbed_copy ();
41 }
42
43
44 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3)
45 SCM
46 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
47 {
48   if (scm_is_string (markup))
49     return interpret_string (layout_smob, props, markup);
50   else if (scm_is_pair (markup))
51     {
52       SCM func = scm_car (markup);
53       SCM args = scm_cdr (markup);
54       if (!markup_p (markup))
55         programming_error ("Markup head has no markup signature.");
56       
57       return scm_apply_2 (func, layout_smob, props, args);
58     }
59   else
60     {
61       programming_error ("Is not a markup: ");
62       scm_display (markup, scm_current_error_port());
63       assert (false);
64       Box b;
65       b[X_AXIS].set_empty();
66       b[Y_AXIS].set_empty();
67       
68       Stencil s(b, SCM_EOL);
69       return s.smobbed_copy();
70     }
71 }
72
73 MAKE_SCHEME_CALLBACK (Text_interface, print, 1);
74 SCM
75 Text_interface::print (SCM grob)
76 {
77   Grob *me = unsmob_grob (grob);
78   
79   SCM t = me->get_property ("text");
80   SCM chain = Font_interface::text_font_alist_chain (me);
81   return interpret_markup (me->get_layout ()->self_scm (), chain, t);
82 }
83
84 /* Ugh. Duplicated from Scheme.  */
85 bool
86 Text_interface::markup_p (SCM x)
87 {
88   return (scm_is_string (x)
89           || (scm_is_pair (x)
90               && SCM_BOOL_F
91               != scm_object_property (scm_car (x),
92                                       ly_symbol2scm ("markup-signature"))));
93 }
94
95 ADD_INTERFACE (Text_interface, "text-interface",
96                "A scheme markup text, see @usermanref{Text-markup}.",
97                "text baseline-skip word-space");
98
99
100
101