]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-item.cc
b327e78865c6b7d09a90fc0ebc08ba599be5c3f7
[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           SCM proc= ly_scheme_function ("make-simple-markup");
29           return interpret_markup (paper, props, scm_call_1 (proc, markup));
30         }
31
32       /* Simple word.  */
33       Paper_def *pap = unsmob_paper (paper);
34       Font_metric *fm = select_font (pap, props);
35       SCM lst = scm_list_n (ly_symbol2scm ("text"), markup, SCM_UNDEFINED);
36       
37       if (dynamic_cast<Virtual_font_metric*> (fm))
38         /* ARGH. */
39         programming_error ("Can't use virtual font for text.");
40       else
41         lst = fontify_atom (fm, lst);
42
43       Box b = fm->text_dimension (str);
44       return Stencil (b, lst).smobbed_copy ();
45     }
46   else if (gh_pair_p (markup))
47     {
48       SCM func = gh_car (markup);
49       SCM args = gh_cdr (markup);
50       if (!markup_p (markup))
51         programming_error ("Markup head has no markup signature.");
52       
53       return scm_apply_2 (func, paper, props, args);
54     }
55   return SCM_EOL;
56 }
57
58 MAKE_SCHEME_CALLBACK (Text_item,print,1);
59 SCM
60 Text_item::print (SCM grob)
61 {
62   Grob * me = unsmob_grob (grob);
63   
64   SCM t = me->get_property ("text");
65   SCM chain = Font_interface::text_font_alist_chain (me);
66   return interpret_markup (me->get_paper ()->self_scm (), 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 @usermanref{Text-markup}.",
84   "text baseline-skip word-space");
85
86
87
88