]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-item.cc
patch::: 1.3.96.jcn5
[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 style = scm_assoc (ly_symbol2scm ("font-style"), properties);
61   SCM paper = me->get_elt_property ("style-sheet");
62   SCM font_name;
63   if (gh_pair_p (style))
64     {
65       SCM f = me->get_elt_property ("style-to-font-name");
66       font_name = gh_call2 (f, paper, gh_cdr (style));
67     }
68   else
69     {
70       SCM f = me->get_elt_property ("properties-to-font-name");
71       font_name = gh_call2 (f, paper, properties);
72     }
73   String font_str = "roman";
74   if (gh_string_p (font_name))
75     font_str = ly_scm2string (font_name);
76     
77   SCM magnification = me->get_elt_property ("font-magnification");
78
79   Font_metric* metric_l = 0;
80   if (gh_number_p (magnification))
81     metric_l = all_fonts_global_p->find_scaled (font_str,
82                                                 gh_scm2int (magnification));
83   else
84     metric_l = all_fonts_global_p->find_font (font_str);
85
86   SCM list = gh_list (ly_symbol2scm ("text"), text, SCM_UNDEFINED);
87   list = fontify_atom (metric_l, list);
88
89   return Molecule (metric_l->text_dimension (ly_scm2string (text)), list);
90 }
91
92 Molecule
93 Text_item::markup_sentence2molecule (Score_element *me, SCM markup_sentence,
94                                      SCM properties)
95 {
96   SCM markup = gh_car (markup_sentence);
97   SCM sentence = gh_cdr (markup_sentence);
98   SCM f = me->get_elt_property ("markup-to-properties");
99   
100   SCM p = gh_cons (gh_call1 (f, markup), properties);
101
102   Axis align = X_AXIS;
103   SCM a = scm_assoc (ly_symbol2scm ("align"), p);
104   if (gh_pair_p (a) && gh_number_p (gh_cdr (a)))
105     align = (Axis)gh_scm2int (gh_cdr (a));
106
107   Molecule mol;
108   while (gh_pair_p (sentence))
109     {
110       Molecule m = text2molecule (me, gh_car (sentence), p);
111       if (!m.empty_b ())
112         mol.add_at_edge (align, align == X_AXIS ? RIGHT : DOWN, m, 0);
113       sentence = gh_cdr (sentence);
114     }
115   return mol;
116 }
117
118 MAKE_SCHEME_CALLBACK (Text_item, brew_molecule, 1);
119 SCM 
120 Text_item::brew_molecule (SCM smob) 
121 {
122   Score_element *me = unsmob_element (smob);
123   
124   SCM text = me->get_elt_property ("scm-text");
125   Molecule mol;
126   if (text == SCM_EOL)
127     {
128       SCM style = me->get_elt_property ("style");
129       String st = gh_string_p (style) ?  ly_scm2string (style) : "";
130       SCM text = me->get_elt_property ("text");
131       String t = gh_string_p (text) ? ly_scm2string (text) : "";
132       
133       mol = me->paper_l ()->lookup_l (0)->text (st, t, me->paper_l ());
134     }
135   else
136     mol = text2molecule (me, text,
137                          gh_append2 (me->immutable_property_alist_,
138                                      me->mutable_property_alist_));
139
140   SCM space = me->get_elt_property ("word-space");
141   if (gh_number_p (space))
142     {
143       Molecule m;
144       m.set_empty (false);
145       mol.add_at_edge (X_AXIS, RIGHT, m, gh_scm2double (space)
146                        * Staff_symbol_referencer::staff_space (me));
147     }
148   return mol.create_scheme (); 
149 }
150