2 hyphen-spanner.cc -- implement Hyphen_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 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"
22 MAKE_SCHEME_CALLBACK(Hyphen_spanner,brew_molecule,1)
25 Hyphen_spanner::brew_molecule (SCM smob)
27 Spanner * sp = dynamic_cast<Spanner*> (unsmob_element (smob));
29 Score_element * common = sp;
33 common = common->common_refpoint( sp->get_bound (d), X_AXIS);
35 while (flip (&d) != LEFT);
40 bounds[d] = sp->get_bound (d)->extent (common, X_AXIS)[-d];
42 while (flip (&d) != LEFT);
46 Real ss = sp->paper_l ()->get_var ("staffspace");
47 Real lt = sp->paper_l ()->get_var ("stafflinethickness");
48 Real th = gh_scm2double (sp->get_elt_property ("thickness")) * lt ;
49 Real h = gh_scm2double (sp->get_elt_property ("height")) * ss;
50 Real l = gh_scm2double (sp->get_elt_property ("minimum-length")) * ss;
51 // The hyphen can exist in the word space of the left lyric ...
52 SCM space = sp->get_bound (LEFT)->get_elt_property ("word-space");
53 if (gh_number_p (space))
55 bounds[LEFT] -= gh_scm2double (space)*ss;
57 Real w = bounds.length ();
58 /* for length, use a geometric mean of the available space and some minimum
64 /* OK, we have a problem. Usually this means that we're on the
65 first column, and we have a long lyric which extends to near
66 the offset for stuff */
67 /* This test for being on the first column has been shamelessly
68 ripped from spanner.cc */
69 Paper_column *sc = dynamic_cast<Paper_column*> (sp->get_bound(LEFT)->column_l());
71 sc->break_status_dir () == RIGHT)
73 /* We are on the first column, so it's probably harmless to
74 get the minimum length back by extending leftwards into
75 the space under the clef/key sig/time sig */
76 bounds[LEFT] = bounds[RIGHT] - l;
80 /* We can't get the length desired. Maybe we should warn. */
84 Box b (Interval (-l/2,l/2), Interval (h,h+th));
85 Molecule mol (sp->lookup_l ()->filledbox (b));
86 mol.translate_axis (bounds.center ()
87 -sp->relative_coordinate (common, X_AXIS),
89 return mol.create_scheme ();
93 Hyphen_spanner::set_textitem (Direction d, Score_element* b)
95 elt_l_->set_bound (d, b);
96 elt_l_->add_dependency (b);
99 Hyphen_spanner::Hyphen_spanner (Spanner*s)