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>
9 #include <libc-extension.hh>
11 #include "side-position-interface.hh"
13 #include "dimension-cache.hh"
14 #include "lily-guile.hh"
15 #include "break-align-item.hh"
16 #include "dimensions.hh"
17 #include "paper-score.hh"
18 #include "paper-def.hh"
19 #include "paper-column.hh"
20 #include "group-interface.hh"
21 #include "align-interface.hh"
24 Break_align_item::before_line_breaking ()
26 if (break_status_dir() == LEFT)
28 set_elt_property ("self-alignment-X", gh_int2scm (RIGHT));
32 add_offset_callback (Align_interface::center_on_element, X_AXIS);
37 Real interline= paper_l ()->get_var ("interline");
38 Link_array<Score_element> elems;
39 Link_array<Score_element> all_elems
40 = Pointer_group_interface__extract_elements (this, (Score_element*)0,
43 for (int i=0; i < all_elems.size(); i++)
45 Interval y = all_elems[i]->extent(X_AXIS);
47 elems.push (dynamic_cast<Score_element*> (all_elems[i]));
53 SCM symbol_list = SCM_EOL;
55 SCM current_origin = ly_symbol2scm ("none");
56 for (int i=0; i <= elems.size (); i++)
58 Score_element *next_elt = i < elems.size ()
66 next_origin = next_elt->get_elt_property ("break-align-symbol");
68 (next_origin == SCM_UNDEFINED)
69 ? ly_symbol2scm ("none")
73 next_origin = ly_symbol2scm ("begin-of-note");
76 = scm_eval (scm_listify (ly_symbol2scm ("break-align-spacer"),
77 ly_quote_scm (current_origin),
78 ly_quote_scm (next_origin),
80 SCM symbol = gh_car (extra_space);
81 Real spc = gh_scm2double (SCM_CADR(extra_space));
85 symbol_list = gh_cons (symbol, symbol_list);
86 current_origin = next_origin;
90 // skip the first sym.
91 symbol_list = gh_cdr (scm_reverse (symbol_list));
92 for (int i=0; i <elems.size()-1; i++)
94 String sym_str = ly_symbol2string (gh_car (symbol_list));
95 elems[i]->set_elt_property (sym_str,
96 scm_cons (gh_double2scm (0),
97 gh_double2scm (dists[i+1])));
99 symbol_list = gh_cdr (symbol_list);
104 SCM first_pair = elems[0]->get_elt_property ("minimum-space");
105 if (gh_pair_p (first_pair))
106 first_pair = first_pair;
108 first_pair = gh_cons (gh_double2scm (0.0), gh_double2scm (0.0));
110 scm_set_car_x (first_pair, gh_double2scm (-dists[0]));
111 elems[0]->set_elt_property ("minimum-space", first_pair);
115 Force callbacks for alignment to be called
117 Real unused = elems[0]->relative_coordinate (this, X_AXIS);
118 Real pre_space = elems[0]->relative_coordinate (column_l (), X_AXIS);
120 Real xl = elems[0]->extent (X_AXIS)[LEFT];
124 programming_error ("Infinity reached. ");
126 Real xr = elems.top ()->extent (X_AXIS)[RIGHT];
127 Real spring_len = elems.top ()->relative_coordinate (column_l (), X_AXIS);
131 programming_error ("Infinity reached.");
133 Real stretch_distance =0.;
135 if (gh_car (symbol_list) == ly_symbol2scm ("extra-space"))
137 spring_len += dists.top ();
138 stretch_distance = dists.top ();
140 else if (gh_car (symbol_list) == ly_symbol2scm ("minimum-space"))
142 spring_len = spring_len >? dists.top ();
143 stretch_distance = spring_len;
147 Hint the spacing engine how much space to put in.
149 The pairs are in the format of an interval (ie. CAR < CDR).
151 column_l ()->set_elt_property ("extra-space",
152 scm_cons (gh_double2scm (pre_space),
153 gh_double2scm (spring_len)));
155 column_l ()->set_elt_property ("stretch-distance",
156 gh_cons (gh_double2scm (-dists[0]),
157 gh_double2scm (stretch_distance)));
161 Break_align_item::Break_align_item (SCM s)
164 set_elt_property ("stacking-dir" , gh_int2scm (RIGHT));
166 Align_interface (this).set_interface ();
167 Align_interface (this).set_axis (X_AXIS);
169 add_offset_callback (Side_position_interface::aligned_on_self, X_AXIS);