3 text-spanner.cc -- implement Text_spanner
5 source file of the GNU LilyPond music typesetter
7 (c) 2000--2002 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "molecule.hh"
11 #include "text-item.hh"
12 #include "text-spanner.hh"
13 #include "line-spanner.hh"
15 #include "font-interface.hh"
16 #include "dimensions.hh"
17 #include "paper-def.hh"
19 #include "paper-column.hh"
20 #include "staff-symbol-referencer.hh"
24 - vertical start / vertical end (fixme-name) |
25 - contination types (vert. star, vert. end) |-> eat volta-spanner
27 - more texts/positions
30 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
33 TODO: this function is too long, too hairy.
35 TODO: document this. What the heck is happening here?
38 Text_spanner::brew_molecule (SCM smob)
40 Grob *me= unsmob_grob (smob);
41 Spanner *spanner = dynamic_cast<Spanner*> (me);
43 if (spanner->has_interface (ly_symbol2scm ("piano-pedal-interface")) )
45 setup_pedal_bracket(spanner);
49 /* Ugh, must be same as Hairpin::brew_molecule. */
50 Real padding = gh_scm2double (me->get_grob_property ("if-text-padding"));
51 Real broken_left = spanner->get_broken_left_end_align ();
52 Real width = spanner->spanner_length ();
55 Drul_array<bool> broken;
56 Drul_array<Real> extra_off;
61 Item *b = spanner->get_bound (d);
62 broken[d] = b->break_status_dir () != CENTER;
67 Interval e = b->extent (b, X_AXIS);
71 /* Text spanners such as ottava, should span from outer limits of
72 noteheads, iso (de)cresc. spanners that span the inner space */
73 if (me->get_grob_property ("outer") != SCM_EOL)
85 while (flip (&d) != LEFT);
87 // FIXME: ecs tells us -- only for (de)cresc. spanners
88 width += gh_scm2double (me->get_grob_property ("width-correct"));
93 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))
102 /* Don't repeat edge text for broken end */
105 SCM text = index_cell (edge_text, d);
106 edge[d] = Text_item::text2molecule (me, text, properties);
107 if (!edge[d].empty_b ())
108 edge[d].align_to (Y_AXIS, CENTER);
111 while (flip (&d) != LEFT);
113 width -= edge[LEFT].extent (X_AXIS).length ()
114 + edge[RIGHT].extent (X_AXIS).length ();
116 Drul_array<Real> shorten;
120 SCM s = me->get_grob_property ("shorten-pair");
123 shorten[LEFT] = gh_scm2double (ly_car (s));
124 shorten[RIGHT] = gh_scm2double (ly_cdr (s));
127 width -= shorten[LEFT] + shorten[RIGHT];
131 me->warning (_ ("Text_spanner too small"));
137 Real thick = me->paper_l ()->get_var ("stafflinethickness");
138 SCM st = me->get_grob_property ("thickness");
139 if (gh_number_p (st))
141 thick *= gh_scm2double (st);
144 Molecule line = Line_spanner::line_molecule (me, thick, width, 0);
146 Drul_array<Molecule> edge_line;
147 s = me->get_grob_property ("edge-height");
148 SCM ew = me->get_grob_property ("edge-width");
152 int dir = to_dir (me->get_grob_property ("direction"));
155 Real dx = ( gh_pair_p (ew) ?
156 gh_scm2double (index_cell (ew, d)) * - dir :
158 Real dy = gh_scm2double (index_cell (s, d)) * - dir;
161 edge_line[d] = Line_spanner::line_molecule (me, thick, dx, dy);
164 while (flip (&d) != LEFT);
168 if (!edge[LEFT].empty_b ())
171 if (!edge_line[LEFT].empty_b ())
172 m.add_at_edge (X_AXIS, RIGHT, edge_line[LEFT], 0);
173 if (!line.empty_b ())
174 m.add_at_edge (X_AXIS, RIGHT, line,
175 edge_line[LEFT].empty_b () ? 0 : - thick/2);
176 if (!edge_line[RIGHT].empty_b ())
177 m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], -thick/2);
178 if (!edge[RIGHT].empty_b ())
179 m.add_at_edge (X_AXIS, RIGHT, edge[RIGHT], 0);
180 m.translate_axis (broken_left + extra_off[LEFT] + shorten[LEFT], X_AXIS);
182 return m.smobbed_copy ();
188 Piano pedal brackets are a special case of a text spanner.
189 Pedal up-down (restart) indicated by the angled right and left edges
190 of consecutive pedals touching exactly to form an __/\__
191 Chris Jackson <chris@fluffhouse.org.uk>
195 Text_spanner::setup_pedal_bracket(Spanner *me)
198 Real thick = me->paper_l ()->get_var ("stafflinethickness");
199 SCM st = me->get_grob_property ("thickness");
200 if (gh_number_p (st))
202 thick *= gh_scm2double (st);
205 Drul_array<bool> w, broken;
206 Drul_array<Real> height, width, shorten, r;
208 SCM pa = me->get_grob_property ("if-text-padding");
209 SCM ew = me->get_grob_property ("edge-width");
210 SCM eh = me->get_grob_property ("edge-height");
211 SCM sp = me->get_grob_property ("shorten-pair");
212 SCM wl = me->get_grob_property ("left-widen");
213 SCM wr = me->get_grob_property ("right-widen");
215 // Pedal has an angled left edge \__ or an angled right edge __/
216 w[LEFT] = w[RIGHT] = false;
217 if (gh_boolean_p (wl) )
218 w[LEFT] = to_boolean (wl);
219 if (gh_boolean_p (wr) )
220 w[RIGHT] = to_boolean (wr);
226 if (gh_number_p (pa) )
227 padding = gh_scm2double (pa);
230 Item *b = me->get_bound (d);
232 e = b->extent (b, X_AXIS);
234 r[d] = d * (e[-d] + padding);
236 broken[d] = b->break_status_dir () != CENTER;
240 if ( w[d] && gh_pair_p (ew) )
241 width[d] += gh_scm2double (index_cell (ew, d)) * d;
242 if ( !broken[d] && (gh_pair_p (eh) ) )
243 height[d] = gh_scm2double (index_cell (eh, d));
244 if ( gh_pair_p (sp) )
245 shorten[d] = gh_scm2double (index_cell (sp, d));
247 while (flip (&d) != LEFT);
249 Real extra_short = 0;
250 // For 'Mixed' style pedals, i.e. a bracket preceded by text: Ped._____|
251 // need to shorten by the extent of the text grob
252 if ( to_boolean (me->get_grob_property ("text-start")) )
255 Grob * textbit = me->get_parent(Y_AXIS);
256 extra_short = padding;
257 if (textbit->has_interface(ly_symbol2scm("piano-pedal-interface")))
258 // for pretty Ped. scripts.
260 e = textbit->extent(textbit, Y_AXIS);
261 extra_short += e.length();
263 if (textbit->has_interface(ly_symbol2scm("text-interface")))
264 // for plain text, e.g., Sost. Ped.
266 SCM text = textbit->get_grob_property("text");
267 if (gh_string_p (text)) {
268 SCM properties = Font_interface::font_alist_chain (me);
269 Molecule mol = Text_item::text2molecule (me, text, properties);
270 extra_short += mol.extent(X_AXIS).length() / 2;
273 shorten[RIGHT] -= thick;
276 // Shorten a \____ on the left so that it will touch an adjoining ___/
277 shorten[LEFT] += abs(width[LEFT]) * 2 + extra_short ;
280 shorten[LEFT] -= me->get_broken_left_end_align () ;
281 shorten[RIGHT] -= r[RIGHT];
284 // Shorten bracket on the right so it ends just before the spanned note.
285 shorten[RIGHT] += thick - (r[LEFT] + r[RIGHT]);
287 me->set_grob_property ("edge-height", gh_cons ( gh_double2scm ( height[LEFT] ) ,
288 gh_double2scm ( height[RIGHT]) ) );
289 me->set_grob_property ("edge-width", gh_cons ( gh_double2scm ( width[LEFT] ),
290 gh_double2scm ( width[RIGHT] ) ));
291 me->set_grob_property ("shorten-pair", gh_cons ( gh_double2scm ( shorten[LEFT] ),
292 gh_double2scm ( shorten[RIGHT] ) ));