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