2 span-bar.cc -- implement Span_bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "font-interface.hh"
12 #include "dimensions.hh"
13 #include "output-def.hh"
16 #include "axis-group-interface.hh"
17 #include "bar-line.hh"
19 #include "pointer-group-interface.hh"
22 Span_bar::add_bar (Grob *me, Grob *b)
24 Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), b);
27 MAKE_SCHEME_CALLBACK (Span_bar, print, 1);
31 (1) Elements from 'me->get_object ("elements")' must be
32 ordered according to their y coordinates relative to their common
33 axis group parent. Otherwise, the computation goes mad.
35 (2) This method depends on bar_engraver not being removed from
36 staff context. If bar_engraver is removed, the size of the staff
37 lines is evaluated as 0, which results in a solid span bar line
38 with faulty y coordinate. */
40 /* This routine was originally by Juergen Reuter, but it was a on the
41 bulky side. Rewritten by Han-Wen. */
43 Span_bar::print (SCM smobbed_me)
45 Grob *me = unsmob_grob (smobbed_me);
46 extract_grob_set (me, "elements", elements);
47 Grob *refp = common_refpoint_of_array (elements, me, Y_AXIS);
49 SCM glyph = me->get_property ("glyph-name");
51 /* glyph may not be a string, when ME is killed by Hara Kiri in
53 if (!scm_is_string (glyph))
56 string glyph_string = ly_scm2string (glyph);
58 /* compose span_bar_mol */
59 vector<Interval> extents;
61 for (vsize i = elements.size (); i--;)
63 Grob *bar = elements[i];
64 Interval ext = bar->extent (refp, Y_AXIS);
68 extents.push_back (ext);
75 vector_sort (extents, Interval::left_less);
78 for (vsize i = 1; i < extents.size (); i++)
80 Interval prev_extent = extents[i - 1];
81 Interval ext = extents[i];
82 if (!prev_extent.is_empty ())
84 Interval l (prev_extent [UP],
89 /* There is overlap between the bar lines. Do nothing. */
93 Stencil interbar = Bar_line::compound_barline (model_bar,
97 interbar.translate_axis (l.center (), Y_AXIS);
98 span_bar.add_stencil (interbar);
104 span_bar.translate_axis (- me->relative_coordinate (refp, Y_AXIS),
107 return span_bar.smobbed_copy ();
110 MAKE_SCHEME_CALLBACK (Span_bar, width, 1);
112 Span_bar::width (SCM smob)
114 Grob *me = unsmob_grob (smob);
115 SCM gn = me->get_property ("glyph-name");
117 return ly_interval2scm (Interval ());
119 string gl = ly_scm2string (gn);
124 Stencil m = Bar_line::compound_barline (me, gl, 40 PT, false);
126 return ly_interval2scm (m.extent (X_AXIS));
129 MAKE_SCHEME_CALLBACK (Span_bar, before_line_breaking, 1);
131 Span_bar::before_line_breaking (SCM smob)
133 Grob *me = unsmob_grob (smob);
134 extract_grob_set (me, "elements", elements);
135 if (elements.empty ())
138 return SCM_UNSPECIFIED;
141 MAKE_SCHEME_CALLBACK (Span_bar, center_on_spanned_callback, 1);
144 Span_bar::center_on_spanned_callback (SCM smob)
146 Grob *me = unsmob_grob (smob);
147 Interval i (get_spanned_interval (me));
149 /* Bar_line::print delivers a barline of y-extent (-h/2, h/2), so
150 we have to translate ourselves to be in the center of the
151 interval that we span. */
155 return scm_from_double (0.0);
158 return scm_from_double (i.center ());
163 MAKE_SCHEME_CALLBACK(Span_bar, calc_glyph_name, 1);
165 Span_bar::calc_glyph_name (SCM smob)
167 Grob *me = unsmob_grob (smob);
168 extract_grob_set (me, "elements", elements);
170 for (vsize i = elements.size ();
171 i-- && !scm_is_string (gl);)
172 gl = elements[i]->get_property ("glyph-name");
174 if (!scm_is_string (gl))
177 return SCM_UNSPECIFIED;
180 string type = ly_scm2string (gl);
183 else if (type == ":|")
185 else if (type == ":|:")
188 return scm_makfrom0str (type.c_str ());
192 Span_bar::get_spanned_interval (Grob *me)
194 return ly_scm2interval (Axis_group_interface::generic_group_extent (me, Y_AXIS));
197 MAKE_SCHEME_CALLBACK (Span_bar, calc_bar_size, 1);
199 Span_bar::calc_bar_size (SCM smob)
201 Grob *me = unsmob_grob (smob);
202 Interval iv (get_spanned_interval (me));
205 /* This happens if the bars are hara-kiried from under us. */
207 return scm_from_double (-1);
209 return scm_from_double (iv.length ());
212 ADD_INTERFACE (Span_bar, "span-bar-interface",
213 "A bar line that spanned between other barlines. This interface is "
214 " used for bar lines that connect different staves.",