X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbreak-align-item.cc;h=1d6c6cb89103860179deb40d423f29eb09afc148;hb=refs%2Ftags%2Frelease%2F1.3.8;hp=14ff34118bf470222d8a81e53cc776b0ee252dbb;hpb=0dc651561ed849b121d26cbd07a192e9fefeb832;p=lilypond.git diff --git a/lily/break-align-item.cc b/lily/break-align-item.cc index 14ff34118b..1d6c6cb891 100644 --- a/lily/break-align-item.cc +++ b/lily/break-align-item.cc @@ -3,17 +3,143 @@ source file of the GNU LilyPond music typesetter - (c) 1997 Han-Wen Nienhuys + (c) 1997--1999 Han-Wen Nienhuys */ +#include "dimension-cache.hh" +#include "lily-guile.hh" #include "break-align-item.hh" +#include "dimensions.hh" +#include "paper-score.hh" +#include "paper-def.hh" +#include "paper-column.hh" + +/* + Handle spacing for prefatory matter. + + TODO: rewrite this. It is kludgy +*/ void Break_align_item::do_pre_processing() { + if (break_status_dir() == LEFT) + align_dir_ = LEFT; + else + align_dir_ = RIGHT; + + flip (&align_dir_); + sort_elements (); + Real interline= paper_l ()->get_var ("interline"); + + Link_array elems; + for (int i=0; i < elem_l_arr_.size(); i++) + { + Interval y = elem_l_arr_[i]->extent(axis ()); + if (!y.empty_b()) + elems.push (dynamic_cast (elem_l_arr_[i])); + } + + if (!elems.size ()) + return; + + SCM symbol_list = SCM_EOL; + Array dists; + SCM current_origin = ly_str02scm (""); + for (int i=0; i <= elems.size (); i++) + { + Score_element *next_elt = i < elems.size () + ? elems[i] + : 0 ; + + SCM next_origin; + + if (next_elt) + { + next_origin = next_elt->get_elt_property ("origin"); + next_origin = + (next_origin == SCM_UNDEFINED) + ? ly_str02scm ("") + : next_origin; + } + else + next_origin = ly_str02scm ("begin-of-note"); + + SCM extra_space + = scm_eval (scm_listify (ly_symbol2scm ("break-align-spacer"), + current_origin, next_origin, SCM_UNDEFINED)); + SCM symbol = SCM_CAR (extra_space); + Real spc = gh_scm2double (SCM_CADR(extra_space)); + spc *= interline; + + dists.push(spc); + symbol_list = gh_cons (symbol, symbol_list); + current_origin = next_origin; + } + + + // skip the first sym. + symbol_list = SCM_CDR (scm_reverse (symbol_list)); + for (int i=0; i set_elt_property (sym_str, + scm_cons (gh_double2scm (0), + gh_double2scm (dists[i+1]))); + + symbol_list = SCM_CDR (symbol_list); + } - align_i_ = break_status_i(); - Horizontal_align_item::do_pre_processing(); + + // urg + SCM first_pair = elems[0]->get_elt_property ("minimum-space"); + if (first_pair == SCM_UNDEFINED) + first_pair = gh_cons (gh_double2scm (0.0), gh_double2scm (0.0)); + else + first_pair = first_pair; + + scm_set_car_x (first_pair, gh_double2scm (-dists[0])); + elems[0]->set_elt_property ("minimum-space", first_pair); + + Axis_align_item::do_pre_processing(); + + + Real pre_space = elems[0]->extent (X_AXIS)[LEFT] + + elems[0]->relative_coordinate (column_l (), X_AXIS); + Real spring_len = elems.top ()->extent (X_AXIS)[RIGHT] + + elems.top ()->relative_coordinate (column_l (), X_AXIS); + + Real stretch_distance =0.; + + if (SCM_CAR (symbol_list) == ly_symbol2scm ("extra-space")) + { + spring_len += dists.top (); + stretch_distance = dists.top (); + } + else if (SCM_CAR (symbol_list) == ly_symbol2scm ("minimum-space")) + { + spring_len = spring_len >? dists.top (); + stretch_distance = spring_len; + } + + /* + Hint the spacing engine how much space to put in. + + + The pairs are in the format of an interval (ie. CAR < CDR). + */ + column_l ()->set_elt_property ("extra-space", + scm_cons (gh_double2scm (pre_space), + gh_double2scm (spring_len))); + + column_l ()->set_elt_property ("stretch-distance", + gh_cons (gh_double2scm (-dists[0]), + gh_double2scm (stretch_distance))); + +} + +Break_align_item::Break_align_item () +{ + stacking_dir_ = RIGHT; + set_axis (X_AXIS); } -IMPLEMENT_STATIC_NAME(Break_align_item); -IMPLEMENT_IS_TYPE_B1(Break_align_item, Horizontal_align_item);