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
36 Text_spanner::brew_molecule (SCM smob)
38 Grob *me= unsmob_grob (smob);
39 Spanner *spanner = dynamic_cast<Spanner*> (me);
41 if (spanner->internal_has_interface (ly_symbol2scm ("piano-pedal-interface")))
43 setup_pedal_bracket(spanner);
46 /* Ugh, must be same as Hairpin::brew_molecule. */
48 SCM itp= me->get_grob_property ("if-text-padding");
49 if (gh_number_p (itp))
50 padding = gh_scm2double (itp);
52 Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
55 Drul_array<bool> broken;
59 Item *b = spanner->get_bound (d);
60 broken[d] = b->break_status_dir () != CENTER;
65 span_points[d] = spanner->get_broken_left_end_align ();
67 span_points[d] = b->relative_coordinate (common, X_AXIS);
71 bool encl = to_boolean (me->get_grob_property ("enclose-bounds"));
72 span_points[d] = b->extent (common, X_AXIS)[encl ? d : -d];
75 while (flip (&d) != LEFT);
79 SCM properties = Font_interface::font_alist_chain (me);
80 SCM edge_text = me->get_grob_property ("edge-text");
81 Drul_array<Molecule> edge;
82 if (gh_pair_p (edge_text))
87 /* Don't repeat edge text for broken end */
91 SCM text = index_get_cell (edge_text, d);
97 edge[d] = Text_item::interpret_new_markup (smob, properties, text);
98 if (!edge[d].empty_b ())
99 edge[d].align_to (Y_AXIS, CENTER);
101 while (flip (&d) != LEFT);
105 Drul_array<Real> shorten;
109 SCM ew = me->get_grob_property ("edge-flare");
110 SCM s = me->get_grob_property ("shorten-pair");
113 span_points[LEFT] += gh_scm2double (ly_car (s));
114 span_points[RIGHT] -= gh_scm2double (ly_cdr (s));
118 span_points[LEFT] += gh_scm2double (ly_car (ew));
119 span_points[RIGHT] -= gh_scm2double (ly_cdr (ew));
122 Real thick = me->get_paper ()->get_var ("linethickness");
123 SCM st = me->get_grob_property ("thickness");
124 if (gh_number_p (st))
126 thick *= gh_scm2double (st);
129 Drul_array<Molecule> edge_line;
130 s = me->get_grob_property ("edge-height");
134 int dir = to_dir (me->get_grob_property ("direction"));
142 dx = gh_scm2double (index_get_cell (ew, d)) * d;
144 Real dy = gh_scm2double (index_get_cell (s, d)) * - dir;
146 edge_line[d] = Line_spanner::line_molecule (me, thick, dx, dy);
148 while (flip (&d) != LEFT);
154 Interval ext = edge[d].extent (X_AXIS);
156 edge[d].translate_axis (span_points[d], X_AXIS);
157 m.add_molecule (edge[d]);
158 edge_line[d].translate_axis (span_points[d], X_AXIS);
159 m.add_molecule (edge_line[d]);
161 span_points[d] += -d * ext[-d];
163 while (flip (&d) != LEFT);
165 Molecule l =Line_spanner::line_molecule (me, thick,
166 span_points.length (), 0);
167 l.translate_axis (span_points[LEFT], X_AXIS);
170 m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
171 return m.smobbed_copy ();
178 Piano pedal brackets are a special case of a text spanner.
179 Pedal up-down (restart) indicated by the angled right and left edges
180 of consecutive pedals touching exactly to form an __/\__
181 Chris Jackson <chris@fluffhouse.org.uk>
184 TODO: this should be moved somewhere else (?).
186 Perhaps make separate function for pedal-bracket.
191 This is broken broken.
193 All the tweak props should be unnecessary.
195 This should not be linked with Text_spanner.
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 eh = me->get_grob_property ("edge-height");
214 SCM sp = me->get_grob_property ("shorten-pair");
220 if (gh_number_p (pa))
221 padding = gh_scm2double (pa);
225 Item *b = me->get_bound (d);
227 e = b->extent (b, X_AXIS);
229 r[d] = d * (e[-d] + padding);
231 broken[d] = b->break_status_dir () != CENTER;
235 if (!broken[d] && (ly_number_pair_p (eh)))
236 height[d] += gh_scm2double (index_get_cell (eh, d));
237 if (ly_number_pair_p (sp))
238 shorten[d] += gh_scm2double (index_get_cell (sp, d));
240 while (flip (&d) != LEFT);
242 Real extra_short = 0;
244 // For 'Mixed' style pedals, i.e. a bracket preceded by text: Ped._____|
245 // need to shorten by the extent of the text grob
246 if (to_boolean (me->get_grob_property ("text-start")))
249 extra_short = padding;
250 if (Grob *textbit = unsmob_grob (me->get_grob_property("pedal-text")))
252 if (textbit->internal_has_interface(ly_symbol2scm("text-interface")))
253 // for plain text, e.g., Sost. Ped.
255 SCM text = textbit->get_grob_property("text");
256 if (gh_string_p (text)) {
257 SCM properties = Font_interface::font_alist_chain (me);
259 Molecule mol = Text_item::interpret_new_markup (me->self_scm (),
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 ("shorten-pair", ly_interval2scm (shorten));
291 static bool has_interface (Grob*);
293 ADD_INTERFACE (Pianopedal,"piano-pedal-interface",
295 "pedal-type edge-widen edge-height shorten-pair text-start left-widen right-widen pedal-text");
297 ADD_INTERFACE (Text_spanner,"text-spanner-interface",
298 "generic text spanner",
299 "dash-period if-text-padding dash-length edge-height edge-widen edge-text shorten-pair style thickness enclose-bounds width-correct");