2 text-item.cc -- implement Text_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "text-item.hh"
11 #include "paper-def.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "staff-symbol-referencer.hh"
16 #include "all-font-metrics.hh"
20 text: string | (markup sentence)
21 markup: markup-symbol | (markup-symbol . parameter)
22 sentence: text | sentence text
29 ------* Series: medium, bold
30 ------* Shape: upright, italic, slanted
31 ------* Family: roman, music, orator, typewriter
34 ------* size: ...,-2,-1,0,1,2,... (style-sheet -> cmrXX, fetaXX)
35 ------* points: 11,13,16,20,23,26 (for feta)
36 ------* magnification: UNSIGNED
39 ---* kern: INT (staff-space)
40 ---* align: horizontal/vertical / lines / rows
43 Text_item::text2molecule (Score_element *me, SCM text, SCM properties)
45 if (gh_string_p (text))
46 return string2molecule (me, text, properties);
47 else if (gh_list_p (text))
49 if (!gh_pair_p (gh_car (text)) && gh_string_p (gh_car (text)))
50 return string2molecule (me, gh_car (text), properties);
52 return markup_sentence2molecule (me, text, properties);
58 Text_item::string2molecule (Score_element *me, SCM text, SCM properties)
60 SCM f = me->get_elt_property ("get-font-name");
61 SCM style = me->get_elt_property ("style-sheet");
62 SCM font_name = gh_call2 (f, style, properties);
63 String font_str = "roman";
64 if (gh_string_p (font_name))
65 font_str = ly_scm2string (font_name);
67 SCM magnification = me->get_elt_property ("font-magnification");
69 Font_metric* metric_l = 0;
70 if (gh_number_p (magnification))
71 metric_l = all_fonts_global_p->find_scaled (font_str,
72 gh_scm2int (magnification));
74 metric_l = all_fonts_global_p->find_font (font_str);
76 SCM list = gh_list (ly_symbol2scm ("text"), text, SCM_UNDEFINED);
77 list = fontify_atom (metric_l, list);
79 return Molecule (metric_l->text_dimension (ly_scm2string (text)), list);
83 Text_item::markup_sentence2molecule (Score_element *me, SCM markup_sentence,
86 SCM markup = gh_car (markup_sentence);
87 SCM sentence = gh_cdr (markup_sentence);
88 SCM f = me->get_elt_property ("markup-to-properties");
90 SCM p = gh_cons (gh_call1 (f, markup), properties);
93 SCM a = scm_assoc (ly_symbol2scm ("align"), p);
94 if (gh_pair_p (a) && gh_number_p (gh_cdr (a)))
95 align = (Axis)gh_scm2int (gh_cdr (a));
98 while (gh_pair_p (sentence))
100 Molecule m = text2molecule (me, gh_car (sentence), p);
102 mol.add_at_edge (align, align == X_AXIS ? RIGHT : DOWN, m, 0);
103 sentence = gh_cdr (sentence);
108 MAKE_SCHEME_CALLBACK (Text_item, brew_molecule, 1);
110 Text_item::brew_molecule (SCM smob)
112 Score_element *me = unsmob_element (smob);
114 SCM text = me->get_elt_property ("scm-text");
118 SCM style = me->get_elt_property ("style");
119 String st = gh_string_p (style) ? ly_scm2string (style) : "";
120 SCM text = me->get_elt_property ("text");
121 String t = gh_string_p (text) ? ly_scm2string (text) : "";
123 mol = me->paper_l ()->lookup_l (0)->text (st, t, me->paper_l ());
126 mol = text2molecule (me, text,
127 gh_append2 (me->immutable_property_alist_,
128 me->mutable_property_alist_));
130 SCM space = me->get_elt_property ("word-space");
131 if (gh_number_p (space))
135 mol.add_at_edge (X_AXIS, RIGHT, m, gh_scm2double (space)
136 * Staff_symbol_referencer::staff_space (me));
138 return mol.create_scheme ();