2 span-bar.cc -- implement Span_bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "font-interface.hh"
11 #include "dimensions.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
15 #include "axis-group-interface.hh"
16 #include "group-interface.hh"
21 Span_bar::add_bar (Grob*me, Grob*b)
23 Pointer_group_interface::add_element (me,"elements", b);
25 me->add_dependency (b);
28 MAKE_SCHEME_CALLBACK(Span_bar,width_callback,2);
30 Span_bar::width_callback (SCM element_smob, SCM scm_axis)
32 Grob *se = unsmob_grob (element_smob);
33 Axis a = (Axis) gh_scm2int (scm_axis);
35 String gl = ly_scm2string (se->get_grob_property ("glyph"));
40 Molecule m = Bar::compound_barline (se, gl, 40 PT);
42 return ly_interval2scm ( m.extent (X_AXIS));
45 MAKE_SCHEME_CALLBACK(Span_bar,before_line_breaking,1);
47 Span_bar::before_line_breaking (SCM smob)
49 evaluate_empty (unsmob_grob (smob));
50 evaluate_glyph (unsmob_grob (smob));
53 no need to call Bar::before_line_breaking (), because the info
54 in ELEMENTS already has been procced by Bar::before_line_breaking().
56 return SCM_UNSPECIFIED;
59 MAKE_SCHEME_CALLBACK(Span_bar,center_on_spanned_callback,2);
61 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
63 Grob *me = unsmob_grob (element_smob);
64 Axis a = (Axis) gh_scm2int (axis);
66 Interval i (get_spanned_interval (me));
69 Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
70 we have to translate ourselves to be in the center of the
71 interval that we span. */
73 return gh_double2scm (i.center ());
77 Span_bar::evaluate_empty (Grob*me)
80 TODO: filter all hara-kiried out of ELEMENS list, and then
81 optionally do suicide. Call this cleanage function from
82 center_on_spanned_callback() as well.
85 if (!gh_pair_p (me->get_grob_property ("elements")))
92 Span_bar::evaluate_glyph (Grob*me)
94 SCM elts = me->get_grob_property ("elements");
95 Grob * b = unsmob_grob (gh_car (elts));
96 SCM glsym =ly_symbol2scm ("glyph");
97 SCM gl =b ->get_grob_property (glsym);
98 if (!gh_string_p (gl))
104 String type = ly_scm2string (gl);
110 else if (type== ":|")
114 else if (type== ":|:")
119 gl = ly_str02scm (type.ch_C());
120 if (scm_equal_p (me->get_grob_property (glsym), gl) != SCM_BOOL_T)
121 me->set_grob_property (glsym, gl);
125 Span_bar::get_spanned_interval (Grob*me)
127 return ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm(), gh_int2scm (Y_AXIS)));
131 MAKE_SCHEME_CALLBACK(Span_bar,get_bar_size,1);
133 Span_bar::get_bar_size (SCM smob)
135 Grob* me = unsmob_grob (smob);
136 Interval iv (get_spanned_interval (me));
140 This happens if the bars are hara-kiried from under us.
143 return gh_double2scm (-1);
145 return gh_double2scm (iv.length ());
149 Span_bar::set_interface (Grob *me)
151 Bar::set_interface (me);
153 me->set_interface (ly_symbol2scm ("span-bar-interface"));
154 me->set_extent_callback (SCM_EOL, Y_AXIS);
158 Span_bar::has_interface (Grob*m)
160 return m && m->has_interface (ly_symbol2scm ("span-bar-interface"));