]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner.cc
* input/regression/rehearsal-mark-letter.ly: new file.
[lilypond.git] / lily / text-spanner.cc
1 /*
2   text-spanner.cc -- implement Text_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7
8   Revised over good by Han-Wen. 
9 */
10
11 #include "molecule.hh"
12 #include "text-item.hh"
13 #include "text-spanner.hh"
14 #include "line-spanner.hh"
15 #include "spanner.hh"
16 #include "font-interface.hh"
17 #include "dimensions.hh"
18 #include "paper-def.hh"
19 #include "warn.hh"
20 #include "paper-column.hh"
21 #include "staff-symbol-referencer.hh"
22
23 /*
24   TODO:
25   - vertical start / vertical end (fixme-name) |
26   - contination types (vert. star, vert. end)  |-> eat volta-bracket
27   - more styles
28   - more texts/positions
29 */
30
31 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
32
33 /*
34   TODO: this function is too long
35
36
37   TODO: the string for ottava shoudl depend on the available space, ie.
38
39   
40   Long: 15ma        Short: 15ma    Empty: 15
41          8va                8va            8
42          8va bassa          8ba            8
43
44
45 */
46 SCM
47 Text_spanner::brew_molecule (SCM smob) 
48 {
49   Grob *me= unsmob_grob (smob);
50   Spanner *spanner = dynamic_cast<Spanner*> (me);
51   
52   /* Ugh, must be same as Hairpin::brew_molecule.  */
53   Real padding = 0.0;
54   SCM itp= me->get_grob_property ("if-text-padding");
55   if (gh_number_p (itp))
56     padding = gh_scm2double (itp);
57
58   Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
59   Paper_def * paper = me->get_paper();
60
61   SCM flare = me->get_grob_property ("bracket-flare");
62   SCM shorten = me->get_grob_property ("shorten-pair");
63
64   Interval span_points;
65   Drul_array<bool> broken;
66   Direction d = LEFT;
67   do
68     {
69       Item *b = spanner->get_bound (d);
70       broken[d] = b->break_status_dir () != CENTER;
71
72       if (broken[d])
73         {
74           if (d == LEFT)
75             span_points[d] = spanner->get_broken_left_end_align ();
76           else
77             span_points[d] = b->relative_coordinate (common, X_AXIS);
78         }
79       else
80           {
81             bool encl = to_boolean (me->get_grob_property ("enclose-bounds"));
82             span_points[d] = b->extent (common, X_AXIS)[encl ? d : -d];
83
84             if (is_number_pair (shorten))
85               span_points -= d * gh_scm2double (index_get_cell (shorten, d));
86           }
87       
88       if (is_number_pair (flare))
89         span_points -= d * gh_scm2double (index_get_cell (flare, d));
90     }
91   while (flip (&d) != LEFT);
92
93
94   SCM properties = Font_interface::font_alist_chain (me);
95   SCM edge_text = me->get_grob_property ("edge-text");
96   Drul_array<Molecule> edge;
97   if (gh_pair_p (edge_text))
98     {
99       Direction d = LEFT;
100       do
101         {
102           if (!to_boolean (me->get_grob_property ("text-repeat-if-broken"))
103               && broken[d])
104             continue;
105           
106           SCM text = index_get_cell (edge_text, d);
107
108           if (Text_item::markup_p (text)) 
109             edge[d] = *unsmob_molecule (Text_item::interpret_markup (paper->self_scm (), properties, text));
110           
111           if (!edge[d].is_empty ())
112             edge[d].align_to (Y_AXIS, CENTER);
113         }
114       while (flip (&d) != LEFT);
115     }
116
117   Real thick = paper->get_realvar (ly_symbol2scm ("linethickness"));  
118   SCM st = me->get_grob_property ("thickness");
119   if (gh_number_p (st))
120     {
121       thick *=  gh_scm2double (st);
122     }
123   
124   Drul_array<Molecule> edge_line;
125   SCM edge_height = me->get_grob_property ("edge-height");
126   if (is_number_pair (edge_height))
127     {
128       Direction d = LEFT;
129       int dir = to_dir (me->get_grob_property ("direction"));
130       do
131         {
132           if (broken[d])
133             continue;
134           
135           Real dx = 0.0;
136           if (gh_pair_p (flare))
137             dx = gh_scm2double (index_get_cell (flare, d)) * d;
138
139           Real dy = gh_scm2double (index_get_cell (edge_height, d)) * - dir;
140           if (dy)
141             edge_line[d] = Line_spanner::line_molecule (me, thick, Offset(0,0),
142                                                         Offset (dx, dy));
143         }
144       while (flip (&d) != LEFT);
145     }
146   
147   Molecule m;
148   do
149     {
150       Interval ext = edge[d].extent (X_AXIS);
151       if (!ext.is_empty ())
152         {
153           edge[d].translate_axis (span_points[d], X_AXIS);
154           m.add_molecule (edge[d]);
155           span_points[d] += -d *  ext[-d];
156         }
157     }
158   while (flip (&d) != LEFT);
159   do
160     {
161       if (d* span_points[d] > d * edge[-d].extent(X_AXIS)[d])
162         {
163           edge_line[d].translate_axis (span_points[d], X_AXIS);
164           m.add_molecule (edge_line[d]);
165         }
166     }
167   while (flip (&d) != LEFT);
168
169   if (!span_points.is_empty ())
170     {
171       Molecule l =Line_spanner::line_molecule (me, thick,
172                                                Offset (span_points[LEFT], 0),
173                                                Offset (span_points[RIGHT], 0));
174       m.add_molecule (l);
175     }
176   m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
177   return m.smobbed_copy ();
178 }
179
180
181
182
183 ADD_INTERFACE (Text_spanner,"text-spanner-interface",
184                "generic text spanner",
185                "text-repeat-if-broken dash-period if-text-padding dash-fraction edge-height bracket-flare edge-text shorten-pair style thickness enclose-bounds width-correct");
186