2 separating-group-spanner.cc -- implement Separating_group_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "separating-group-spanner.hh"
11 #include "separation-item.hh"
12 #include "paper-column.hh"
13 #include "output-def.hh"
14 #include "dimensions.hh"
15 #include "group-interface.hh"
18 Separating_group_spanner::find_rods (Item *r, SCM next, Real padding)
22 This is an inner loop: look for the first normal (unbroken) Left
23 grob. This looks like an inner loop (ie. quadratic total), but in
24 most cases, the interesting L will just be the first entry of
25 NEXT, making it linear in most of the cases.
27 if (Separation_item::width (r).is_empty ())
30 for (; scm_is_pair (next); next = scm_cdr (next))
32 Item *l = dynamic_cast<Item *> (unsmob_grob (scm_car (next)));
33 Item *lb = l->find_prebroken_piece (RIGHT);
37 Interval li (Separation_item::width (lb));
38 Interval ri (Separation_item::conditional_width (r, lb));
39 if (!li.is_empty () && !ri.is_empty ())
43 rod.item_drul_[LEFT] = lb;
44 rod.item_drul_[RIGHT] = r;
46 rod.distance_ = li[RIGHT] - ri[LEFT] + padding;
51 Interval li (Separation_item::width (l));
52 Interval ri (Separation_item::conditional_width (r, l));
53 if (!li.is_empty () && !ri.is_empty ())
57 rod.item_drul_[LEFT] = l;
58 rod.item_drul_[RIGHT] = r;
60 rod.distance_ = li[RIGHT] - ri[LEFT] + padding;
62 if (rod.distance_ > 0.0)
68 this grob doesn't cause a constraint. We look further until we
74 MAKE_SCHEME_CALLBACK (Separating_group_spanner, set_spacing_rods, 1);
76 Separating_group_spanner::set_spacing_rods (SCM smob)
78 Grob *me = unsmob_grob (smob);
81 Ugh: padding is added doubly, also for SeparationItem
83 Real padding = robust_scm2double (me->get_property ("padding"), 0.1);
85 for (SCM s = me->get_property ("elements"); scm_is_pair (s) && scm_is_pair (scm_cdr (s)); s = scm_cdr (s))
88 Order of elements is reversed!
90 SCM elt = scm_car (s);
91 Item *r = unsmob_item (elt);
97 = dynamic_cast<Item *> (r->find_prebroken_piece (LEFT));
99 find_rods (r, scm_cdr (s), padding);
101 find_rods (rb, scm_cdr (s), padding);
104 return SCM_UNSPECIFIED;
108 Separating_group_spanner::add_spacing_unit (Grob *me, Item *i)
110 Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), i);
111 me->add_dependency (i);
114 ADD_INTERFACE (Separating_group_spanner, "separation-spanner-interface",
115 "A spanner that calculates spacing constraints (\"rods\") "
116 "using the @code{separation-item-interface} grobs in @code{elements}.",