source file of the GNU LilyPond music typesetter
- (c) 1999--2003 Glen Prideaux <glenprideaux@iname.com>
+ (c) 1999--2004 Glen Prideaux <glenprideaux@iname.com>
(adapted from lyric-extender)
*/
#include "spanner.hh"
#include "item.hh"
-MAKE_SCHEME_CALLBACK (Hyphen_spanner,brew_molecule,1)
+MAKE_SCHEME_CALLBACK (Hyphen_spanner,brew_molecule,1)
SCM
Hyphen_spanner::brew_molecule (SCM smob)
{
Spanner * sp = unsmob_spanner (smob);
+ Drul_array<Item*> bounds (sp->get_bound (LEFT),
+ sp->get_bound (RIGHT));
+
+ Grob * common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
- Grob * common = sp;
+ Interval span_points;
Direction d = LEFT;
do
{
- common = common->common_refpoint (sp->get_bound (d), X_AXIS);
- }
- while (flip (&d) != LEFT);
- Interval bounds;
-
- do
- {
- Interval iv = sp->get_bound (d)->extent (common, X_AXIS);
+ Interval iv = bounds[d]->extent (common, X_AXIS);
- bounds[d] = iv.empty_b ()
- ? sp->get_bound (d)->relative_coordinate (common, X_AXIS)
+ span_points[d] = iv.is_empty ()
+ ? bounds[d]->relative_coordinate (common, X_AXIS)
: iv[-d];
}
while (flip (&d) != LEFT);
- Real lt = sp->get_paper ()->get_var ("linethickness");
- Real th = gh_scm2double (sp->get_grob_property ("thickness")) * lt ;
- Real h = gh_scm2double (sp->get_grob_property ("height"));
+ Real lt = sp->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
+ Real th = robust_scm2double (sp->get_grob_property ("thickness"), 1) * lt ;
+ Real h = robust_scm2double (sp->get_grob_property ("height"), 0.5);
// interval?
- Real l = gh_scm2double (sp->get_grob_property ("minimum-length"));
- Real x = gh_scm2double (sp->get_grob_property ("maximum-length"));
- // The hyphen can exist in the word space of the left lyric ...
- SCM space = sp->get_bound (LEFT)->get_grob_property ("word-space");
- if (gh_number_p (space))
- {
- bounds[LEFT] -= gh_scm2double (space);
- }
+
+ Real dp = robust_scm2double (sp->get_grob_property ("dash-period"), 1.0);
+ Real dl = robust_scm2double (sp->get_grob_property ("length"), .5 );
+
+ if (dp < dl)
+ dp = 1.5 * dl;
+
+ Real l = span_points.length ();
+ int n = int (ceil (l/dp - 0.5));
+ if (n <= 0)
+ n = 1;
+
+ Real space_left = l - dl - (n-1)* dp;
/*
- we should probably do something more intelligent when bounds is
- empty, but at least this doesn't crash.
- */
- Real w = bounds.empty_b () ? 0 : bounds.length ();
-
- /* for length, use a geometric mean of the available space and some minimum
+ If there is not enough space, the hyphen should disappear.
*/
- if (l < w)
- {
- l = sqrt (l*w);
- if (l > x)
- l = x;
- }
- else
+ if (space_left < 0)
+ return SCM_EOL;
+
+ Box b (Interval (0, dl), Interval (h,h+th));
+ Molecule dash_mol (Lookup::round_filled_box (b, 0.8 * lt));
+
+ Molecule total;
+ for (int i = 0; i < n; i++)
{
- /* OK, we have a problem. Usually this means that we're on the
- first column, and we have a long lyric which extends to near
- the offset for stuff */
- /* This test for being on the first column has been shamelessly
- ripped from spanner.cc */
- Paper_column *sc = dynamic_cast<Paper_column*> (sp->get_bound (LEFT)->get_column ());
- if (sc != NULL &&
- sc->break_status_dir () == RIGHT)
- {
- /* We are on the first column, so it's probably harmless to
- get the minimum length back by extending leftwards into
- the space under the clef/key sig/time sig */
- bounds[LEFT] = bounds[RIGHT] - l;
- }
- else
- {
- /* We can't get the length desired. Maybe we should warn. */
- l = w;
- }
+ Molecule m (dash_mol);
+ m.translate_axis (span_points[LEFT] + i * dp + space_left / 2, X_AXIS);
+ total.add_molecule (m);
}
- Box b (Interval (-l/2,l/2), Interval (h,h+th));
- Molecule mol (Lookup::filledbox (b));
- Real ct = bounds.empty_b () ? 0 : bounds.center () ;
- mol.translate_axis (ct -sp->relative_coordinate (common, X_AXIS), X_AXIS);
- return mol.smobbed_copy ();
-}
-
-void
-Hyphen_spanner::set_textitem (Direction d, Grob* b)
-{
- elt_->set_bound (d, b);
- elt_->add_dependency (b);
-}
-Hyphen_spanner::Hyphen_spanner (Spanner*s)
-{
- elt_ = s;
+ total.translate_axis ( -sp->relative_coordinate (common, X_AXIS), X_AXIS);
+ return total.smobbed_copy ();
}
-
ADD_INTERFACE (Hyphen_spanner, "lyric-hyphen-interface",
- "A centred hyphen is a simple line between lyrics used to divide
-syllables. The length of the hyphen line should stretch based on the
-size of the gap between syllables.",
- "thickness height minimum-length maximum-length word-space");
+ "A centred hyphen is a simple line between lyrics used to divide syllables",
+ "thickness height dash-period length");
+