]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-extender.cc
* lily/lyric-engraver.cc (get_current_rest): 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--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 bool
22 Lyric_extender::is_visible (Grob *gr)
23 {
24   Spanner *me = dynamic_cast<Spanner*> (gr);
25
26   SCM heads = me->get_property ("heads");
27   int il = scm_ilength (heads);
28   return il != 0;
29 }
30
31 MAKE_SCHEME_CALLBACK (Lyric_extender, print, 1)
32 SCM 
33 Lyric_extender::print (SCM smob) 
34 {
35   Spanner *me = unsmob_spanner (smob);
36   Item *le = me->get_bound (LEFT);
37   Item *ri = me->get_bound (RIGHT);
38   Grob *common = le->common_refpoint (ri, X_AXIS);
39
40   Real sl = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness"));  
41
42   Link_array<Grob> heads (Pointer_group_interface__extract_grobs (me, (Grob*)0,
43                                                                   "heads"));
44
45   if (!heads.size () && ri->break_status_dir () == CENTER)
46     return SCM_EOL;
47
48   common = common_refpoint_of_array (heads, common, X_AXIS);
49   
50   Real left_point = 0.0;
51   if (le->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
52     left_point = le->extent (common, X_AXIS)[RIGHT];
53   else if (heads.size ())
54     left_point = heads[0]->extent (common, X_AXIS)[LEFT];
55   else
56     left_point = le->extent (common, X_AXIS)[RIGHT];
57
58   if (isinf (left_point))
59     return SCM_EOL;
60
61   /* It seems that short extenders are even lengthened to go past the
62      note head, but haven't found a pattern in it yet. --hwn 1/1/04  */
63   SCM minlen = me->get_property ("minimum-length");
64   Real right_point
65     = left_point + (robust_scm2double  (minlen, 0));
66
67   Spanner *orig = dynamic_cast<Spanner*> (me->original_);
68   bool last_line = orig
69     && (me->get_break_index () == orig->broken_intos_.size () - 2)
70     && !Lyric_extender::is_visible (orig->broken_intos_.top ());
71     
72   if (heads.size ())
73     right_point = right_point >? heads.top ()->extent (common, X_AXIS)[RIGHT];
74
75   Real h = sl * robust_scm2double (me->get_property ("thickness"), 0);
76   Real pad = 2* h;
77
78   if (ri->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
79     right_point = right_point <? (ri->extent (common, X_AXIS)[LEFT] - pad);
80   else if (Note_head::has_interface (ri))
81     ; 
82   else if (!last_line)
83     /* run to end of line. */
84     right_point = right_point >? (ri->extent (common, X_AXIS)[LEFT] - pad);
85   
86   if (isinf (right_point))
87     {
88       programming_error ("Right point of extender not defined?");
89       right_point = ri->relative_coordinate (common, X_AXIS);
90     }  
91
92   left_point += pad;
93
94   Real w = right_point - left_point;
95
96   if (w < 1.5 * h)
97     return SCM_EOL;
98   
99   Stencil  mol (Lookup::round_filled_box (Box (Interval (0, w),
100                                                Interval (0, h)),
101                                           0.8 * h));
102   mol.translate_axis (left_point - me->relative_coordinate (common, X_AXIS),
103                       X_AXIS);
104   return mol.smobbed_copy ();
105 }
106
107
108 ADD_INTERFACE (Lyric_extender,"lyric-extender-interface",
109   "The extender is a simple line at the baseline of the lyric "
110   " that helps show the length of a melissima (tied/slurred note).",
111   "thickness heads");