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