2 break-align-item.cc -- implement Break_align_interface
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_interface,before_line_breaking,1);
27 Break_align_interface::before_line_breaking (SCM smob)
29 Grob* me = unsmob_grob (smob);
31 return SCM_UNSPECIFIED;
33 MAKE_SCHEME_CALLBACK(Break_align_interface,alignment_callback,2);
36 Break_align_interface::alignment_callback (SCM element_smob, SCM axis)
38 Grob *me = unsmob_grob (element_smob);
39 Axis a = (Axis) gh_scm2int (axis);
42 Grob *par = me->parent_l (a);
43 if (par && !to_boolean (par->get_grob_property ("break-alignment-done")))\
45 par->set_grob_property ("break-alignment-done", SCM_BOOL_T);
46 Break_align_interface::do_alignment (par);
49 return gh_double2scm (0);
52 MAKE_SCHEME_CALLBACK(Break_align_interface,self_align_callback,2);
54 Break_align_interface::self_align_callback (SCM element_smob, SCM axis)
56 Grob *me = unsmob_grob (element_smob);
57 Axis a = (Axis) gh_scm2int (axis);
60 Item* item = dynamic_cast<Item*> (me);
61 Direction bsd = item->break_status_dir();
64 me->set_grob_property ("self-alignment-X", gh_int2scm (RIGHT));
67 return Side_position::aligned_on_self (element_smob, axis);
71 Break_align_interface::add_element (Grob*me, Grob *toadd)
73 Axis_group_interface::add_element (me, toadd);
77 Break_align_interface::do_alignment (Grob *me)
79 Item * item = dynamic_cast<Item*> (me);
80 Item *column = item->column_l ();
82 Link_array<Grob> elems;
83 Link_array<Grob> all_elems
84 = Pointer_group_interface__extract_elements (me, (Grob*)0,
87 for (int i=0; i < all_elems.size(); i++)
89 Interval y = all_elems[i]->extent(all_elems[i], X_AXIS);
91 elems.push (dynamic_cast<Grob*> (all_elems[i]));
97 SCM symbol_list = SCM_EOL;
99 SCM current_origin = ly_symbol2scm ("none");
100 for (int i=0; i <= elems.size (); i++)
102 Grob *next_elt = i < elems.size ()
110 next_origin = next_elt->get_grob_property ("break-align-symbol");
112 gh_symbol_p (next_origin)?
113 next_origin : ly_symbol2scm ("none")
117 next_origin = ly_symbol2scm ("begin-of-note");
119 SCM alist = me->get_grob_property ("space-alist");
120 SCM e = scm_assoc (scm_listify (current_origin,
122 SCM_UNDEFINED), alist);
127 extra_space = gh_cdr (e);
131 warning (_f ("unknown spacing pair `%s', `%s'",
132 ly_symbol2string (current_origin),
133 ly_symbol2string (next_origin)));
134 extra_space = scm_listify (ly_symbol2scm ("minimum-space"), gh_double2scm (0.0), SCM_UNDEFINED);
137 SCM symbol = gh_car (extra_space);
138 Real spc = gh_scm2double (gh_cadr(extra_space));
141 symbol_list = gh_cons (symbol, symbol_list);
142 current_origin = next_origin;
146 // skip the first sym.
147 symbol_list = gh_cdr (scm_reverse (symbol_list));
148 for (int i=0; i <elems.size()-1; i++)
150 elems[i]->set_grob_property (gh_car (symbol_list),
151 scm_cons (gh_double2scm (0),
152 gh_double2scm (dists[i+1])));
154 symbol_list = gh_cdr (symbol_list);
159 SCM first_pair = elems[0]->get_grob_property ("minimum-space");
160 if (gh_pair_p (first_pair))
161 first_pair = first_pair;
163 first_pair = gh_cons (gh_double2scm (0.0), gh_double2scm (0.0));
165 scm_set_car_x (first_pair, gh_double2scm (-dists[0]));
166 elems[0]->set_grob_property ("minimum-space", first_pair);
170 Force callbacks for alignment to be called
172 Align_interface::align_to_extents (me, X_AXIS);
174 Real pre_space = elems[0]->relative_coordinate (column, X_AXIS);
176 Real xl = elems[0]->extent (elems[0],X_AXIS)[LEFT];
180 programming_error ("Infinity reached. ");
182 Real xr = elems.top ()->extent (elems.top (), X_AXIS)[RIGHT];
183 Real spring_len = elems.top ()->relative_coordinate (column, X_AXIS);
187 programming_error ("Infinity reached.");
189 Real stretch_distance =0.;
191 if (gh_car (symbol_list) == ly_symbol2scm ("extra-space"))
193 spring_len += dists.top ();
194 stretch_distance = dists.top ();
196 else if (gh_car (symbol_list) == ly_symbol2scm ("minimum-space"))
198 spring_len = spring_len >? dists.top ();
199 stretch_distance = spring_len;
203 Hint the spacing engine how much space to put in.
205 The pairs are in the format of an interval (ie. CAR < CDR).
207 column->set_grob_property ("extra-space",
208 scm_cons (gh_double2scm (pre_space),
209 gh_double2scm (spring_len)));
211 column->set_grob_property ("stretch-distance",
212 gh_cons (gh_double2scm (-dists[0]),
213 gh_double2scm (stretch_distance)));
218 Break_align_interface::set_interface (Grob*me)
220 Align_interface::set_interface (me);
221 Align_interface::set_axis (me,X_AXIS);