]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-spanner.cc
release: 1.2.15
[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 /*
12   TODO: too complicated implementation.  Why the dx_drul?.
13  */
14
15 #include <math.h>
16 #include "box.hh"
17 #include "debug.hh"
18 #include "lookup.hh"
19 #include "molecule.hh"
20 #include "paper-column.hh"
21 #include "paper-def.hh"
22 #include "hyphen-spanner.hh"
23
24 Hyphen_spanner::Hyphen_spanner ()
25   : Directional_spanner ()
26 {
27   dx_f_drul_[LEFT] = dx_f_drul_[RIGHT] = 0.0;
28 }
29
30 // UGH - is this even used?
31 Offset
32 Hyphen_spanner::center () const
33 {
34   Real dx = extent (X_AXIS).length ();
35
36   return Offset (dx / 2, 0);
37 }
38
39 Molecule*
40 Hyphen_spanner::do_brew_molecule_p () const
41 {
42   Molecule* mol_p = new Molecule;
43
44   Real w = extent (X_AXIS).length ();
45
46   w += (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]);
47
48   Real th = paper_l ()->get_realvar (hyphen_thickness_scm_sym);
49   Real h = paper_l ()->get_realvar (hyphen_height_scm_sym);
50
51   // UGH. First try: just make the hyphen take 1/3 of the available space  
52   // for length, use a geometric mean of the available space and some minimum
53   Real l = paper_l ()->get_realvar (hyphen_minimum_length_scm_sym);
54   if(l < w)
55     l = sqrt(l*w);
56   Molecule a = lookup_l ()->filledbox ( Box (Interval ((w-l)/2,(w+l)/2), Interval (h,h+th)));
57   a.translate (Offset (dx_f_drul_[LEFT], 0));
58
59   mol_p->add_molecule (a);
60
61   return mol_p;
62 }
63
64 Interval
65 Hyphen_spanner::do_height () const
66 {
67   return Interval (0,0);
68 }
69
70 void
71 Hyphen_spanner::do_post_processing ()
72 {
73   // UGH
74   Real gap = paper_l ()->get_realvar (interline_scm_sym);
75
76   Direction d = LEFT;
77   do
78     {
79       Item* t = spanned_drul_[d]
80         ? spanned_drul_[d] : spanned_drul_[(Direction)-d];
81       if (d == LEFT)
82         dx_f_drul_[d] += t->extent (X_AXIS).length ();
83       else
84         dx_f_drul_[d] -= d * gap / 2;
85     }
86   while (flip(&d) != LEFT);
87 }
88
89   
90 void
91 Hyphen_spanner::set_textitem (Direction d, Item* textitem_l)
92 {
93   set_bounds (d, textitem_l);
94   add_dependency (textitem_l);
95 }
96