2 hyphen-spanner.cc -- implement Hyphen_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2003 Glen Prideaux <glenprideaux@iname.com>
8 (adapted from lyric-extender)
15 #include "molecule.hh"
16 #include "paper-def.hh"
17 #include "hyphen-spanner.hh"
18 #include "paper-column.hh"
23 MAKE_SCHEME_CALLBACK (Hyphen_spanner,brew_molecule,1)
25 Hyphen_spanner::brew_molecule (SCM smob)
27 Spanner * sp = unsmob_spanner (smob);
28 Drul_array<Item*> bounds (sp->get_bound (LEFT),
29 sp->get_bound (RIGHT));
31 Grob * common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
37 Interval iv = bounds[d]->extent (common, X_AXIS);
39 span_points[d] = iv.is_empty ()
40 ? bounds[d]->relative_coordinate (common, X_AXIS)
43 while (flip (&d) != LEFT);
45 Real lt = sp->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
46 Real th = robust_scm2double (sp->get_grob_property ("thickness"), 1) * lt ;
47 Real h = robust_scm2double (sp->get_grob_property ("height"), 0.5);
51 Real dp = robust_scm2double (sp->get_grob_property ("dash-period"), 1.0);
52 Real dl = robust_scm2double (sp->get_grob_property ("length"), .5 );
57 Real l = span_points.length ();
58 int n = int (ceil (l/dp - 0.5));
62 Real space_left = l - dl - (n-1)* dp;
65 If there is not enough space, the hyphen should disappear.
70 Box b (Interval (0, dl), Interval (h,h+th));
71 Molecule dash_mol (Lookup::round_filled_box (b, 0.8 * lt));
74 for (int i = 0; i < n; i++)
76 Molecule m (dash_mol);
77 m.translate_axis (span_points[LEFT] + i * dp + space_left / 2, X_AXIS);
78 total.add_molecule (m);
81 total.translate_axis ( -sp->relative_coordinate (common, X_AXIS), X_AXIS);
82 return total.smobbed_copy ();
86 ADD_INTERFACE (Hyphen_spanner, "lyric-hyphen-interface",
87 "A centred hyphen is a simple line between lyrics used to divide syllables",
88 "thickness height dash-period length");