]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-item.cc
31d34024109c800c968b47582eca660b4270200f
[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 "paper-def.hh"
17
18 MAKE_SCHEME_CALLBACK (Text_item, interpret_markup, 3)
19 SCM
20 Text_item::interpret_markup (SCM paper, SCM props, SCM markup)
21 {
22   if (gh_string_p (markup))
23     {
24       String str = ly_scm2string (markup);
25       if (str.index_any (" \t\n\r") != -1)
26         {
27           /* Multi word string to line markup.  */
28           static SCM proc;
29           if (!proc)
30             proc = scm_c_eval_string ("make-simple-markup");
31           return interpret_markup (paper, props, scm_call_1 (proc, markup));
32         }
33
34       /* Simple word.  */
35       Paper_def *pap = unsmob_paper (paper);
36       Font_metric *fm = select_font (pap, props);
37       SCM lst = scm_list_n (ly_symbol2scm ("text"), markup, SCM_UNDEFINED);
38       
39       if (dynamic_cast<Virtual_font_metric*> (fm))
40         /* ARGH. */
41         programming_error ("Can't use virtual font for text.");
42       else
43         lst = fontify_atom (fm, lst);
44
45       Box b = fm->text_dimension (str);
46       return Stencil (b, lst).smobbed_copy ();
47     }
48   else if (gh_pair_p (markup))
49     {
50       SCM func = gh_car (markup);
51       SCM args = gh_cdr (markup);
52       if (!markup_p (markup))
53         programming_error ("Markup head has no markup signature.");
54       
55       return scm_apply_2 (func, paper, props, args);
56     }
57   return SCM_EOL;
58 }
59
60 MAKE_SCHEME_CALLBACK (Text_item,print,1);
61 SCM
62 Text_item::print (SCM grob)
63 {
64   Grob * me = unsmob_grob (grob);
65   
66   SCM t = me->get_property ("text");
67   SCM chain = Font_interface::font_alist_chain (me);
68   return interpret_markup (me->get_paper ()->self_scm (), chain, t);
69 }
70
71
72 /*
73   Ugh. Duplicated from Scheme.
74  */
75 bool
76 Text_item::markup_p (SCM x)
77 {
78   return
79     gh_string_p (x) ||
80     (gh_pair_p (x)
81      && SCM_BOOL_F != scm_object_property (gh_car (x), ly_symbol2scm ("markup-signature")));
82 }
83
84 ADD_INTERFACE (Text_item,"text-interface",
85   "A scheme markup text, see @usermanref{Text-markup}.",
86   "text baseline-skip word-space");
87
88
89
90