2 break-align-item.cc -- implement Break_align_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include <libc-extension.hh>
13 #include "side-position-interface.hh"
14 #include "axis-group-interface.hh"
16 #include "lily-guile.hh"
17 #include "break-align-item.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_item,before_line_breaking);
27 Break_align_item::before_line_breaking (SCM smob)
29 Score_element* me = unsmob_element (smob);
31 return SCM_UNSPECIFIED;
35 Break_align_item::alignment_callback (Score_element*c, Axis a)
38 Score_element *par = c->parent_l (a);
39 if (par && !to_boolean (par->get_elt_property ("break-alignment-done")))\
41 par->set_elt_property ("break-alignment-done", SCM_BOOL_T);
42 Break_align_item::do_alignment (par);
49 Break_align_item::add_element (Score_element*me, Score_element *toadd)
51 toadd->add_offset_callback (alignment_callback, X_AXIS);
52 Axis_group_interface::add_element (me, toadd);
56 Break_align_item::do_alignment (Score_element *me)
58 Item * item = dynamic_cast<Item*> (me);
59 Item *column = item->column_l ();
60 if (item->break_status_dir() == LEFT)
62 me->set_elt_property ("self-alignment-X", gh_int2scm (RIGHT));
66 me->add_offset_callback (Align_interface::center_on_element, X_AXIS);
69 Real interline= me->paper_l ()->get_var ("interline");
70 Link_array<Score_element> elems;
71 Link_array<Score_element> all_elems
72 = Pointer_group_interface__extract_elements (me, (Score_element*)0,
75 for (int i=0; i < all_elems.size(); i++)
77 Interval y = all_elems[i]->extent(X_AXIS);
79 elems.push (dynamic_cast<Score_element*> (all_elems[i]));
85 SCM symbol_list = SCM_EOL;
87 SCM current_origin = ly_symbol2scm ("none");
88 for (int i=0; i <= elems.size (); i++)
90 Score_element *next_elt = i < elems.size ()
98 next_origin = next_elt->get_elt_property ("break-align-symbol");
100 gh_symbol_p (next_origin)?
101 next_origin : ly_symbol2scm ("none")
105 next_origin = ly_symbol2scm ("begin-of-note");
107 SCM e = scm_assoc (scm_listify (current_origin,
110 scm_eval2 (ly_symbol2scm ("space-alist"), SCM_EOL));
115 extra_space = gh_cdr (e);
119 warning (_f ("unknown spacing pair `%s', `%s'",
120 ly_symbol2string (current_origin),
121 ly_symbol2string (next_origin)));
122 extra_space = scm_listify (ly_symbol2scm ("minimum-space"), gh_double2scm (0.0), SCM_UNDEFINED);
125 SCM symbol = gh_car (extra_space);
126 Real spc = gh_scm2double (gh_cadr(extra_space));
130 symbol_list = gh_cons (symbol, symbol_list);
131 current_origin = next_origin;
135 // skip the first sym.
136 symbol_list = gh_cdr (scm_reverse (symbol_list));
137 for (int i=0; i <elems.size()-1; i++)
139 elems[i]->set_elt_property (gh_car (symbol_list),
140 scm_cons (gh_double2scm (0),
141 gh_double2scm (dists[i+1])));
143 symbol_list = gh_cdr (symbol_list);
148 SCM first_pair = elems[0]->get_elt_property ("minimum-space");
149 if (gh_pair_p (first_pair))
150 first_pair = first_pair;
152 first_pair = gh_cons (gh_double2scm (0.0), gh_double2scm (0.0));
154 scm_set_car_x (first_pair, gh_double2scm (-dists[0]));
155 elems[0]->set_elt_property ("minimum-space", first_pair);
159 Force callbacks for alignment to be called
161 Align_interface::do_side_processing (me, X_AXIS);
163 Real pre_space = elems[0]->relative_coordinate (column, X_AXIS);
165 Real xl = elems[0]->extent (X_AXIS)[LEFT];
169 programming_error ("Infinity reached. ");
171 Real xr = elems.top ()->extent (X_AXIS)[RIGHT];
172 Real spring_len = elems.top ()->relative_coordinate (column, X_AXIS);
176 programming_error ("Infinity reached.");
178 Real stretch_distance =0.;
180 if (gh_car (symbol_list) == ly_symbol2scm ("extra-space"))
182 spring_len += dists.top ();
183 stretch_distance = dists.top ();
185 else if (gh_car (symbol_list) == ly_symbol2scm ("minimum-space"))
187 spring_len = spring_len >? dists.top ();
188 stretch_distance = spring_len;
192 Hint the spacing engine how much space to put in.
194 The pairs are in the format of an interval (ie. CAR < CDR).
196 column->set_elt_property ("extra-space",
197 scm_cons (gh_double2scm (pre_space),
198 gh_double2scm (spring_len)));
200 column->set_elt_property ("stretch-distance",
201 gh_cons (gh_double2scm (-dists[0]),
202 gh_double2scm (stretch_distance)));
209 Break_align_item::set_interface (Score_element*me)
211 Align_interface::set_interface (me);
212 Align_interface::set_axis (me,X_AXIS);
214 me->add_offset_callback (Side_position::aligned_on_self, X_AXIS);