2 vaticana-ligature.cc -- implement Vaticana_ligature
4 source file of the GNU LilyPond music typesetter
6 (c) 2003--2004 Juergen Reuter <reuter@ipd.uka.de>
11 #include "vaticana-ligature.hh"
12 #include "font-interface.hh"
13 #include "molecule.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "note-head.hh"
17 #include "paper-def.hh"
22 vaticana_brew_cauda (Grob *me,
28 bool on_staffline = Staff_symbol_referencer::on_staffline (me, pos);
29 int interspaces = Staff_symbol_referencer::line_count (me)-1;
30 bool above_staff = pos > interspaces;
34 me->programming_error ("flexa cauda: invalid delta_pitch; assuming -1");
40 if (delta_pitch >= -1)
42 else if (delta_pitch >= -2)
49 if (delta_pitch >= -1)
54 else if (delta_pitch >= -2)
56 else if (delta_pitch >= -3)
61 Box cauda_box (Interval (0, thickness), Interval (-length, 0));
62 return Lookup::round_filled_box (cauda_box, blotdiameter);
66 * TODO: move this function to class Lookup?
69 vaticana_brew_flexa (Grob *me,
73 Real staff_space = Staff_symbol_referencer::staff_space (me);
74 Molecule molecule = Molecule ();
75 Real right_height = 0.6 * staff_space;
78 SCM flexa_height_scm = me->get_grob_property ("flexa-height");
79 if (flexa_height_scm != SCM_EOL)
81 interval = gh_scm2int (flexa_height_scm);
85 me->warning ("Vaticana_ligature: "
86 "flexa-height undefined; assuming 0");
92 me->warning (_ ("ascending vaticana style flexa"));
95 Real width = robust_scm2double ( me->get_grob_property ("flexa-width"), 2);
98 * Compensate curve thickness that appears to be smaller in steep
103 min (0.12 * abs(interval), 0.3) * staff_space;
106 * Compensate optical illusion regarding vertical position of left
107 * and right endings due to curved shape.
109 Real ypos_correction = -0.1*staff_space * sign(interval);
110 Real interval_correction = 0.2*staff_space * sign(interval);
111 Real corrected_interval = interval*staff_space + interval_correction;
114 * middle curve of flexa shape
117 curve.control_[0] = Offset (0.00 * width, 0.0);
118 curve.control_[1] = Offset (0.33 * width, corrected_interval / 2.0);
119 curve.control_[2] = Offset (0.66 * width, corrected_interval / 2.0);
120 curve.control_[3] = Offset (1.00 * width, corrected_interval / 2.0);
122 Bezier top_curve = curve, bottom_curve = curve;
123 for (int i = 0; i < 4; i++)
125 Real curve_thickness = 0.33 * ((3 - i)*left_height + i*right_height);
126 top_curve.control_[i] += Offset (0, 0.5 * curve_thickness);
127 bottom_curve.control_[i] -= Offset (0, 0.5 * curve_thickness);
132 Molecule solid_head =
133 Lookup::bezier_sandwich (top_curve, bottom_curve);
134 molecule.add_molecule (solid_head);
138 Bezier inner_top_curve = top_curve;
139 inner_top_curve.translate (Offset (0.0, -line_thickness));
141 Lookup::bezier_sandwich (top_curve, inner_top_curve);
142 molecule.add_molecule(top_edge);
144 Bezier inner_bottom_curve = bottom_curve;
145 inner_bottom_curve.translate (Offset (0.0, +line_thickness));
146 Molecule bottom_edge =
147 Lookup::bezier_sandwich (bottom_curve, inner_bottom_curve);
148 molecule.add_molecule(bottom_edge);
151 * TODO: Use horizontal slope with proper slope value rather
152 * than filled box for left edge, since the filled box stands
153 * out from the flexa shape if the interval is big and the line
154 * thickness small. The difficulty here is to compute a proper
155 * slope value, as it should roughly be equal with the slope of
156 * the left end of the bezier curve.
158 Box left_edge_box (Interval (0, line_thickness),
159 Interval (-0.5*left_height, +0.5*left_height));
160 Molecule left_edge = Lookup::filled_box (left_edge_box);
161 molecule.add_molecule(left_edge);
163 Box right_edge_box (Interval (-line_thickness, 0),
164 Interval (-0.5*right_height, +0.5*right_height));
165 Molecule right_edge = Lookup::filled_box (right_edge_box);
166 right_edge.translate_axis (width, X_AXIS);
167 right_edge.translate_axis (corrected_interval / 2.0, Y_AXIS);
168 molecule.add_molecule(right_edge);
170 molecule.translate_axis (ypos_correction, Y_AXIS);
175 vaticana_brew_join (Grob *me, int delta_pitch,
176 Real join_thickness, Real blotdiameter)
178 Real staff_space = Staff_symbol_referencer::staff_space (me);
181 me->programming_error (_f ("Vaticana_ligature: "
182 "zero join (delta_pitch == 0)"));
185 Interval x_extent = Interval (0, join_thickness);
186 Interval y_extent = (delta_pitch > 0) ?
187 Interval (0, delta_pitch * 0.5 * staff_space) : // ascending join
188 Interval (delta_pitch * 0.5 * staff_space, 0); // descending join
189 Box join_box (x_extent, y_extent);
190 return Lookup::round_filled_box (join_box, blotdiameter);
194 vaticana_add_ledger_lines (Grob *me, Molecule *out, int pos, Real offs,
195 bool ledger_take_space)
197 int interspaces = Staff_symbol_referencer::line_count (me)-1;
198 if (abs (pos) - interspaces > 1)
200 Interval hd = out->extent (X_AXIS);
201 Real left_ledger_protusion = hd.length ()/4;
202 Real right_ledger_protusion = left_ledger_protusion;
204 Interval l_extents = Interval (hd[LEFT] - left_ledger_protusion,
205 hd[RIGHT] + right_ledger_protusion);
206 Molecule ledger_lines =
207 Note_head::brew_ledger_lines (me, pos, interspaces,
210 ledger_lines.translate_axis (offs, Y_AXIS);
211 out->add_molecule (ledger_lines);
216 vaticana_brew_primitive (Grob *me, bool ledger_take_space)
218 SCM glyph_name_scm = me->get_grob_property ("glyph-name");
219 if (glyph_name_scm == SCM_EOL)
221 me->programming_error ("Vaticana_ligature: "
222 "undefined glyph-name -> ignoring grob");
226 String glyph_name = ly_scm2string (glyph_name_scm);
229 int flexa_height = 0;
230 Real thickness = robust_scm2double ( me->get_grob_property ("thickness"), 1);
232 Real line_thickness =
233 thickness * me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
236 (me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")));
238 int pos = (int)rint (Staff_symbol_referencer::get_position (me));
240 SCM delta_pitch_scm = me->get_grob_property ("delta-pitch");
242 if (delta_pitch_scm != SCM_EOL)
243 delta_pitch = gh_scm2int (delta_pitch_scm);
247 Real x_offset = robust_scm2double ( me->get_grob_property ("x-offset"), 0);
249 bool add_stem = to_boolean (me->get_grob_property ("add-stem"));
250 bool add_cauda = to_boolean (me->get_grob_property ("add-cauda"));
251 bool add_join = to_boolean (me->get_grob_property ("add-join"));
253 if (!String::compare (glyph_name, ""))
256 * This is an empty head. This typically applies for the right
257 * side of a curved flexa shape, which is already typeset by the
258 * associated left side head. The only possible thing left to
259 * do is to draw a vertical join to the next head. (Urgh: need
262 Real staff_space = Staff_symbol_referencer::staff_space (me);
263 Real flexa_width = robust_scm2double ( me->get_grob_property ("flexa-width"), 2) *staff_space;
265 Lookup::blank (Box (Interval (0, 0.5*flexa_width), Interval (0,0)));
267 else if (!String::compare (glyph_name, "flexa"))
269 out = vaticana_brew_flexa (me, true, line_thickness);
274 Font_interface::get_default_font (me)->
275 find_by_name ("noteheads-" + glyph_name);
277 out.translate_axis (x_offset, X_AXIS);
278 Real head_width = out.extent (X_AXIS).length ();
283 vaticana_brew_cauda (me, pos, delta_pitch,
284 line_thickness, blotdiameter);
285 out.add_molecule (cauda);
291 vaticana_brew_cauda (me, pos, -1,
292 line_thickness, blotdiameter);
293 stem.translate_axis (head_width - line_thickness, X_AXIS);
294 out.add_molecule (stem);
300 vaticana_brew_join (me, delta_pitch, line_thickness, blotdiameter);
301 join.translate_axis (head_width - line_thickness, X_AXIS);
302 out.add_molecule (join);
305 vaticana_add_ledger_lines(me, &out, pos, 0, ledger_take_space);
306 if (!String::compare (glyph_name, "flexa"))
309 vaticana_add_ledger_lines(me, &out, pos, 0.5*flexa_height,
316 MAKE_SCHEME_CALLBACK (Vaticana_ligature, brew_ligature_primitive, 1);
318 Vaticana_ligature::brew_ligature_primitive (SCM smob)
320 Grob *me = unsmob_grob (smob);
321 SCM primitive = vaticana_brew_primitive (me, false).smobbed_copy ();
325 MAKE_SCHEME_CALLBACK (Vaticana_ligature, brew_molecule, 1);
327 Vaticana_ligature::brew_molecule (SCM)
332 ADD_INTERFACE (Vaticana_ligature, "vaticana-ligature-interface",
333 "A vaticana style gregorian ligature",
334 "glyph-name flexa-height flexa-width thickness add-cauda "
335 "add-stem add-join delta-pitch x-offset "
336 "ligature-primitive-callback");