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