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