]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-hyphen.cc
*** empty log message ***
[lilypond.git] / lily / lyric-hyphen.cc
1 /*
2   hyphen-spanner.cc -- implement Hyphen_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2003--2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "lyric-hyphen.hh"
10
11 #include <math.h>
12
13 #include "lookup.hh"
14 #include "output-def.hh"
15 #include "paper-column.hh"
16 #include "moment.hh"
17
18 MAKE_SCHEME_CALLBACK (Hyphen_spanner,print,1)
19 SCM 
20 Hyphen_spanner::print (SCM smob)
21 {
22   Spanner * me = unsmob_spanner (smob);
23   Drul_array<Item*> bounds (me->get_bound (LEFT),
24                             me->get_bound (RIGHT));
25
26   if (bounds[LEFT]->break_status_dir ()
27       && Paper_column::when_mom (bounds[LEFT]) == Paper_column::when_mom (bounds[RIGHT]->get_column ()))
28     return SCM_EOL;
29   
30   Grob * common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
31
32   Interval span_points;
33   Direction d = LEFT;
34   do
35     {
36       Interval iv = bounds[d]->extent (common, X_AXIS);
37
38       span_points[d] = iv.is_empty ()
39         ? bounds[d]->relative_coordinate (common, X_AXIS)
40         : iv[-d];
41     }
42   while (flip (&d) != LEFT);
43   
44   Real lt = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
45   Real th = robust_scm2double (me->get_property ("thickness"), 1) * lt ;
46   Real h = robust_scm2double (me->get_property ("height"), 0.5);
47
48   // interval?
49   
50   Real dp = robust_scm2double (me->get_property ("dash-period"), 1.0);
51   Real dl = robust_scm2double (me->get_property ("length"), .5 );
52
53   if (dp < dl)
54     dp = 1.5 * dl;
55
56   Real l = span_points.length ();
57   int n = int (ceil (l/dp - 0.5));
58   if (n <= 0)
59     n = 1;
60
61   Real space_left = l - dl - (n-1)* dp;
62
63   /*
64     If there is not enough space, the hyphen should disappear, but not
65     at the end of the line.
66    */
67   if (space_left < 0.0
68       && !bounds[RIGHT]->break_status_dir ())
69     return SCM_EOL;
70
71   space_left = space_left >? 0.0;
72   
73   Box b (Interval (0, dl), Interval (h,h+th));
74   Stencil dash_mol (Lookup::round_filled_box (b, 0.8 * lt));
75
76   Stencil total;
77   for (int i = 0; i < n; i++)
78     {
79       Stencil m (dash_mol);
80       m.translate_axis (span_points[LEFT] + i * dp + space_left / 2, X_AXIS);
81       total.add_stencil (m);
82     }
83
84   total.translate_axis ( -me->relative_coordinate (common, X_AXIS), X_AXIS);
85   return total.smobbed_copy ();
86 }
87
88
89 MAKE_SCHEME_CALLBACK (Hyphen_spanner,set_spacing_rods,1);
90 SCM
91 Hyphen_spanner::set_spacing_rods (SCM smob)
92 {
93   Grob*me = unsmob_grob (smob);
94
95   Rod r;
96   Spanner*sp = dynamic_cast<Spanner*> (me);
97   r.distance_ =
98     robust_scm2double (me->get_property ("minimum-length"), 0);
99
100   Direction d = LEFT;
101   do
102     {
103       r.item_l_drul_[d] = sp->get_bound (d);
104       if (r.item_l_drul_[d])
105         r.distance_ += r.item_l_drul_[d]->extent (r.item_l_drul_[d], X_AXIS)[-d];
106     }
107   while (flip (&d) != LEFT);
108
109   if (r.item_l_drul_[LEFT]
110       && r.item_l_drul_[RIGHT])
111     r.add_to_cols ();
112   
113   return SCM_UNSPECIFIED;
114 }
115
116 ADD_INTERFACE (Hyphen_spanner, "lyric-hyphen-interface",
117                "A centred hyphen is a simple line between lyrics used to divide syllables",
118                "thickness height dash-period minimum-length length");
119
120