]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-spanner.cc
patch::: 1.3.76.gp1
[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_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   // The hyphen can exist in the word space of the left lyric ...
53   SCM space =  sp->get_bound (LEFT)->get_elt_property ("word-space");
54   if (gh_number_p (space))
55     {
56       bounds[LEFT] -=  gh_scm2double (space)*ss;
57     }
58   Real w  = bounds.length ();
59   /* for length, use a geometric mean of the available space and some minimum
60   */
61   if(l < w)
62     l = sqrt(l*w);
63
64   Box b  (Interval (-l/2,l/2), Interval (h,h+th));
65   Molecule mol (sp->lookup_l ()->filledbox (b));
66   mol.translate_axis (bounds.center ()
67                       -sp->relative_coordinate (common, X_AXIS),
68                       X_AXIS);
69   return mol.create_scheme ();
70 }
71   
72 void
73 Hyphen_spanner::set_textitem (Direction d, Score_element* b)
74 {
75   elt_l_->set_bound (d, b);
76   elt_l_->add_dependency (b);
77 }
78
79 Hyphen_spanner::Hyphen_spanner (Spanner*s)
80 {
81   elt_l_ = s;
82 }