]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-spanner.cc
af618e87ca33851fb25d5a0637e61f0ee68fe0ab
[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 lyric-extender)
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
28   Score_element * common = sp;
29   Direction d = LEFT;
30   do
31     {
32       common = common->common_refpoint( sp->get_bound (d), X_AXIS);
33     }
34   while (flip (&d) != LEFT);
35   Interval bounds;
36   
37   do
38     {
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]);
42     }
43   while (flip (&d) != LEFT);
44
45   
46   
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
55   */
56   if(l < w)
57     l = sqrt(l*w);
58
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 ();
65 }
66   
67 void
68 Hyphen_spanner::set_textitem (Direction d, Score_element* b)
69 {
70   elt_l_->set_bound (d, b);
71   elt_l_->add_dependency (b);
72 }
73
74 Hyphen_spanner::Hyphen_spanner (Spanner*s)
75 {
76   elt_l_ = s;
77 }