2 break-align-item.cc -- implement Break_align_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "dimension-cache.hh"
10 #include "lily-guile.hh"
11 #include "break-align-item.hh"
12 #include "dimensions.hh"
13 #include "paper-score.hh"
14 #include "paper-def.hh"
15 #include "paper-column.hh"
18 Handle spacing for prefatory matter.
22 TODO: rewrite this. It is kludgy
26 Break_align_item::do_pre_processing()
28 if (break_status_dir() == LEFT)
35 Real interline= paper_l ()->get_var ("interline");
37 Link_array<Score_element> elems;
38 for (int i=0; i < elem_l_arr_.size(); i++)
40 Interval y = elem_l_arr_[i]->extent(axis ());
42 elems.push (dynamic_cast<Score_element*> (elem_l_arr_[i]));
48 SCM symbol_list = SCM_EOL;
50 SCM current_origin = ly_str02scm ("");
51 for (int i=0; i <= elems.size (); i++)
53 Score_element *next_elt = i < elems.size ()
61 next_origin = next_elt->get_elt_property ("origin");
63 (next_origin == SCM_UNDEFINED)
68 next_origin = ly_str02scm ("begin-of-note");
71 = scm_eval (scm_listify (ly_symbol ("break-align-spacer"),
72 current_origin, next_origin, SCM_UNDEFINED));
73 SCM symbol = SCM_CAR (extra_space);
74 Real spc = gh_scm2double (SCM_CADR(extra_space));
78 symbol_list = gh_cons (symbol, symbol_list);
79 current_origin = next_origin;
83 // skip the first sym.
84 symbol_list = SCM_CDR (scm_reverse (symbol_list));
85 for (int i=0; i <elems.size()-1; i++)
87 String sym_str = ly_scm2string (SCM_CAR (symbol_list));
88 elems[i]->set_elt_property (sym_str,
89 scm_cons (gh_double2scm (0),
90 gh_double2scm (dists[i+1])));
92 symbol_list = SCM_CDR (symbol_list);
97 SCM first_pair = elems[0]->get_elt_property ("minimum-space");
98 if (first_pair == SCM_UNDEFINED)
99 first_pair = gh_cons (gh_double2scm (0.0), gh_double2scm (0.0));
101 first_pair = first_pair;
103 scm_set_car_x (first_pair, gh_double2scm (-dists[0]));
104 elems[0]->set_elt_property ("minimum-space", first_pair);
106 Axis_align_item::do_pre_processing();
109 Real pre_space = elems[0]->extent (X_AXIS)[LEFT]
110 + elems[0]->relative_coordinate (column_l (), X_AXIS);
111 Real spring_len = elems.top ()->extent (X_AXIS)[RIGHT]
112 + elems.top ()->relative_coordinate (column_l (), X_AXIS);
114 Real stretch_distance =0.;
116 if (SCM_CAR (symbol_list) == gh_symbol2scm ("extra-space"))
118 spring_len += dists.top ();
119 stretch_distance = dists.top ();
121 else if (SCM_CAR (symbol_list) == gh_symbol2scm ("minimum-space"))
123 spring_len = spring_len >? dists.top ();
124 stretch_distance = spring_len;
128 Hint the spacing engine how much space to put in.
131 The pairs are in the format of an interval (ie. CAR < CDR).
133 column_l ()->set_elt_property ("extra-space",
134 scm_cons (gh_double2scm (pre_space),
135 gh_double2scm (spring_len)));
137 column_l ()->set_elt_property ("stretch-distance",
138 gh_cons (gh_double2scm (-dists[0]),
139 gh_double2scm (stretch_distance)));
143 Break_align_item::Break_align_item ()
145 stacking_dir_ = RIGHT;
150 Break_align_item::add_breakable_item (Item *it)
152 SCM pr = it->remove_elt_property ("break-priority");
154 if (pr == SCM_UNDEFINED)
157 int priority = gh_scm2int (pr);
159 Score_element * column_l = get_elt_by_priority (priority);
160 Axis_group_item * hg=0;
163 hg = dynamic_cast<Axis_group_item*> (column_l);
167 hg = new Axis_group_item;
168 hg->set_axes (X_AXIS,X_AXIS);
171 this is quite ridiculous, but we do this anyway, to ensure that no
172 warning bells about missing Y refpoints go off later on.
174 hg->set_parent (this, Y_AXIS);
175 hg->set_elt_property ("origin", ly_str02scm (it->name ()));
177 pscore_l_->typeset_element (hg);
178 add_element_priority (hg, priority);
184 hg->add_element (it);