]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-item.cc
patch::: 1.3.96.jcn4
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8  */
9
10 #include "text-item.hh"
11 #include "paper-def.hh"
12 #include "lookup.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "staff-symbol-referencer.hh"
15 #include "main.hh"
16 #include "all-font-metrics.hh"
17 #include "afm.hh"
18
19 /*
20   text: string | (markup sentence)
21   markup: markup-symbol | (markup-symbol . parameter)
22   sentence: text | sentence text
23   
24
25   Properties:
26
27   * Font:
28   ---* Type:
29   ------* Series: medium, bold
30   ------* Shape: upright, italic, slanted
31   ------* Family: roman, music, orator, typewriter
32
33   ---* Size:
34   ------* size: ...,-2,-1,0,1,2,... (style-sheet -> cmrXX, fetaXX)
35   ------* points: 11,13,16,20,23,26 (for feta)
36   ------* magnification: UNSIGNED
37
38   * Typesetting:
39   ---* kern: INT (staff-space)
40   ---* align: horizontal/vertical / lines / rows
41  */
42 Molecule
43 Text_item::text2molecule (Score_element *me, SCM text, SCM properties) 
44 {
45   if (gh_string_p (text))
46     return string2molecule (me, text, properties);
47   else if (gh_list_p (text))
48     {
49       if (!gh_pair_p (gh_car (text)) && gh_string_p (gh_car (text)))
50         return string2molecule (me, gh_car (text), properties);
51       else
52         return markup_sentence2molecule (me, text, properties);
53     }
54   return Molecule ();
55 }
56
57 Molecule
58 Text_item::string2molecule (Score_element *me, SCM text, SCM properties)
59 {
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);
66     
67   SCM magnification = me->get_elt_property ("font-magnification");
68
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));
73   else
74     metric_l = all_fonts_global_p->find_font (font_str);
75
76   SCM list = gh_list (ly_symbol2scm ("text"), text, SCM_UNDEFINED);
77   list = fontify_atom (metric_l, list);
78
79   return Molecule (metric_l->text_dimension (ly_scm2string (text)), list);
80 }
81
82 Molecule
83 Text_item::markup_sentence2molecule (Score_element *me, SCM markup_sentence,
84                                      SCM properties)
85 {
86   SCM markup = gh_car (markup_sentence);
87   SCM sentence = gh_cdr (markup_sentence);
88   SCM f = me->get_elt_property ("markup-to-properties");
89   
90   SCM p = gh_cons (gh_call1 (f, markup), properties);
91
92   Axis align = X_AXIS;
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));
96
97   Molecule mol;
98   while (gh_pair_p (sentence))
99     {
100       Molecule m = text2molecule (me, gh_car (sentence), p);
101       if (!m.empty_b ())
102         mol.add_at_edge (align, align == X_AXIS ? RIGHT : DOWN, m, 0);
103       sentence = gh_cdr (sentence);
104     }
105   return mol;
106 }
107
108 MAKE_SCHEME_CALLBACK (Text_item, brew_molecule, 1);
109 SCM 
110 Text_item::brew_molecule (SCM smob) 
111 {
112   Score_element *me = unsmob_element (smob);
113   
114   SCM text = me->get_elt_property ("scm-text");
115   Molecule mol;
116   if (text == SCM_EOL)
117     {
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) : "";
122       
123       mol = me->paper_l ()->lookup_l (0)->text (st, t, me->paper_l ());
124     }
125   else
126     mol = text2molecule (me, text,
127                          gh_append2 (me->immutable_property_alist_,
128                                      me->mutable_property_alist_));
129
130   SCM space = me->get_elt_property ("word-space");
131   if (gh_number_p (space))
132     {
133       Molecule m;
134       m.set_empty (false);
135       mol.add_at_edge (X_AXIS, RIGHT, m, gh_scm2double (space)
136                        * Staff_symbol_referencer::staff_space (me));
137     }
138   return mol.create_scheme (); 
139 }
140