lilypond-1.3.124
[lilypond.git] / lily / hyphen-spanner.cc
blob6c0dd240ae409ed10560ce13a893c49b4581edcd
1 /*
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)
9 */
11 #include <math.h>
13 #include "box.hh"
14 #include "lookup.hh"
15 #include "molecule.hh"
16 #include "paper-def.hh"
17 #include "hyphen-spanner.hh"
18 #include "paper-column.hh"
19 #include "spanner.hh"
20 #include "item.hh"
22 MAKE_SCHEME_CALLBACK(Hyphen_spanner,brew_molecule,1)
24 SCM
25 Hyphen_spanner::brew_molecule (SCM smob)
27 Spanner * sp = dynamic_cast<Spanner*> (unsmob_grob (smob));
29 Grob * common = sp;
30 Direction d = LEFT;
33 common = common->common_refpoint( sp->get_bound (d), X_AXIS);
35 while (flip (&d) != LEFT);
36 Interval bounds;
40 bounds[d] = sp->get_bound (d)->extent (common, X_AXIS)[-d];
42 while (flip (&d) != LEFT);
44 Real lt = sp->paper_l ()->get_var ("stafflinethickness");
45 Real th = gh_scm2double (sp->get_grob_property ("thickness")) * lt ;
46 Real h = gh_scm2double (sp->get_grob_property ("height"));
47 Real l = gh_scm2double (sp->get_grob_property ("minimum-length"));
48 // The hyphen can exist in the word space of the left lyric ...
49 SCM space = sp->get_bound (LEFT)->get_grob_property ("word-space");
50 if (gh_number_p (space))
52 bounds[LEFT] -= gh_scm2double (space);
54 Real w = bounds.length ();
55 /* for length, use a geometric mean of the available space and some minimum
57 if(l < w)
58 l = sqrt(l*w);
59 else
61 /* OK, we have a problem. Usually this means that we're on the
62 first column, and we have a long lyric which extends to near
63 the offset for stuff */
64 /* This test for being on the first column has been shamelessly
65 ripped from spanner.cc */
66 Paper_column *sc = dynamic_cast<Paper_column*> (sp->get_bound(LEFT)->column_l());
67 if (sc != NULL &&
68 sc->break_status_dir () == RIGHT)
70 /* We are on the first column, so it's probably harmless to
71 get the minimum length back by extending leftwards into
72 the space under the clef/key sig/time sig */
73 bounds[LEFT] = bounds[RIGHT] - l;
75 else
77 /* We can't get the length desired. Maybe we should warn. */
78 l = w;
81 Box b (Interval (-l/2,l/2), Interval (h,h+th));
82 Molecule mol (Lookup::filledbox (b));
83 mol.translate_axis (bounds.center ()
84 -sp->relative_coordinate (common, X_AXIS),
85 X_AXIS);
86 return mol.smobbed_copy ();
89 void
90 Hyphen_spanner::set_textitem (Direction d, Grob* b)
92 elt_l_->set_bound (d, b);
93 elt_l_->add_dependency (b);
96 Hyphen_spanner::Hyphen_spanner (Spanner*s)
98 elt_l_ = s;