.ly version update.
[lilypond.git] / lily / text-item.cc
blobfef4babe23d08c088616013472c6e0a198affb5b
1 /*
2 text-item.cc -- implement Text_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9 #include <math.h>
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"
18 MAKE_SCHEME_CALLBACK(Text_item,interpret_markup,3);
19 SCM
20 Text_item::interpret_markup (SCM paper, SCM props, SCM markup)
22 if (gh_string_p (markup))
24 Paper_def *pap = unsmob_paper (paper);
25 Font_metric *fm = select_font (pap, props);
27 SCM list = scm_list_n (ly_symbol2scm ("text"), markup, SCM_UNDEFINED);
29 if (dynamic_cast<Virtual_font_metric*> (fm))
32 ARGH.
34 programming_error ("Can't use virtual font for text.");
36 else
37 list = fontify_atom (fm, list);
39 Box b = fm->text_dimension (ly_scm2string (markup));
40 return Molecule (b, list).smobbed_copy();
42 else if (gh_pair_p (markup))
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.");
49 return scm_apply_2 (func, paper, props, args);
51 else
53 return SCM_EOL;
57 MAKE_SCHEME_CALLBACK(Text_item,brew_molecule,1);
58 SCM
59 Text_item::brew_molecule (SCM grob)
61 Grob * me = unsmob_grob (grob);
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);
70 Ugh. Duplicated from Scheme.
72 bool
73 Text_item::markup_p (SCM x)
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")));
81 ADD_INTERFACE (Text_item,"text-interface",
82 "A scheme markup text, see @ref{Markup functions}.",
83 "text baseline-skip word-space");