]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-spanner.cc
release: 1.3.89
[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 "paper-column.hh"
19 #include "spanner.hh"
20 #include "item.hh"
21
22 MAKE_SCHEME_CALLBACK(Hyphen_spanner,brew_molecule)
23
24 SCM 
25 Hyphen_spanner::brew_molecule (SCM smob)
26 {
27   Spanner * sp = dynamic_cast<Spanner*> (unsmob_element (smob));
28
29   Score_element * common = sp;
30   Direction d = LEFT;
31   do
32     {
33       common = common->common_refpoint( sp->get_bound (d), X_AXIS);
34     }
35   while (flip (&d) != LEFT);
36   Interval bounds;
37   
38   do
39     {
40       Real  x = sp->get_bound (d)->relative_coordinate (common, X_AXIS);
41       Interval ext =  sp->get_bound (d)->extent (X_AXIS);
42       bounds[d] = (x + ext[-d]);
43     }
44   while (flip (&d) != LEFT);
45
46   
47   
48   Real ss = sp->paper_l ()->get_var ("staffspace");
49   Real lt = sp->paper_l ()->get_var ("stafflinethickness");
50   Real th = gh_scm2double (sp->get_elt_property ("thickness")) * lt ;
51   Real h = gh_scm2double (sp->get_elt_property ("height")) * ss;
52   Real l = gh_scm2double (sp->get_elt_property ("minimum-length")) * ss;  
53   // The hyphen can exist in the word space of the left lyric ...
54   SCM space =  sp->get_bound (LEFT)->get_elt_property ("word-space");
55   if (gh_number_p (space))
56     {
57       bounds[LEFT] -=  gh_scm2double (space)*ss;
58     }
59   Real w  = bounds.length ();
60   /* for length, use a geometric mean of the available space and some minimum
61   */
62   if(l < w)
63     l = sqrt(l*w);
64   else
65     {
66       /* OK, we have a problem. Usually this means that we're on the
67          first column, and we have a long lyric which extends to near
68          the offset for stuff */
69       /* This test for being on the first column has been shamelessly
70          ripped from spanner.cc */
71       Paper_column *sc = dynamic_cast<Paper_column*> (sp->get_bound(LEFT)->column_l());
72       if (sc != NULL &&
73           sc->break_status_dir () == RIGHT)
74         {
75           /* We are on the first column, so it's probably harmless to
76              get the minimum length back by extending leftwards into
77              the space under the clef/key sig/time sig */
78           bounds[LEFT] = bounds[RIGHT] - l;
79         }
80       else 
81         {
82           /* We can't get the length desired. Maybe we should warn. */
83           l = w;
84         }
85     }
86   Box b  (Interval (-l/2,l/2), Interval (h,h+th));
87   Molecule mol (sp->lookup_l ()->filledbox (b));
88   mol.translate_axis (bounds.center ()
89                       -sp->relative_coordinate (common, X_AXIS),
90                       X_AXIS);
91   return mol.create_scheme ();
92 }
93   
94 void
95 Hyphen_spanner::set_textitem (Direction d, Score_element* b)
96 {
97   elt_l_->set_bound (d, b);
98   elt_l_->add_dependency (b);
99 }
100
101 Hyphen_spanner::Hyphen_spanner (Spanner*s)
102 {
103   elt_l_ = s;
104 }
105