Format and improve documentation of internal grob properties.
[lilypond.git] / lily / span-bar.cc
blob993fafe14a70581aad7f852c4d53f2b806056d04
1 /*
2 span-bar.cc -- implement Span_bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "span-bar.hh"
11 #include "font-interface.hh"
12 #include "dimensions.hh"
13 #include "output-def.hh"
14 #include "stencil.hh"
15 #include "warn.hh"
16 #include "axis-group-interface.hh"
17 #include "bar-line.hh"
18 #include "grob.hh"
19 #include "pointer-group-interface.hh"
21 void
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);
29 /* Limitations/Bugs:
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. */
42 SCM
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
52 between. */
53 if (!scm_is_string (glyph))
54 return SCM_EOL;
56 string glyph_string = ly_scm2string (glyph);
58 /* compose span_bar_mol */
59 vector<Interval> extents;
60 Grob *model_bar = 0;
61 for (vsize i = elements.size (); i--;)
63 Grob *bar = elements[i];
64 Interval ext = bar->extent (refp, Y_AXIS);
65 if (ext.is_empty () || to_boolean (bar->get_property ("transparent")))
66 continue;
68 extents.push_back (ext);
69 model_bar = bar;
72 if (!model_bar)
73 model_bar = me;
75 vector_sort (extents, Interval::left_less);
77 Stencil span_bar;
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],
85 ext[DOWN]);
87 if (l.is_empty ())
89 /* There is overlap between the bar lines. Do nothing. */
91 else
93 Stencil interbar = Bar_line::compound_barline (model_bar,
94 glyph_string,
95 l.length (),
96 false);
97 interbar.translate_axis (l.center (), Y_AXIS);
98 span_bar.add_stencil (interbar);
101 prev_extent = ext;
104 span_bar.translate_axis (- me->relative_coordinate (refp, Y_AXIS),
105 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");
116 if (!me->is_live ())
117 return ly_interval2scm (Interval ());
119 string gl = ly_scm2string (gn);
122 urg.
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 ())
136 me->suicide ();
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. */
152 if (i.is_empty ())
154 me->suicide ();
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);
169 SCM gl = SCM_EOL;
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))
176 me->suicide ();
177 return SCM_UNSPECIFIED;
180 string type = ly_scm2string (gl);
181 if (type == "|:")
182 type = ".|";
183 else if (type == ":|")
184 type = "|.";
185 else if (type == ":|:")
186 type = ".|.";
188 return ly_string2scm (type);
191 Interval
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));
203 if (iv.is_empty ())
205 /* This happens if the bars are hara-kiried from under us. */
206 me->suicide ();
207 return scm_from_double (-1);
209 return scm_from_double (iv.length ());
212 ADD_INTERFACE (Span_bar,
213 "A bar line that spanned between other barlines. This interface is "
214 " used for bar lines that connect different staves.",
216 /* properties */
217 "glyph-name "
218 "elements");