2 break-align-interface.cc -- implement Break_align_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include <libc-extension.hh> // isinf
13 #include "side-position-interface.hh"
14 #include "axis-group-interface.hh"
16 #include "lily-guile.hh"
17 #include "break-align-interface.hh"
18 #include "dimensions.hh"
19 #include "paper-def.hh"
20 #include "paper-column.hh"
21 #include "group-interface.hh"
22 #include "align-interface.hh"
24 MAKE_SCHEME_CALLBACK (Break_align_interface,alignment_callback,2);
27 Break_align_interface::alignment_callback (SCM element_smob, SCM axis)
29 Grob *me = unsmob_grob (element_smob);
30 Axis a = (Axis) gh_scm2int (axis);
33 Grob *par = me->get_parent (a);
34 if (par && !to_boolean (par->get_grob_property ("break-alignment-done")))
36 par->set_grob_property ("break-alignment-done", SCM_BOOL_T);
37 Break_align_interface::do_alignment (par);
40 return gh_double2scm (0);
43 MAKE_SCHEME_CALLBACK (Break_align_interface,self_align_callback,2);
45 Break_align_interface::self_align_callback (SCM element_smob, SCM axis)
47 Grob *me = unsmob_grob (element_smob);
48 Axis a = (Axis) gh_scm2int (axis);
51 Item* item = dynamic_cast<Item*> (me);
52 Direction bsd = item->break_status_dir ();
55 me->set_grob_property ("self-alignment-X", gh_int2scm (RIGHT));
59 Force break alignment itself to be done first, in the case
61 return Self_alignment_interface::aligned_on_self (element_smob, axis);
65 Break_align_interface::add_element (Grob*me, Grob *toadd)
67 Axis_group_interface::add_element (me, toadd);
71 Break_align_interface::do_alignment (Grob *me)
73 Item * item = dynamic_cast<Item*> (me);
75 Link_array<Grob> elems
76 = Pointer_group_interface__extract_grobs (me, (Grob*)0,
78 Array<Interval> extents;
80 for (int i=0; i < elems.size (); i++)
82 Interval y = elems[i]->extent (elems[i], X_AXIS);
88 while (idx < extents.size () && extents[idx].empty_b ())
92 offsets.set_size (elems.size());
93 for (int i= 0; i < offsets.size();i ++)
98 while (idx < elems.size())
100 int next_idx = idx+1;
101 while ( next_idx < elems.size() && extents[next_idx].empty_b())
104 if (next_idx == elems.size())
107 Grob *l = elems[idx];
108 Grob *r = elems[next_idx];
112 for (SCM s= l->get_grob_property ("elements");
113 gh_pair_p (s) ; s = gh_cdr (s))
115 Grob *elt = unsmob_grob (gh_car (s));
118 && elt->get_grob_property ("break-align-symbol") == ly_symbol2scm( "left-edge"))
121 SCM l =elt->get_grob_property ("space-alist");
132 We used to use #'cause to find out the symbol and the spacing
133 table, but that gets icky when that grob is suicided for some
136 for (SCM s = r->get_grob_property ("elements");
137 gh_pair_p (s); s = gh_cdr (s))
139 Grob * elt =unsmob_grob(gh_car (s));
141 SCM sym = elt->get_grob_property ("break-align-symbol");
142 if (gh_symbol_p (sym))
148 if (rsym == ly_symbol2scm("left-edge"))
152 if (gh_symbol_p (rsym))
153 entry = scm_assq (rsym, alist);
155 bool entry_found = gh_pair_p (entry);
159 if(gh_symbol_p(rsym))
160 sym_str = ly_symbol2string (rsym);
163 if (unsmob_grob (l->get_grob_property ("cause")))
164 orig_str = unsmob_grob (l->get_grob_property ("cause"))->name ();
166 programming_error (_f("No spacing entry from %s to `%s'",
172 SCM type = ly_symbol2scm ("extra-space");
176 entry = gh_cdr (entry);
178 distance = gh_scm2double (gh_cdr (entry));
179 type = gh_car (entry) ;
182 if (type == ly_symbol2scm ("extra-space"))
183 offsets[next_idx] = extents[idx][RIGHT] + distance;
184 else if (type == ly_symbol2scm("minimum-space"))
185 offsets[next_idx] = extents[idx][RIGHT] >? distance;
192 Interval total_extent;
194 Real alignment_off =0.0;
195 for (int i =0 ; i < offsets.size(); i++)
199 alignment_off = -here;
200 total_extent.unite (extents[i] + here);
204 if (item->break_status_dir () == LEFT)
205 alignment_off = -total_extent[RIGHT];
206 else if (edge_idx < 0)
207 alignment_off = -total_extent[LEFT];
209 here = alignment_off;
210 for (int i =0 ; i < offsets.size(); i++)
213 elems[i]->translate_axis (here, X_AXIS);
218 ADD_INTERFACE (Break_aligned_interface, "break-aligned-interface",
219 "Items that are aligned in prefatory matter.
221 The spacing of these items is controlled by the space-alist
222 property. It contains a list break-align-symbols with a specification
223 of the associated space. The space definition is either (extra-space
224 . @var{number}), which adds space after the symbol, (minimum-space
225 . @var{ms}), which pads the space until it it is @var{ms}.
228 Special keys for the alist are 'first-note and 'next-note, signifyign
229 the first note on a line, and the next note halfway a line.
231 Rules for this spacing are much more complicated than this.
232 See [Wanske] page 126 -- 134, [Ross] pg 143 -- 147
236 "break-align-symbol break-alignment-done space-alist");
238 ADD_INTERFACE (Break_align_interface, "break-alignment-interface",
239 "See @ref{break-aligned-interface}.",
240 "break-alignment-done");