]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-hyphen.cc
(LY_DEFINE): use Scheme style naming for
[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 <math.h>
10
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"
20
21 MAKE_SCHEME_CALLBACK (Hyphen_spanner,print,1)
22 SCM 
23 Hyphen_spanner::print (SCM smob)
24 {
25   Spanner * me = unsmob_spanner (smob);
26   Drul_array<Item*> bounds (me->get_bound (LEFT),
27                             me->get_bound (RIGHT));
28
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;
32   
33   Grob * common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
34
35   Interval span_points;
36   Direction d = LEFT;
37   do
38     {
39       Interval iv = bounds[d]->extent (common, X_AXIS);
40
41       span_points[d] = iv.is_empty ()
42         ? bounds[d]->relative_coordinate (common, X_AXIS)
43         : iv[-d];
44     }
45   while (flip (&d) != LEFT);
46   
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);
50
51   // interval?
52   
53   Real dp = robust_scm2double (me->get_property ("dash-period"), 1.0);
54   Real dl = robust_scm2double (me->get_property ("length"), .5 );
55
56   if (dp < dl)
57     dp = 1.5 * dl;
58
59   Real l = span_points.length ();
60   int n = int (ceil (l/dp - 0.5));
61   if (n <= 0)
62     n = 1;
63
64   Real space_left = l - dl - (n-1)* dp;
65
66   /*
67     If there is not enough space, the hyphen should disappear, but not
68     at the end of the line.
69    */
70   if (space_left < 0.0
71       && !bounds[RIGHT]->break_status_dir ())
72     return SCM_EOL;
73
74   space_left = space_left >? 0.0;
75   
76   Box b (Interval (0, dl), Interval (h,h+th));
77   Stencil dash_mol (Lookup::round_filled_box (b, 0.8 * lt));
78
79   Stencil total;
80   for (int i = 0; i < n; i++)
81     {
82       Stencil m (dash_mol);
83       m.translate_axis (span_points[LEFT] + i * dp + space_left / 2, X_AXIS);
84       total.add_stencil (m);
85     }
86
87   total.translate_axis ( -me->relative_coordinate (common, X_AXIS), X_AXIS);
88   return total.smobbed_copy ();
89 }
90
91
92 MAKE_SCHEME_CALLBACK (Hyphen_spanner,set_spacing_rods,1);
93 SCM
94 Hyphen_spanner::set_spacing_rods (SCM smob)
95 {
96   Grob*me = unsmob_grob (smob);
97
98   Rod r;
99   Spanner*sp = dynamic_cast<Spanner*> (me);
100   r.distance_ =
101     robust_scm2double (me->get_property ("minimum-length"), 0);
102
103   Direction d=LEFT;
104   do
105     {
106       r.item_l_drul_[d] = sp->get_bound (d);
107       r.distance_ += r.item_l_drul_[d]->extent (r.item_l_drul_[d], X_AXIS)[-d];
108     }
109   while (flip (&d) != LEFT);
110
111   r.add_to_cols ();
112   return SCM_UNSPECIFIED;
113 }
114
115 ADD_INTERFACE (Hyphen_spanner, "lyric-hyphen-interface",
116                "A centred hyphen is a simple line between lyrics used to divide syllables",
117                "thickness height dash-period minimum-length length");
118
119