2 separation-item.cc -- implement Separation_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "separation-item.hh"
11 #include "paper-column.hh"
13 #include "pointer-group-interface.hh"
14 #include "accidental-placement.hh"
17 Separation_item::add_item (Grob *s, Item *i)
20 Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"), i);
24 Separation_item::add_conditional_item (Grob *me, Grob *e)
26 Pointer_group_interface::add_grob (me, ly_symbol2scm ("conditional-elements"), e);
30 Return the width of ME given that we are considering the object on
34 Separation_item::conditional_width (Grob *me, Grob *left)
36 Interval w = width (me);
38 Item *item = dynamic_cast<Item *> (me);
39 Paper_column *pc = item->get_column ();
41 extract_grob_set (me, "conditional-elements", elts);
42 for (int i = 0; i < elts.size (); i++)
44 Item *il = dynamic_cast<Item *> (elts[i]);
45 if (pc != il->get_column ())
47 /* this shouldn't happen, but let's continue anyway. */
48 programming_error ("Separation_item: I've been drinking too much");
52 if (to_boolean (il->get_property ("no-spacing-rods")))
55 if (Accidental_placement::has_interface (il))
56 w.unite (Accidental_placement::get_relevant_accidental_extent (il, pc, left));
59 SCM pad = me->get_property ("padding");
61 w.widen (robust_scm2double (pad, 0.0));
66 Separation_item::width (Grob *me)
68 SCM sw = me->get_property ("X-extent");
69 if (is_number_pair (sw))
70 return ly_scm2interval (sw);
72 Item *item = dynamic_cast<Item *> (me);
73 Paper_column *pc = item->get_column ();
76 extract_grob_set (me, "elements", elts);
77 for (int i = 0; i < elts.size (); i++)
79 Item *il = dynamic_cast<Item *> (elts[i]);
80 if (pc != il->get_column ())
82 /* this shouldn't happen, but let's continue anyway. */
83 programming_error ("Separation_item: I've been drinking too much");
87 if (to_boolean (il->get_property ("no-spacing-rods")))
90 Interval iv (il->extent (pc, X_AXIS));
95 SCM pad = me->get_property ("padding");
97 w.widen (robust_scm2double (pad, 0.0));
99 me->set_property ("X-extent", ly_interval2scm (w));
105 Separation_item::relative_width (Grob *me, Grob *common)
107 Interval iv = width (me);
109 return dynamic_cast<Item *> (me)->get_column ()->relative_coordinate (common, X_AXIS) + iv;
113 Try to find the break-aligned symbol in SEPARATION_ITEM that is
114 sticking out at direction D. The x size is put in LAST_EXT
117 Separation_item::extremal_break_aligned_grob (Grob *me,
121 Grob *col = dynamic_cast<Item *> (me)->get_column ();
122 last_ext->set_empty ();
125 extract_grob_set (me, "elements", elts);
126 for (int i = elts.size (); i--;)
128 Grob *break_item = elts[i];
129 if (!scm_is_symbol (break_item->get_property ("break-align-symbol")))
132 if (!scm_is_pair (break_item->get_property ("space-alist")))
135 Interval ext = break_item->extent (col, X_AXIS);
141 || (last_grob && d * (ext[d]- (*last_ext)[d]) > 0))
144 last_grob = break_item;
151 ADD_INTERFACE (Separation_item, "separation-item-interface",
152 "Item that computes widths to generate spacing rods. "
153 "This is done in concert with @ref{separation-spanner-interface}.",
154 "padding X-extent conditional-elements elements");