]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-spanner.cc
17b01dad53193d0ac68d837dc3bff768c5ac80eb
[lilypond.git] / lily / hyphen-spanner.cc
1 /*
2   hyphen-spanner.cc -- implement Hyphen_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1999--2003 Glen Prideaux <glenprideaux@iname.com>
7
8  (adapted from lyric-extender)
9 */
10
11 #include <math.h>
12
13 #include "box.hh"
14 #include "lookup.hh"
15 #include "molecule.hh"
16 #include "paper-def.hh"
17 #include "hyphen-spanner.hh"
18 #include "paper-column.hh"
19 #include "spanner.hh"
20 #include "item.hh"
21
22
23 MAKE_SCHEME_CALLBACK (Hyphen_spanner,brew_molecule,1)
24 SCM 
25 Hyphen_spanner::brew_molecule (SCM smob)
26 {
27   Spanner * sp = unsmob_spanner (smob);
28   Drul_array<Item*> bounds (sp->get_bound (LEFT),
29                             sp->get_bound (RIGHT));
30   
31   Grob * common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
32
33   Interval span_points;
34   Direction d = LEFT;
35   do
36     {
37       Interval iv = bounds[d]->extent (common, X_AXIS);
38
39       span_points[d] = iv.is_empty ()
40         ? bounds[d]->relative_coordinate (common, X_AXIS)
41         : iv[-d];
42     }
43   while (flip (&d) != LEFT);
44   
45   Real lt = sp->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
46   Real th = robust_scm2double (sp->get_grob_property ("thickness"), 1) * lt ;
47   Real h = robust_scm2double (sp->get_grob_property ("height"), 0.5);
48
49   // interval?
50   
51   Real dp = robust_scm2double (sp->get_grob_property ("dash-period"), 1.0);
52   Real dl = robust_scm2double (sp->get_grob_property ("length"), .5 );
53
54   if (dp < dl)
55     dp = 1.5 * dl;
56
57   Real l = span_points.length ();
58   int n = int (ceil (l/dp - 0.5));
59   if (n <= 0)
60     n = 1;
61
62   Real space_left = l - dl - (n-1)* dp;
63
64   /*
65     If there is not enough space, the hyphen should disappear.
66    */
67   if (space_left < 0)
68     return SCM_EOL;
69   
70   Box b (Interval (0, dl), Interval (h,h+th));
71   Molecule dash_mol (Lookup::round_filled_box (b, 0.8 * lt));
72
73   Molecule total;
74   for (int i = 0; i < n; i++)
75     {
76       Molecule m (dash_mol);
77       m.translate_axis (span_points[LEFT] + i * dp + space_left / 2, X_AXIS);
78       total.add_molecule (m);
79     }
80
81   total.translate_axis ( -sp->relative_coordinate (common, X_AXIS), X_AXIS);
82   return total.smobbed_copy ();
83 }
84
85
86 ADD_INTERFACE (Hyphen_spanner, "lyric-hyphen-interface",
87                "A centred hyphen is a simple line between lyrics used to divide syllables",
88                "thickness height dash-period length");
89
90