2 span-bar.cc -- implement Span_bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.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);
26 me->add_dependency (b);
29 MAKE_SCHEME_CALLBACK (Span_bar, print, 1);
33 (1) Elements from 'me->get_object ("elements")' must be
34 ordered according to their y coordinates relative to their common
35 axis group parent. Otherwise, the computation goes mad.
37 (2) This method depends on bar_engraver not being removed from
38 staff context. If bar_engraver is removed, the size of the staff
39 lines is evaluated as 0, which results in a solid span bar line
40 with faulty y coordinate. */
42 /* This routine was originally by Juergen Reuter, but it was a on the
43 bulky side. Rewritten by Han-Wen. */
45 Span_bar::print (SCM smobbed_me)
47 Grob *me = unsmob_grob (smobbed_me);
48 extract_grob_set (me, "elements", elements);
49 Grob *refp = common_refpoint_of_array (elements, me, Y_AXIS);
51 Span_bar::evaluate_glyph (me);
52 SCM glyph = me->get_property ("glyph");
54 /* glyph may not be a string, when ME is killed by Hara Kiri in
56 if (!scm_is_string (glyph))
59 String glyph_string = ly_scm2string (glyph);
61 /* compose span_bar_mol */
62 Array<Interval> extents;
64 for (int i = elements.size (); i--;)
66 Grob *bar = elements[i];
67 Interval ext = bar->extent (refp, Y_AXIS);
78 extents.sort (&Interval::left_comparison);
81 for (int i = 1; i < extents.size (); i++)
83 Interval prev_extent = extents[i - 1];
84 Interval ext = extents[i];
85 if (!prev_extent.is_empty ())
87 Interval l (prev_extent [UP],
92 /* There is overlap between the bar lines. Do nothing. */
96 Stencil interbar = Bar_line::compound_barline (model_bar,
100 interbar.translate_axis (l.center (), Y_AXIS);
101 span_bar.add_stencil (interbar);
107 span_bar.translate_axis (- me->relative_coordinate (refp, Y_AXIS),
110 return span_bar.smobbed_copy ();
113 MAKE_SCHEME_CALLBACK (Span_bar, width_callback, 2);
115 Span_bar::width_callback (SCM element_smob, SCM scm_axis)
117 Grob *se = unsmob_grob (element_smob);
120 assert ((Axis) scm_to_int (scm_axis) == X_AXIS);
121 String gl = ly_scm2string (se->get_property ("glyph"));
126 Stencil m = Bar_line::compound_barline (se, gl, 40 PT, false);
128 return ly_interval2scm (m.extent (X_AXIS));
131 MAKE_SCHEME_CALLBACK (Span_bar, before_line_breaking, 1);
133 Span_bar::before_line_breaking (SCM smob)
135 Grob *g = unsmob_grob (smob);
139 /* No need to call Bar_line::before_line_breaking (), because the info
140 in ELEMENTS already has been procced by
141 Bar_line::before_line_breaking (). */
142 return SCM_UNSPECIFIED;
145 MAKE_SCHEME_CALLBACK (Span_bar, center_on_spanned_callback, 2);
148 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
150 Grob *me = unsmob_grob (element_smob);
152 assert (scm_to_int (axis) == Y_AXIS);
153 Interval i (get_spanned_interval (me));
155 /* Bar_line::print delivers a barline of y-extent (-h/2, h/2), so
156 we have to translate ourselves to be in the center of the
157 interval that we span. */
161 return scm_from_double (0.0);
164 return scm_from_double (i.center ());
168 Span_bar::evaluate_empty (Grob *me)
170 /* TODO: filter all hara-kiried out of ELEMENS list, and then
171 optionally do suicide. Call this cleanage function from
172 center_on_spanned_callback () as well. */
174 extract_grob_set (me, "elements", elements);
175 if (elements.is_empty ())
180 Span_bar::evaluate_glyph (Grob *me)
182 SCM gl = me->get_property ("glyph");
184 if (scm_is_string (gl))
187 extract_grob_set (me, "elements", elements);
188 for (int i = elements.size ();
189 i-- && !scm_is_string (gl);)
190 gl = elements[i]->get_property ("glyph");
192 if (!scm_is_string (gl))
198 String type = ly_scm2string (gl);
201 else if (type == ":|")
203 else if (type == ":|:")
206 gl = scm_makfrom0str (type.to_str0 ());
207 if (scm_equal_p (me->get_property ("glyph"), gl)
209 me->set_property ("glyph", gl);
213 Span_bar::get_spanned_interval (Grob *me)
215 return ly_scm2interval (Axis_group_interface::group_extent_callback
216 (me->self_scm (), scm_from_int (Y_AXIS)));
219 MAKE_SCHEME_CALLBACK (Span_bar, get_bar_size, 1);
221 Span_bar::get_bar_size (SCM smob)
223 Grob *me = unsmob_grob (smob);
224 Interval iv (get_spanned_interval (me));
227 /* This happens if the bars are hara-kiried from under us. */
229 return scm_from_double (-1);
231 return scm_from_double (iv.length ());
234 ADD_INTERFACE (Span_bar, "span-bar-interface",
235 "A bar line that spanned between other barlines. This interface is "
236 " used for bar lines that connect different staves.",