]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-item.cc
new file, move from
[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
19 MAKE_SCHEME_CALLBACK (Text_item, interpret_string, 4)
20 SCM
21 Text_item::interpret_string (SCM paper, SCM props, SCM encoding, SCM markup)
22 {
23   Output_def *pap = unsmob_output_def (paper);
24   
25   SCM_ASSERT_TYPE(pap, paper, SCM_ARG1, __FUNCTION__, "Paper definition");
26   SCM_ASSERT_TYPE(ly_c_string_p (markup), markup, SCM_ARG3, __FUNCTION__, "string");
27   SCM_ASSERT_TYPE(encoding == SCM_EOL
28                   || ly_c_symbol_p (encoding), encoding, SCM_ARG2, __FUNCTION__, "symbol");
29   
30   String str = ly_scm2string (markup);
31   Font_metric *fm = select_encoded_font (pap, props, encoding);
32
33   SCM lst = SCM_EOL;      
34   Box b;
35   if (Modified_font_metric* mf = dynamic_cast<Modified_font_metric*> (fm))
36     {
37       lst = scm_list_3 (ly_symbol2scm ("text"),
38                         mf->self_scm (),
39                         markup);
40         
41       b = mf->text_dimension (str);
42     }
43   else
44     {
45       /* ARGH. */
46       programming_error ("Must have Modified_font_metric for text.");
47     }
48       
49   return Stencil (b, lst).smobbed_copy ();
50 }
51
52
53 MAKE_SCHEME_CALLBACK (Text_item, interpret_markup, 3)
54 SCM
55 Text_item::interpret_markup (SCM paper, SCM props, SCM markup)
56 {
57   if (ly_c_string_p (markup))
58     return interpret_string (paper, props, SCM_EOL, markup);
59   else if (ly_c_pair_p (markup))
60     {
61       SCM func = ly_car (markup);
62       SCM args = ly_cdr (markup);
63       if (!markup_p (markup))
64         programming_error ("Markup head has no markup signature.");
65       
66       return scm_apply_2 (func, paper, props, args);
67     }
68   return SCM_EOL;
69 }
70
71 MAKE_SCHEME_CALLBACK (Text_item,print,1);
72 SCM
73 Text_item::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_paper ()->self_scm (), chain, t);
80 }
81
82
83 /*
84   Ugh. Duplicated from Scheme.
85  */
86 bool
87 Text_item::markup_p (SCM x)
88 {
89   return
90     ly_c_string_p (x) ||
91     (ly_c_pair_p (x)
92      && SCM_BOOL_F != scm_object_property (ly_car (x), ly_symbol2scm ("markup-signature")));
93 }
94
95 ADD_INTERFACE (Text_item,"text-interface",
96   "A scheme markup text, see @usermanref{Text-markup}.",
97   "text baseline-skip word-space");
98
99
100
101