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"
21 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Hyphen_spanner
,brew_molecule
)
24 Hyphen_spanner::brew_molecule (SCM smob
)
26 Spanner
* sp
= dynamic_cast<Spanner
*> (unsmob_element (smob
));
28 Score_element
* common
= sp
;
32 common
= common
->common_refpoint( sp
->get_bound (d
), X_AXIS
);
34 while (flip (&d
) != LEFT
);
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
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
),
64 return mol
.create_scheme ();
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
)