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