2 separation-item.cc -- implement Separation_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "separation-item.hh"
11 #include "axis-group-interface.hh"
15 #include "paper-column.hh"
17 #include "pointer-group-interface.hh"
18 #include "accidental-placement.hh"
21 Separation_item::add_item (Grob *s, Item *i)
24 Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"), i);
28 Separation_item::add_conditional_item (Grob *me, Grob *e)
30 Pointer_group_interface::add_grob (me, ly_symbol2scm ("conditional-elements"), e);
34 Separation_item::set_distance (Drul_array<Item *> items,
37 Drul_array<Skyline_pair*> lines (Skyline_pair::unsmob (items[LEFT]->get_property ("horizontal-skylines")),
38 Skyline_pair::unsmob (items[RIGHT]->get_property ("horizontal-skylines")));
39 Skyline right = conditional_skyline (items[RIGHT], items[LEFT]);
40 right.merge ((*lines[RIGHT])[LEFT]);
42 Real dist = padding + (*lines[LEFT])[RIGHT].distance (right);
47 rod.item_drul_ = items;
55 Separation_item::is_empty (Grob *me)
57 Skyline_pair *sky = Skyline_pair::unsmob (me->get_property ("horizontal-skylines"));
58 return (!sky || sky->is_empty ());
62 Return the width of ME given that we are considering the object on
66 Separation_item::conditional_skyline (Grob *me, Grob *left)
68 vector<Box> bs = boxes (me, left);
69 return Skyline (bs, 0.1, Y_AXIS, LEFT);
73 MAKE_SCHEME_CALLBACK (Separation_item, calc_skylines,1);
75 Separation_item::calc_skylines (SCM smob)
77 Item *me = unsmob_item (smob);
78 vector<Box> bs = boxes (me, 0);
79 /* todo: the horizon_padding is somewhat arbitrary */
80 return Skyline_pair (bs, 0.1, Y_AXIS).smobbed_copy ();
83 /* if left is non-NULL, get the boxes corresponding to the
84 conditional-elements (conditioned on the grob LEFT). This
85 sounds more general than it is: conditional-elements are
86 always accidentals attached to a tied note.
89 Separation_item::boxes (Grob *me, Grob *left)
91 Item *item = dynamic_cast<Item *> (me);
93 int very_large = INT_MAX;
94 Paper_column *pc = item->get_column ();
96 extract_grob_set (me, left ? "conditional-elements" : "elements", read_only_elts);
100 elts = Accidental_placement::get_relevant_accidentals (read_only_elts, left);
102 elts = read_only_elts;
104 Grob *ycommon = common_refpoint_of_array (elts, me, Y_AXIS);
106 for (vsize i = 0; i < elts.size (); i++)
108 Item *il = dynamic_cast<Item *> (elts[i]);
109 if (pc != il->get_column ())
111 if (Axis_group_interface::has_interface (il))
114 Interval y (il->pure_height (ycommon, 0, very_large));
115 Interval x (il->extent (pc, X_AXIS));
117 Interval extra = robust_scm2interval (elts[i]->get_property ("extra-spacing-width"),
118 Interval (-0.1, 0.1));
119 x[LEFT] += extra[LEFT];
120 x[RIGHT] += extra[RIGHT];
121 if (to_boolean (elts[i]->get_property ("infinite-spacing-height")))
122 y = Interval (-infinity_f, infinity_f);
124 if (!x.is_empty () && !y.is_empty ())
125 out.push_back (Box (x, y));
132 Try to find the break-aligned symbol in SEPARATION_ITEM that is
133 sticking out at direction D. The x size is put in LAST_EXT
136 Separation_item::extremal_break_aligned_grob (Grob *me,
140 Grob *col = dynamic_cast<Item *> (me)->get_column ();
141 last_ext->set_empty ();
144 extract_grob_set (me, "elements", elts);
145 for (vsize i = elts.size (); i--;)
147 Grob *break_item = elts[i];
148 if (!scm_is_symbol (break_item->get_property ("break-align-symbol")))
151 if (!scm_is_pair (break_item->get_property ("space-alist")))
154 Interval ext = break_item->extent (col, X_AXIS);
160 || (last_grob && d * (ext[d]- (*last_ext)[d]) > 0))
163 last_grob = break_item;
170 extern bool debug_skylines;
171 MAKE_SCHEME_CALLBACK (Separation_item, print, 1)
173 Separation_item::print (SCM smob)
178 Grob *me = unsmob_grob (smob);
180 if (Skyline_pair *s = Skyline_pair::unsmob (me->get_property ("horizontal-skylines")))
182 ret.add_stencil (Lookup::points_to_line_stencil (0.1, (*s)[LEFT].to_points (Y_AXIS)).in_color (255, 255, 0));
183 ret.add_stencil (Lookup::points_to_line_stencil (0.1, (*s)[RIGHT].to_points (Y_AXIS)).in_color (0, 255, 255));
185 return ret.smobbed_copy ();
188 ADD_INTERFACE (Separation_item,
189 "Item that computes widths to generate spacing rods. "
193 "conditional-elements "
196 "horizontal-skylines "