X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fhyphen-spanner.cc;h=6b42b5b5547e175a953f47b0bb3bd13244810f41;hb=38d60c0c4e8c29beccd4acfd07aadf1cdea74097;hp=624f682be20234a3c1085a7c60e04e85ae908856;hpb=c21d49df60cb97801ab33ab8a1bad6f2c81cd820;p=lilypond.git diff --git a/lily/hyphen-spanner.cc b/lily/hyphen-spanner.cc index 624f682be2..6b42b5b554 100644 --- a/lily/hyphen-spanner.cc +++ b/lily/hyphen-spanner.cc @@ -5,7 +5,7 @@ (c) 1999 Glen Prideaux - (adapted from extender-spanner) + (adapted from lyric-extender) */ #include @@ -15,47 +15,102 @@ #include "molecule.hh" #include "paper-def.hh" #include "hyphen-spanner.hh" +#include "paper-column.hh" #include "spanner.hh" #include "item.hh" -MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Hyphen_spanner,brew_molecule) +MAKE_SCHEME_CALLBACK (Hyphen_spanner,brew_molecule,1) SCM Hyphen_spanner::brew_molecule (SCM smob) { - Spanner * sp =dynamic_cast (unsmob_element (smob)); - Molecule mol; + Spanner * sp = unsmob_spanner (smob); - Real leftext = sp->get_bound (LEFT)->extent (X_AXIS).length (); + Grob * common = sp; + 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); - Real ss = sp->paper_l ()->get_var ("staffspace"); + bounds[d] = iv.empty_b () + ? sp->get_bound (d)->relative_coordinate (common, X_AXIS) + : iv[-d]; + } + while (flip (&d) != LEFT); + Real lt = sp->paper_l ()->get_var ("stafflinethickness"); - Real th = gh_scm2double (sp->get_elt_property ("thickness")) * lt ; - Real h = gh_scm2double (sp->get_elt_property ("height")) * ss; - Real l = gh_scm2double (sp->get_elt_property ("minimum-length")) * ss; - Real w = sp->spanner_length () - leftext - ss/2; - - - /* First try: just make the hyphen take 1/3 of the available space - for length, use a geometric mean of the available space and some minimum - */ - if(l < w) - l = sqrt(l*w); - - Box b (Interval ( (w-l)/2, (w+l)/2), Interval (h,h+th)); - mol.add_molecule (sp->lookup_l ()->filledbox (b)); - mol.translate_axis(leftext, X_AXIS); - return mol.create_scheme (); + 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); + } + + /* + 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 (l < w) + { + l = sqrt (l*w); + if (l > x) + l = x; + } + else + { + /* 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; + } + } + 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, Item* textitem_l) +Hyphen_spanner::set_textitem (Direction d, Grob* b) { - elt_l_->set_bound (d, textitem_l); - elt_l_->add_dependency (textitem_l); + elt_l_->set_bound (d, b); + elt_l_->add_dependency (b); } Hyphen_spanner::Hyphen_spanner (Spanner*s) { elt_l_ = s; } +