(all-grob-descriptions): remove gap from
[lilypond.git] / lily / lyric-hyphen.cc
blob98b2b22403f33d6375669a51c13accc078022a35
1 /*
2 hyphen-spanner.cc -- implement Hyphen_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 2003--2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include <math.h>
11 #include "box.hh"
12 #include "lookup.hh"
13 #include "stencil.hh"
14 #include "paper-def.hh"
15 #include "paper-column.hh"
16 #include "spanner.hh"
17 #include "item.hh"
18 #include "lyric-hyphen.hh"
19 #include "moment.hh"
21 MAKE_SCHEME_CALLBACK (Hyphen_spanner,print,1)
22 SCM
23 Hyphen_spanner::print (SCM smob)
25 Spanner * me = unsmob_spanner (smob);
26 Drul_array<Item*> bounds (me->get_bound (LEFT),
27 me->get_bound (RIGHT));
29 if (bounds[LEFT]->break_status_dir ()
30 && Paper_column::when_mom (bounds[LEFT]) == Paper_column::when_mom (bounds[RIGHT]->get_column ()))
31 return SCM_EOL;
33 Grob * common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
35 Interval span_points;
36 Direction d = LEFT;
39 Interval iv = bounds[d]->extent (common, X_AXIS);
41 span_points[d] = iv.is_empty ()
42 ? bounds[d]->relative_coordinate (common, X_AXIS)
43 : iv[-d];
45 while (flip (&d) != LEFT);
47 Real lt = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
48 Real th = robust_scm2double (me->get_property ("thickness"), 1) * lt ;
49 Real h = robust_scm2double (me->get_property ("height"), 0.5);
51 // interval?
53 Real dp = robust_scm2double (me->get_property ("dash-period"), 1.0);
54 Real dl = robust_scm2double (me->get_property ("length"), .5 );
56 if (dp < dl)
57 dp = 1.5 * dl;
59 Real l = span_points.length ();
60 int n = int (ceil (l/dp - 0.5));
61 if (n <= 0)
62 n = 1;
64 Real space_left = l - dl - (n-1)* dp;
67 If there is not enough space, the hyphen should disappear, but not
68 at the end of the line.
70 if (space_left < 0.0
71 && !bounds[RIGHT]->break_status_dir ())
72 return SCM_EOL;
74 space_left = space_left >? 0.0;
76 Box b (Interval (0, dl), Interval (h,h+th));
77 Stencil dash_mol (Lookup::round_filled_box (b, 0.8 * lt));
79 Stencil total;
80 for (int i = 0; i < n; i++)
82 Stencil m (dash_mol);
83 m.translate_axis (span_points[LEFT] + i * dp + space_left / 2, X_AXIS);
84 total.add_stencil (m);
87 total.translate_axis ( -me->relative_coordinate (common, X_AXIS), X_AXIS);
88 return total.smobbed_copy ();
92 MAKE_SCHEME_CALLBACK (Hyphen_spanner,set_spacing_rods,1);
93 SCM
94 Hyphen_spanner::set_spacing_rods (SCM smob)
96 Grob*me = unsmob_grob (smob);
98 Rod r;
99 Spanner*sp = dynamic_cast<Spanner*> (me);
100 r.distance_ =
101 robust_scm2double (me->get_property ("minimum-length"), 0);
103 Direction d=LEFT;
106 r.item_l_drul_[d] = sp->get_bound (d);
107 if (r.item_l_drul_[d])
108 r.distance_ += r.item_l_drul_[d]->extent (r.item_l_drul_[d], X_AXIS)[-d];
110 while (flip (&d) != LEFT);
112 if (r.item_l_drul_[LEFT]
113 && r.item_l_drul_[RIGHT])
114 r.add_to_cols ();
116 return SCM_UNSPECIFIED;
119 ADD_INTERFACE (Hyphen_spanner, "lyric-hyphen-interface",
120 "A centred hyphen is a simple line between lyrics used to divide syllables",
121 "thickness height dash-period minimum-length length");