X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Fhyphen-spanner.cc;h=8334e494cc62a4caef7ac734dd133a68b3405443;hb=4c8187e65dd9708d7733692842acc696da121bf1;hp=c222091ef45a55af3243c9f72c7e16b54b1e6c4f;hpb=5e963da4031a9efceda94f4969785bf6fa13048b;p=lilypond.git diff --git a/lily/hyphen-spanner.cc b/lily/hyphen-spanner.cc index c222091ef4..8334e494cc 100644 --- a/lily/hyphen-spanner.cc +++ b/lily/hyphen-spanner.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1999 Glen Prideaux + (c) 1999--2003 Glen Prideaux (adapted from lyric-extender) */ @@ -19,98 +19,72 @@ #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 = dynamic_cast (unsmob_grob (smob)); + Spanner * sp = unsmob_spanner (smob); + Drul_array 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->paper_l ()->get_var ("stafflinethickness"); + Real lt = sp->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); Real th = gh_scm2double (sp->get_grob_property ("thickness")) * lt ; Real h = gh_scm2double (sp->get_grob_property ("height")); // 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 = gh_scm2double (sp->get_grob_property ("dash-period")); + Real dl = gh_scm2double (sp->get_grob_property ("length")); + + 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 (sp->get_bound (LEFT)->column_l ()); - 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_l_->set_bound (d, b); - elt_l_->add_dependency (b); -} -Hyphen_spanner::Hyphen_spanner (Spanner*s) -{ - elt_l_ = 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", + "thickness height dash-period length"); + +