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