lilypond-1.3.65
[lilypond.git] / lily / hyphen-spanner.cc
blobaf618e87ca33851fb25d5a0637e61f0ee68fe0ab
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 "spanner.hh"
19 #include "item.hh"
21 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Hyphen_spanner,brew_molecule)
23 SCM
24 Hyphen_spanner::brew_molecule (SCM smob)
26 Spanner * sp = dynamic_cast<Spanner*> (unsmob_element (smob));
28 Score_element * common = sp;
29 Direction d = LEFT;
32 common = common->common_refpoint( sp->get_bound (d), X_AXIS);
34 while (flip (&d) != LEFT);
35 Interval bounds;
39 Real x = sp->get_bound (d)->relative_coordinate (common, X_AXIS);
40 Interval ext = sp->get_bound (d)->extent (X_AXIS);
41 bounds[d] = (x + ext[-d]);
43 while (flip (&d) != LEFT);
47 Real ss = sp->paper_l ()->get_var ("staffspace");
48 Real lt = sp->paper_l ()->get_var ("stafflinethickness");
49 Real th = gh_scm2double (sp->get_elt_property ("thickness")) * lt ;
50 Real h = gh_scm2double (sp->get_elt_property ("height")) * ss;
51 Real l = gh_scm2double (sp->get_elt_property ("minimum-length")) * ss;
52 Real w = bounds.length ();
53 /* First try: just make the hyphen take 1/3 of the available space
54 for length, use a geometric mean of the available space and some minimum
56 if(l < w)
57 l = sqrt(l*w);
59 Box b (Interval (-l/2,l/2), Interval (h,h+th));
60 Molecule mol (sp->lookup_l ()->filledbox (b));
61 mol.translate_axis (bounds.center ()
62 -sp->relative_coordinate (common, X_AXIS),
63 X_AXIS);
64 return mol.create_scheme ();
67 void
68 Hyphen_spanner::set_textitem (Direction d, Score_element* b)
70 elt_l_->set_bound (d, b);
71 elt_l_->add_dependency (b);
74 Hyphen_spanner::Hyphen_spanner (Spanner*s)
76 elt_l_ = s;