]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-extender.cc
867a6d83d30f903a8853f66c1d0d047bb1a39791
[lilypond.git] / lily / lyric-extender.cc
1 /*
2   lyric-extender.cc -- implement Lyric_extender
3   source file of the GNU LilyPond music typesetter
4
5   (c) 1998--2006 Jan Nieuwenhuizen <janneke@gnu.org>
6   Han-Wen Nienhuys
7 */
8
9 #include "lyric-extender.hh"
10
11
12 #include "warn.hh"
13 #include "lookup.hh"
14 #include "paper-column.hh"
15 #include "output-def.hh"
16 #include "note-head.hh"
17 #include "pointer-group-interface.hh"
18
19 MAKE_SCHEME_CALLBACK (Lyric_extender, print, 1);
20 SCM
21 Lyric_extender::print (SCM smob)
22 {
23   Spanner *me = unsmob_spanner (smob);
24   Item *left_edge = me->get_bound (LEFT);
25   Item *right_text = unsmob_item (me->get_object ("next"));
26
27   Grob *common = left_edge;
28
29   if (right_text)
30     common = common->common_refpoint (right_text, X_AXIS);
31
32   common = common->common_refpoint (me->get_bound (RIGHT), X_AXIS);
33   Real sl = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
34
35   extract_grob_set (me, "heads", heads);
36
37   if (!heads.size ())
38     return SCM_EOL;
39
40   common = common_refpoint_of_array (heads, common, X_AXIS);
41
42   Real left_point = 0.0;
43   if (left_edge->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
44     left_point = left_edge->extent (common, X_AXIS)[RIGHT];
45   else if (heads.size ())
46     left_point = heads[0]->extent (common, X_AXIS)[LEFT];
47   else
48     left_point = left_edge->extent (common, X_AXIS)[RIGHT];
49
50   if (isinf (left_point))
51     return SCM_EOL;
52
53   /* It seems that short extenders are even lengthened to go past the
54      note head, but haven't found a pattern in it yet. --hwn 1/1/04  */
55   SCM minlen = me->get_property ("minimum-length");
56   Real right_point
57     = left_point + (robust_scm2double (minlen, 0));
58
59   if (heads.size ())
60     right_point = max (right_point, heads.back ()->extent (common, X_AXIS)[RIGHT]);
61
62   Real h = sl * robust_scm2double (me->get_property ("thickness"), 0);
63   Drul_array<Real> paddings (robust_scm2double (me->get_property ("left-padding"), h),
64                              robust_scm2double (me->get_property ("right-padding"), h));
65
66   if (right_text)
67     right_point = min (right_point, (robust_relative_extent (right_text, common, X_AXIS)[LEFT] - paddings[RIGHT]));
68
69   /* run to end of line. */
70   if (me->get_bound (RIGHT)->break_status_dir ())
71     right_point = max (right_point, (robust_relative_extent (me->get_bound (RIGHT), common, X_AXIS)[LEFT] - paddings[RIGHT]));
72
73   left_point += paddings[LEFT];
74   Real w = right_point - left_point;
75
76   if (w < 1.5 * h)
77     return SCM_EOL;
78
79   Stencil mol (Lookup::round_filled_box (Box (Interval (0, w),
80                                               Interval (0, h)),
81                                          0.8 * h));
82   mol.translate_axis (left_point - me->relative_coordinate (common, X_AXIS),
83                       X_AXIS);
84   return mol.smobbed_copy ();
85 }
86
87 ADD_INTERFACE (Lyric_extender, "lyric-extender-interface",
88                "The extender is a simple line at the baseline of the lyric "
89                "that helps show the length of a melissima (tied/slurred note).",
90
91                "heads "
92                "left-padding "
93                "next "
94                "right-padding "
95                "thickness "
96                );