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