X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Fbreak-align-item.cc;h=bbea713e2bb8d1f711fad9d141242db4371b5c9a;hb=c21d49df60cb97801ab33ab8a1bad6f2c81cd820;hp=172eb85253d508cf9562e2a225de9b2f5560885e;hpb=2873636a53f0011f837aaf6e2072de602730d957;p=lilypond.git diff --git a/lily/break-align-item.cc b/lily/break-align-item.cc index 172eb85253..bbea713e2b 100644 --- a/lily/break-align-item.cc +++ b/lily/break-align-item.cc @@ -3,9 +3,13 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1999 Han-Wen Nienhuys + (c) 1997--2000 Han-Wen Nienhuys */ +#include +#include +#include "side-position-interface.hh" +#include "warn.hh" #include "dimension-cache.hh" #include "lily-guile.hh" #include "break-align-item.hh" @@ -13,41 +17,43 @@ #include "paper-score.hh" #include "paper-def.hh" #include "paper-column.hh" +#include "group-interface.hh" +#include "align-interface.hh" -/* - Handle spacing for prefatory matter. - - - - TODO: rewrite this. It is kludgy -*/ - -void -Break_align_item::do_pre_processing() +GLUE_SCORE_ELEMENT(Break_align_item,before_line_breaking); +SCM +Break_align_item::member_before_line_breaking () { if (break_status_dir() == LEFT) - align_dir_ = LEFT; + { + set_elt_property ("self-alignment-X", gh_int2scm (RIGHT)); + } else - align_dir_ = RIGHT; + { + add_offset_callback (Align_interface::center_on_element, X_AXIS); + } - 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++) + Link_array all_elems + = Pointer_group_interface__extract_elements (this, (Score_element*)0, + "elements"); + + for (int i=0; i < all_elems.size(); i++) { - Interval y = elem_l_arr_[i]->extent(axis ()); + Interval y = all_elems[i]->extent(X_AXIS); if (!y.empty_b()) - elems.push (dynamic_cast (elem_l_arr_[i])); + elems.push (dynamic_cast (all_elems[i])); } if (!elems.size ()) - return; + return SCM_UNDEFINED; SCM symbol_list = SCM_EOL; Array dists; - SCM current_origin = ly_ch_C_to_scm (""); + SCM current_origin = ly_symbol2scm ("none"); for (int i=0; i <= elems.size (); i++) { Score_element *next_elt = i < elems.size () @@ -58,20 +64,35 @@ Break_align_item::do_pre_processing() if (next_elt) { - next_origin = next_elt->get_elt_property ("origin"); + next_origin = next_elt->get_elt_property ("break-align-symbol"); next_origin = (next_origin == SCM_UNDEFINED) - ? ly_ch_C_to_scm ("") + ? ly_symbol2scm ("none") : next_origin; } else - next_origin = ly_ch_C_to_scm ("begin-of-note"); + next_origin = ly_symbol2scm ("begin-of-note"); + + SCM e = scm_assoc (scm_listify (current_origin, + next_origin, + SCM_UNDEFINED), + scm_eval (ly_symbol2scm ("space-alist"))); - SCM extra_space - = scm_eval (scm_listify (ly_symbol ("break-align-spacer"), - current_origin, next_origin, SCM_UNDEFINED)); - SCM symbol = SCM_CAR (extra_space); - Real spc = gh_scm2double (SCM_CADR(extra_space)); + SCM extra_space; + if (e != SCM_BOOL_F) + { + extra_space = gh_cdr (e); + } + else + { + warning (_f ("unknown spacing pair `%s', `%s'", + ly_symbol2string (current_origin), + ly_symbol2string (next_origin))); + extra_space = scm_listify (ly_symbol2scm ("minimum-space"), gh_double2scm (0.0), SCM_UNDEFINED); + } + + SCM symbol = gh_car (extra_space); + Real spc = gh_scm2double (gh_cadr(extra_space)); spc *= interline; dists.push(spc); @@ -81,44 +102,56 @@ Break_align_item::do_pre_processing() // skip the first sym. - symbol_list = SCM_CDR (scm_reverse (symbol_list)); + symbol_list = gh_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); + symbol_list = gh_cdr (symbol_list); } // 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 + if (gh_pair_p (first_pair)) first_pair = first_pair; + else + first_pair = gh_cons (gh_double2scm (0.0), gh_double2scm (0.0)); 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); + /* + Force callbacks for alignment to be called + */ + Real unused = elems[0]->relative_coordinate (this, X_AXIS); + Real pre_space = elems[0]->relative_coordinate (column_l (), X_AXIS); + + Real xl = elems[0]->extent (X_AXIS)[LEFT]; + if (!isinf (xl)) + pre_space += xl; + else + programming_error ("Infinity reached. "); + + Real xr = elems.top ()->extent (X_AXIS)[RIGHT]; + Real spring_len = elems.top ()->relative_coordinate (column_l (), X_AXIS); + if (!isinf (xr)) + spring_len += xr; + else + programming_error ("Infinity reached."); Real stretch_distance =0.; - if (SCM_CAR (symbol_list) == gh_symbol2scm ("extra-space")) + if (gh_car (symbol_list) == ly_symbol2scm ("extra-space")) { spring_len += dists.top (); stretch_distance = dists.top (); } - else if (SCM_CAR (symbol_list) == gh_symbol2scm ("minimum-space")) + else if (gh_car (symbol_list) == ly_symbol2scm ("minimum-space")) { spring_len = spring_len >? dists.top (); stretch_distance = spring_len; @@ -127,7 +160,6 @@ Break_align_item::do_pre_processing() /* 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", @@ -137,50 +169,18 @@ Break_align_item::do_pre_processing() 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); + + return SCM_UNDEFINED; } -void -Break_align_item::add_breakable_item (Item *it) +Break_align_item::Break_align_item (SCM s) + : Item (s) { - SCM pr = it->remove_elt_property ("break-priority"); + set_elt_property ("stacking-dir" , gh_int2scm (RIGHT)); - if (pr == SCM_UNDEFINED) - return; + Align_interface (this).set_interface (); + Align_interface (this).set_axis (X_AXIS); - int priority = gh_scm2int (pr); - - Score_element * column_l = get_elt_by_priority (priority); - Axis_group_item * hg=0; - if (column_l) - { - hg = dynamic_cast (column_l); - } - else - { - hg = new Axis_group_item; - hg->set_axes (X_AXIS,X_AXIS); - - /* - this is quite ridiculous, but we do this anyway, to ensure that no - warning bells about missing Y refpoints go off later on. - */ - hg->set_parent (this, Y_AXIS); - hg->set_elt_property ("origin", ly_ch_C_to_scm (it->name ())); - - pscore_l_->typeset_element (hg); - add_element_priority (hg, priority); - - if (priority == 0) - center_l_ = hg; - } - - hg->add_element (it); + add_offset_callback (Side_position_interface::aligned_on_self, X_AXIS); } -