]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-spanner.cc
a4ddc8c75014625cba86337adae040b8a93142bc
[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 #include "dimension-cache.hh"
24
25 Hyphen_spanner::Hyphen_spanner (SCM s)
26   : Spanner (s)
27 {
28   dx_f_drul_[LEFT] = dx_f_drul_[RIGHT] = 0.0;
29
30   set_extent_callback (Score_element::point_dimension_callback,Y_AXIS);
31 }
32
33 MAKE_SCHEME_SCORE_ELEMENT_CALLBACKS(Hyphen_spanner)
34 Molecule 
35 Hyphen_spanner::do_brew_molecule () const
36 {
37   Molecule  mol;
38
39   Real w = spanner_length ();
40
41   w += (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]);
42
43   Real th = paper_l ()->get_var ("hyphen_thickness");
44   Real h = paper_l ()->get_var ("hyphen_height");
45
46   // UGH. First try: just make the hyphen take 1/3 of the available space  
47   // for length, use a geometric mean of the available space and some minimum
48   Real l = paper_l ()->get_var ("hyphen_minimum_length");
49   if(l < w)
50     l = sqrt(l*w);
51   Molecule a = lookup_l ()->filledbox ( Box (Interval ((w-l)/2,(w+l)/2), Interval (h,h+th)));
52   a.translate (Offset (dx_f_drul_[LEFT], 0));
53
54   mol.add_molecule (a);
55
56   return mol;
57 }
58
59
60 void
61 Hyphen_spanner::after_line_breaking ()
62 {
63   // UGH
64   Real gap = paper_l ()->get_var ("interline");
65
66   Direction d = LEFT;
67   do
68     {
69       Item* t = get_bound (d)
70         ? get_bound (d) : get_bound ((Direction)-d);
71       if (d == LEFT)
72         dx_f_drul_[d] += t->extent (X_AXIS).length ();
73       else
74         dx_f_drul_[d] -= d * gap / 2;
75     }
76   while (flip(&d) != LEFT);
77 }
78
79   
80 void
81 Hyphen_spanner::set_textitem (Direction d, Item* textitem_l)
82 {
83   set_bound (d, textitem_l);
84   add_dependency (textitem_l);
85 }
86
87