]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-spanner.cc
624f682be20234a3c1085a7c60e04e85ae908856
[lilypond.git] / lily / hyphen-spanner.cc
1 /*
2   hyphen-spanner.cc -- implement Hyphen_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999 Glen Prideaux <glenprideaux@iname.com>
7
8   (adapted from extender-spanner)
9 */
10
11 #include <math.h>
12
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"
20
21 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Hyphen_spanner,brew_molecule)
22
23 SCM 
24 Hyphen_spanner::brew_molecule (SCM smob)
25 {
26   Spanner * sp  =dynamic_cast<Spanner*> (unsmob_element (smob));
27   Molecule  mol;
28
29   Real leftext = sp->get_bound (LEFT)->extent (X_AXIS).length ();
30
31   Real ss = sp->paper_l ()->get_var ("staffspace");
32   Real lt = sp->paper_l ()->get_var ("stafflinethickness");
33   Real th = gh_scm2double (sp->get_elt_property ("thickness")) * lt ;
34   Real h = gh_scm2double (sp->get_elt_property ("height")) * ss;
35   Real l = gh_scm2double (sp->get_elt_property ("minimum-length")) * ss;  
36   Real w = sp->spanner_length () - leftext - ss/2; 
37
38
39   /* First try: just make the hyphen take 1/3 of the available space  
40    for length, use a geometric mean of the available space and some minimum
41   */
42   if(l < w)
43     l = sqrt(l*w);
44
45   Box b  (Interval ( (w-l)/2, (w+l)/2), Interval (h,h+th));
46   mol.add_molecule (sp->lookup_l ()->filledbox (b));
47   mol.translate_axis(leftext, X_AXIS);
48   return mol.create_scheme ();
49 }
50   
51 void
52 Hyphen_spanner::set_textitem (Direction d, Item* textitem_l)
53 {
54   elt_l_->set_bound (d, textitem_l);
55   elt_l_->add_dependency (textitem_l);
56 }
57
58 Hyphen_spanner::Hyphen_spanner (Spanner*s)
59 {
60   elt_l_ = s;
61 }