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,set_spacing_rods,1);
25 Hyphen_spanner::set_spacing_rods (SCM smob)
27 Grob*me = unsmob_grob (smob);
30 Spanner*sp = dynamic_cast<Spanner*> (me);
31 Item * l = sp->get_bound (LEFT);
32 Item * r = sp->get_bound (RIGHT);
33 rod.item_l_drul_[LEFT] = l;
34 rod.item_l_drul_[RIGHT] =r;
36 gh_scm2double (me->get_grob_property ("minimum-length"))
37 + l->extent (l, X_AXIS)[RIGHT]
38 - r->extent (r, X_AXIS)[LEFT];
41 return SCM_UNSPECIFIED;
44 MAKE_SCHEME_CALLBACK (Hyphen_spanner,brew_molecule,1)
46 Hyphen_spanner::brew_molecule (SCM smob)
48 Spanner * sp = unsmob_spanner (smob);
54 common = common->common_refpoint (sp->get_bound (d), X_AXIS);
56 while (flip (&d) != LEFT);
61 Interval iv = sp->get_bound (d)->extent (common, X_AXIS);
63 bounds[d] = iv.is_empty ()
64 ? sp->get_bound (d)->relative_coordinate (common, X_AXIS)
67 while (flip (&d) != LEFT);
69 Real lt = sp->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
70 Real th = gh_scm2double (sp->get_grob_property ("thickness")) * lt ;
71 Real h = gh_scm2double (sp->get_grob_property ("height"));
74 Real x = gh_scm2double (sp->get_grob_property ("maximum-length"));
75 SCM space = sp->get_bound (LEFT)->get_grob_property ("word-space");
77 Real word_space = 1.0;
78 if (gh_number_p (space))
80 word_space = gh_scm2double (space);
84 We remove word space from the distance so it doesn't look like an extender.
87 Real l = (gh_scm2double (sp->get_grob_property ("minimum-length"))
88 - word_space ) >? word_space;
92 we should probably do something more intelligent when bounds is
93 empty, but at least this doesn't crash.
95 Real w = bounds.is_empty () ? 0 : bounds.length ();
97 /* for length, use a geometric mean of the available space and some minimum
107 /* OK, we have a problem. Usually this means that we're on the
108 first column, and we have a long lyric which extends to near
109 the offset for stuff */
110 /* This test for being on the first column has been shamelessly
111 ripped from spanner.cc */
112 Paper_column *sc = dynamic_cast<Paper_column*> (sp->get_bound (LEFT)->get_column ());
114 sc->break_status_dir () == RIGHT)
116 /* We are on the first column, so it's probably harmless to
117 get the minimum length back by extending leftwards into
118 the space under the clef/key sig/time sig */
119 bounds[LEFT] = bounds[RIGHT] - l;
123 /* We can't get the length desired. Maybe we should warn. */
127 Box b (Interval (-l/2,l/2), Interval (h,h+th));
128 Molecule mol (Lookup::filledbox (b));
129 Real ct = bounds.is_empty () ? 0 : bounds.center () ;
130 mol.translate_axis (ct -sp->relative_coordinate (common, X_AXIS), X_AXIS);
131 return mol.smobbed_copy ();
135 Hyphen_spanner::set_textitem (Direction d, Grob* b)
137 elt_->set_bound (d, b);
138 elt_->add_dependency (b);
141 Hyphen_spanner::Hyphen_spanner (Spanner*s)
148 ADD_INTERFACE (Hyphen_spanner, "lyric-hyphen-interface",
149 "A centred hyphen is a simple line between lyrics used to divide syllables",
150 "thickness height minimum-length maximum-length word-space");