]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-hyphen.cc
Run `make grand-replace'.
[lilypond.git] / lily / lyric-hyphen.cc
1 /*
2   hyphen-spanner.cc -- implement Lyric_hyphen
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2003--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "lyric-hyphen.hh"
10
11
12 #include "lookup.hh"
13 #include "output-def.hh"
14 #include "paper-column.hh"
15 #include "moment.hh"
16 #include "spanner.hh"
17
18 /*
19   TODO: should extract hyphen dimensions or hyphen glyph from the
20   font.
21  */
22
23 MAKE_SCHEME_CALLBACK (Lyric_hyphen, print, 1);
24 SCM
25 Lyric_hyphen::print (SCM smob)
26 {
27   Spanner *me = unsmob_spanner (smob);
28   Drul_array<Item *> bounds (me->get_bound (LEFT),
29                              me->get_bound (RIGHT));
30
31   if (bounds[LEFT]->break_status_dir ()
32       && (Paper_column::when_mom (bounds[LEFT])
33           == Paper_column::when_mom (bounds[RIGHT]->get_column ())))
34     return SCM_EOL;
35
36   Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
37
38   Interval span_points;
39   Direction d = LEFT;
40   Drul_array<bool> broken;
41   do
42     {
43       Interval iv = bounds[d]->extent (common, X_AXIS);
44
45       span_points[d] = iv.is_empty ()
46         ? bounds[d]->relative_coordinate (common, X_AXIS)
47         : iv[-d];
48     }
49   while (flip (&d) != LEFT);
50
51   Real lt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
52   Real th = robust_scm2double (me->get_property ("thickness"), 1) * lt;
53   Real font_size_step = robust_scm2double (me->get_property ("font-size"), 0.0);
54   Real h = robust_scm2double (me->get_property ("height"), 0.5)
55     * pow (2.0, font_size_step / 6.0);
56
57   // interval?
58
59   Real dash_period = robust_scm2double (me->get_property ("dash-period"), 1.0);
60   Real dash_length = robust_scm2double (me->get_property ("length"), .5);
61   Real padding = robust_scm2double (me->get_property ("padding"), 0.1);
62
63   if (dash_period < dash_length)
64     dash_period = 1.5 * dash_length;
65
66   Real l = span_points.length ();
67
68   int n = int (ceil (l / dash_period - 0.5));
69   if (n <= 0)
70     n = 1;
71
72   if (l < dash_length + 2 * padding
73       && !bounds[RIGHT]->break_status_dir ())
74     {
75       Real minimum_length = robust_scm2double (me->get_property ("minimum-length"), .3);
76       dash_length = max ((l - 2 * padding), minimum_length);
77     }
78
79   Real space_left = l - dash_length - (n - 1) * dash_period;
80
81   /*
82     If there is not enough space, the hyphen should disappear, but not
83     at the end of the line.
84   */
85   if (space_left < 0.0
86       && !bounds[RIGHT]->break_status_dir ())
87     return SCM_EOL;
88
89   space_left = max (space_left, 0.0);
90
91   Box b (Interval (0, dash_length), Interval (h, h + th));
92   Stencil dash_mol (Lookup::round_filled_box (b, 0.8 * lt));
93
94   Stencil total;
95   for (int i = 0; i < n; i++)
96     {
97       Stencil m (dash_mol);
98       m.translate_axis (span_points[LEFT] + i * dash_period + space_left / 2, X_AXIS);
99       total.add_stencil (m);
100     }
101
102   total.translate_axis (-me->relative_coordinate (common, X_AXIS), X_AXIS);
103   return total.smobbed_copy ();
104 }
105
106 MAKE_SCHEME_CALLBACK (Lyric_hyphen, set_spacing_rods, 1);
107 SCM
108 Lyric_hyphen::set_spacing_rods (SCM smob)
109 {
110   Grob *me = unsmob_grob (smob);
111
112   Rod r;
113   Spanner *sp = dynamic_cast<Spanner *> (me);
114
115   r.distance_ = robust_scm2double (me->get_property ("minimum-distance"), 0);
116   Direction d = LEFT;
117   do
118     {
119       r.item_drul_[d] = sp->get_bound (d);
120       if (r.item_drul_[d])
121         r.distance_ += -d * r.item_drul_[d]->extent (r.item_drul_[d], X_AXIS)[-d];
122     }
123   while (flip (&d) != LEFT);
124
125   if (r.item_drul_[LEFT]
126       && r.item_drul_[RIGHT])
127     r.add_to_cols ();
128
129   return SCM_UNSPECIFIED;
130 }
131
132 ADD_INTERFACE (Lyric_hyphen,
133                "A centered hyphen is simply a line between lyrics used to"
134                " divide syllables.",
135
136                /* properties */
137                "dash-period "
138                "height "
139                "length "
140                "minimum-distance "
141                "minimum-length "
142                "padding "
143                "thickness "
144                );
145