3 text-spanner.cc -- implement Text_spanner
5 source file of the GNU LilyPond music typesetter
7 (c) 2000--2003 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-bracket
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->internal_has_interface (ly_symbol2scm ("piano-pedal-interface")))
45 setup_pedal_bracket(spanner);
48 /* Ugh, must be same as Hairpin::brew_molecule. */
50 SCM itp= me->get_grob_property ("if-text-padding");
51 if (gh_number_p (itp))
52 padding = gh_scm2double (itp);
54 Real broken_left = spanner->get_broken_left_end_align ();
55 Real width = spanner->spanner_length ();
58 Drul_array<bool> broken;
59 Drul_array<Real> extra_off;
64 Item *b = spanner->get_bound (d);
65 broken[d] = b->break_status_dir () != CENTER;
70 Interval e = b->extent (b, X_AXIS);
75 /* Text spanners such as ottava, should span from outer limits of
76 noteheads, iso (de)cresc. spanners that span the inner space */
77 if (me->get_grob_property ("enclose-bounds") != SCM_EOL)
88 while (flip (&d) != LEFT);
90 // FIXME: ecs tells us -- only for (de)cresc. spanners
91 width += gh_scm2double (me->get_grob_property ("width-correct"));
96 SCM properties = Font_interface::font_alist_chain (me);
98 SCM edge_text = me->get_grob_property ("edge-text");
99 Drul_array<Molecule> edge;
100 if (gh_pair_p (edge_text))
105 /* Don't repeat edge text for broken end */
108 SCM text = index_get_cell (edge_text, d);
109 edge[d] = Text_item::text2molecule (me, text, properties);
110 if (!edge[d].empty_b ())
111 edge[d].align_to (Y_AXIS, CENTER);
114 while (flip (&d) != LEFT);
116 width -= edge[LEFT].extent (X_AXIS).length ()
117 + edge[RIGHT].extent (X_AXIS).length ();
119 Drul_array<Real> shorten;
123 SCM s = me->get_grob_property ("shorten-pair");
126 shorten[LEFT] = gh_scm2double (ly_car (s));
127 shorten[RIGHT] = gh_scm2double (ly_cdr (s));
130 width -= shorten[LEFT] + shorten[RIGHT];
134 me->warning (_ ("Text_spanner too small"));
140 Real thick = me->get_paper ()->get_var ("linethickness");
141 SCM st = me->get_grob_property ("thickness");
142 if (gh_number_p (st))
144 thick *= gh_scm2double (st);
147 Molecule line = Line_spanner::line_molecule (me, thick, width, 0);
149 Drul_array<Molecule> edge_line;
150 s = me->get_grob_property ("edge-height");
151 SCM ew = me->get_grob_property ("edge-widen");
155 int dir = to_dir (me->get_grob_property ("direction"));
158 Real dx = ( gh_pair_p (ew) ?
159 gh_scm2double (index_get_cell (ew, d)) * d :
161 Real dy = gh_scm2double (index_get_cell (s, d)) * - dir;
164 edge_line[d] = Line_spanner::line_molecule (me, thick, dx, dy);
167 while (flip (&d) != LEFT);
171 if (!edge[LEFT].empty_b ())
174 if (!edge_line[LEFT].empty_b ())
175 m.add_at_edge (X_AXIS, RIGHT, edge_line[LEFT], 0,0);
176 if (!line.empty_b ())
177 m.add_at_edge (X_AXIS, RIGHT, line,
178 edge_line[LEFT].empty_b () ? 0 : -thick/2, 0);
179 if (!edge_line[RIGHT].empty_b ())
180 m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], -thick/2, 0);
181 if (!edge[RIGHT].empty_b ())
182 m.add_at_edge (X_AXIS, RIGHT, edge[RIGHT], 0, 0);
183 m.translate_axis (broken_left + extra_off[LEFT] + shorten[LEFT], X_AXIS);
185 return m.smobbed_copy ();
192 Piano pedal brackets are a special case of a text spanner.
193 Pedal up-down (restart) indicated by the angled right and left edges
194 of consecutive pedals touching exactly to form an __/\__
195 Chris Jackson <chris@fluffhouse.org.uk>
199 Text_spanner::setup_pedal_bracket(Spanner *me)
202 Real thick = me->get_paper ()->get_var ("linethickness");
203 SCM st = me->get_grob_property ("thickness");
204 if (gh_number_p (st))
206 thick *= gh_scm2double (st);
209 Drul_array<bool> broken;
210 Drul_array<Real> height, width, shorten, r;
212 SCM pa = me->get_grob_property ("if-text-padding");
213 SCM ew = me->get_grob_property ("edge-widen");
214 SCM eh = me->get_grob_property ("edge-height");
215 SCM sp = me->get_grob_property ("shorten-pair");
221 if (gh_number_p (pa) )
222 padding = gh_scm2double (pa);
226 Item *b = me->get_bound (d);
228 e = b->extent (b, X_AXIS);
230 r[d] = d * (e[-d] + padding);
232 broken[d] = b->break_status_dir () != CENTER;
236 if ( ly_number_pair_p (ew) )
237 width[d] += gh_scm2double (index_get_cell (ew, d));
238 if ( !broken[d] && (ly_number_pair_p (eh) ) )
239 height[d] += gh_scm2double (index_get_cell (eh, d));
240 if ( ly_number_pair_p (sp) )
241 shorten[d] += gh_scm2double (index_get_cell (sp, d));
243 while (flip (&d) != LEFT);
245 Real extra_short = 0;
246 // For 'Mixed' style pedals, i.e. a bracket preceded by text: Ped._____|
247 // need to shorten by the extent of the text grob
248 if ( to_boolean (me->get_grob_property ("text-start")) )
251 extra_short = padding;
252 if (Grob *textbit = unsmob_grob (me->get_grob_property("pedal-text")))
254 if (textbit->internal_has_interface(ly_symbol2scm("text-interface")))
255 // for plain text, e.g., Sost. Ped.
257 SCM text = textbit->get_grob_property("text");
258 if (gh_string_p (text)) {
259 SCM properties = Font_interface::font_alist_chain (me);
260 Molecule mol = Text_item::text2molecule (me, text, properties);
261 extra_short += mol.extent(X_AXIS).length() / 2;
265 shorten[RIGHT] -= thick;
268 shorten[LEFT] += extra_short ;
272 shorten[LEFT] -= me->get_broken_left_end_align () ;
273 shorten[RIGHT] += abs(width[RIGHT]) + thick - r[RIGHT];
278 // Shorten a ____/ on the right so that it will touch an adjoining \___
279 shorten[RIGHT] += abs(width[LEFT]) + abs(width[RIGHT]) + thick;
280 // Also shorten so that it ends just before the spanned note.
281 shorten[RIGHT] -= (r[LEFT] + r[RIGHT]);
284 me->set_grob_property ("edge-height", ly_interval2scm (height));
285 me->set_grob_property ("edge-widen", ly_interval2scm(width));
286 me->set_grob_property ("shorten-pair", ly_interval2scm (shorten));
292 static bool has_interface (Grob*);
294 ADD_INTERFACE (Pianopedal,"piano-pedal-interface",
296 "pedal-type edge-widen edge-height shorten-pair text-start left-widen right-widen pedal-text");
298 ADD_INTERFACE (Text_spanner,"text-spanner-interface",
299 "generic text spanner",
300 "dash-period if-text-padding dash-length edge-height edge-widen edge-text shorten-pair type thickness enclose-bounds width-correct");