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