]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-extender.cc
* lily/tie-column.cc (set_manual_tie_configuration): new function.
[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--2005 Jan Nieuwenhuizen <janneke@gnu.org>
6   Han-Wen Nienhuys
7 */
8
9 #include "lyric-extender.hh"
10
11 #include <cmath>
12 using namespace std;
13
14 #include "warn.hh"
15 #include "lookup.hh"
16 #include "paper-column.hh"
17 #include "output-def.hh"
18 #include "note-head.hh"
19 #include "pointer-group-interface.hh"
20
21 MAKE_SCHEME_CALLBACK (Lyric_extender, print, 1)
22   SCM
23 Lyric_extender::print (SCM smob)
24 {
25   Spanner *me = unsmob_spanner (smob);
26   Item *left_edge = me->get_bound (LEFT);
27   Item *right_text = unsmob_item (me->get_object ("next"));
28
29   Grob *common = left_edge;
30
31   if (right_text)
32     common = common->common_refpoint (right_text, X_AXIS);
33
34   common = common->common_refpoint (me->get_bound (RIGHT), X_AXIS);
35   Real sl = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
36
37   extract_grob_set (me, "heads", heads);
38
39   if (!heads.size ())
40     return SCM_EOL;
41
42   common = common_refpoint_of_array (heads, common, X_AXIS);
43
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];
51
52   if (isinf (left_point))
53     return SCM_EOL;
54
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));
60
61   if (heads.size ())
62     right_point = max (right_point, heads.top ()->extent (common, X_AXIS)[RIGHT]);
63
64   Real h = sl * robust_scm2double (me->get_property ("thickness"), 0);
65   Real pad = 2* h;
66
67   if (right_text)
68     right_point = min (right_point, (robust_relative_extent (right_text, common, X_AXIS)[LEFT] - pad));
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] - pad));
73
74   left_point += pad;
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, "lyric-extender-interface",
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                "next thickness heads");