2 span-bar.cc -- implement Span_bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 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);
62 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
64 Grob *me = unsmob_grob (element_smob);
65 Axis a = (Axis) gh_scm2int (axis);
67 Interval i (get_spanned_interval (me));
70 Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
71 we have to translate ourselves to be in the center of the
72 interval that we span. */
76 return gh_double2scm (0.0);
79 return gh_double2scm (i.center ());
83 Span_bar::evaluate_empty (Grob*me)
86 TODO: filter all hara-kiried out of ELEMENS list, and then
87 optionally do suicide. Call this cleanage function from
88 center_on_spanned_callback () as well.
91 if (!gh_pair_p (me->get_grob_property ("elements")))
98 Span_bar::evaluate_glyph (Grob*me)
100 SCM elts = me->get_grob_property ("elements");
101 Grob * b = unsmob_grob (gh_car (elts));
102 SCM glsym =ly_symbol2scm ("glyph");
103 SCM gl =b ->get_grob_property (glsym);
104 if (!gh_string_p (gl))
110 String type = ly_scm2string (gl);
116 else if (type== ":|")
120 else if (type== ":|:")
125 gl = ly_str02scm (type.ch_C ());
126 if (scm_equal_p (me->get_grob_property (glsym), gl) != SCM_BOOL_T)
127 me->set_grob_property (glsym, gl);
131 Span_bar::get_spanned_interval (Grob*me)
133 return ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm (), gh_int2scm (Y_AXIS)));
137 MAKE_SCHEME_CALLBACK (Span_bar,get_bar_size,1);
139 Span_bar::get_bar_size (SCM smob)
141 Grob* me = unsmob_grob (smob);
142 Interval iv (get_spanned_interval (me));
146 This happens if the bars are hara-kiried from under us.
149 return gh_double2scm (-1);
151 return gh_double2scm (iv.length ());
155 Span_bar::set_interface (Grob *me)
157 Bar::set_interface (me);
159 me->set_interface (ly_symbol2scm ("span-bar-interface"));
160 me->set_extent_callback (SCM_EOL, Y_AXIS);
164 Span_bar::has_interface (Grob*m)
166 return m && m->has_interface (ly_symbol2scm ("span-bar-interface"));