]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-item.cc
10fdc67ec0fa7783d9568d811bf2da7fb8a653a0
[lilypond.git] / lily / text-item.cc
1 /*   
2   text-item.cc -- implement Text_item
3
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8  */
9 #include <math.h>
10
11 #include "warn.hh"
12 #include "grob.hh"
13 #include "text-item.hh"
14 #include "font-interface.hh"
15 #include "virtual-font-metric.hh"
16 #include "output-def.hh"
17 #include "scaled-font-metric.hh"
18 #include "ly-module.hh"
19
20 MAKE_SCHEME_CALLBACK (Text_item, interpret_string, 4)
21 SCM
22 Text_item::interpret_string (SCM paper, SCM props, SCM encoding, SCM markup)
23 {
24   Output_def *pap = unsmob_output_def (paper);
25   
26   SCM_ASSERT_TYPE(pap, paper, SCM_ARG1, __FUNCTION__, "Paper definition");
27   SCM_ASSERT_TYPE(ly_c_string_p (markup), markup, SCM_ARG3, __FUNCTION__, "string");
28   SCM_ASSERT_TYPE(encoding == SCM_EOL
29                   || ly_c_symbol_p (encoding), encoding, SCM_ARG2, __FUNCTION__, "symbol");
30   
31   String str = ly_scm2string (markup);
32   if (!ly_c_symbol_p (encoding))
33     {
34       SCM var = ly_module_lookup (pap->scope_,
35                                   ly_symbol2scm ("inputencoding"));
36       if (var != SCM_BOOL_F) 
37         encoding = scm_variable_ref (var);
38       
39     }
40   
41   Font_metric *fm = select_encoded_font (pap, props, encoding);
42
43   SCM lst = SCM_EOL;      
44   Box b;
45   if (Modified_font_metric* mf = dynamic_cast<Modified_font_metric*> (fm))
46     {
47       lst = scm_list_3 (ly_symbol2scm ("text"),
48                         mf->self_scm (),
49                         markup);
50         
51       b = mf->text_dimension (str);
52     }
53   else
54     {
55       /* ARGH. */
56       programming_error ("Must have Modified_font_metric for text.");
57       scm_display (fm->description_, scm_current_error_port ());
58     }
59       
60   return Stencil (b, lst).smobbed_copy ();
61 }
62
63
64 MAKE_SCHEME_CALLBACK (Text_item, interpret_markup, 3)
65 SCM
66 Text_item::interpret_markup (SCM paper, SCM props, SCM markup)
67 {
68   if (ly_c_string_p (markup))
69     return interpret_string (paper, props, SCM_EOL, markup);
70   else if (ly_c_pair_p (markup))
71     {
72       SCM func = ly_car (markup);
73       SCM args = ly_cdr (markup);
74       if (!markup_p (markup))
75         programming_error ("Markup head has no markup signature.");
76       
77       return scm_apply_2 (func, paper, props, args);
78     }
79   return SCM_EOL;
80 }
81
82 MAKE_SCHEME_CALLBACK (Text_item,print,1);
83 SCM
84 Text_item::print (SCM grob)
85 {
86   Grob *me = unsmob_grob (grob);
87   
88   SCM t = me->get_property ("text");
89   SCM chain = Font_interface::text_font_alist_chain (me);
90   return interpret_markup (me->get_paper ()->self_scm (), chain, t);
91 }
92
93
94 /*
95   Ugh. Duplicated from Scheme.
96  */
97 bool
98 Text_item::markup_p (SCM x)
99 {
100   return
101     ly_c_string_p (x) ||
102     (ly_c_pair_p (x)
103      && SCM_BOOL_F != scm_object_property (ly_car (x), ly_symbol2scm ("markup-signature")));
104 }
105
106 ADD_INTERFACE (Text_item,"text-interface",
107   "A scheme markup text, see @usermanref{Text-markup}.",
108   "text baseline-skip word-space");
109
110
111
112