Index: ChangeLog =================================================================== RCS file: /sources/lilypond/lilypond/ChangeLog,v retrieving revision 1.5344 diff -u -r1.5344 ChangeLog --- ChangeLog 30 Sep 2006 20:59:53 -0000 1.5344 +++ ChangeLog 1 Oct 2006 09:10:27 -0000 @@ -1,5 +1,8 @@ 2006-10-01 Joe Neeman + * Documentation/user/page.itely (Page formatting): + document auto-first-page-number + * lily/page-spacing.cc (compress_lines, uncompress_solution): handle correctly the case where there are multiple \noPageBreaks in a row. Index: Documentation/user/page.itely =================================================================== RCS file: /sources/lilypond/lilypond/Documentation/user/page.itely,v retrieving revision 1.11 diff -u -r1.11 page.itely --- Documentation/user/page.itely 22 Sep 2006 08:12:22 -0000 1.11 +++ Documentation/user/page.itely 1 Oct 2006 09:10:27 -0000 @@ -268,6 +268,14 @@ spacing. High values will make page spacing more important. Default value is 1. address@hidden auto-first-page-number address@hidden auto-first-page-number +Whether the first page number is odd or even page affects the +page-turn-page-breaking algorithm. If this variable is set to #t, the +page-turn-page-breaking algorithm will decide for itself whether it is +better to start with an odd or an even page number. The first page number +will either be left alone or increased by one. + @end table @end quotation Index: lily/constrained-breaking.cc =================================================================== RCS file: /sources/lilypond/lilypond/lily/constrained-breaking.cc,v retrieving revision 1.10 diff -u -r1.10 constrained-breaking.cc --- lily/constrained-breaking.cc 22 Sep 2006 07:51:36 -0000 1.10 +++ lily/constrained-breaking.cc 1 Oct 2006 09:10:29 -0000 @@ -76,12 +76,15 @@ vsize start_col = starting_breakpoints_[start]; Matrix &st = state_[start]; vsize max_index = brk - start_col; - for (vsize j=sys; j < max_index; j++) + for (vsize j=max_index; j-- > sys;) { if (0 == sys && j > 0) - break; /* the first line cannot have its first break after the beginning */ + continue; /* the first line cannot have its first break after the beginning */ Line_details const &cur = lines_.at (brk, j + start_col); + if (isinf (cur.force_)) + break; + Real prev_f = 0; Real prev_dem = 0; @@ -91,14 +94,11 @@ prev_dem = st.at (j, sys-1).demerits_; } if (isinf (prev_dem)) - break; - - Real dem = combine_demerits (cur.force_, prev_f) + prev_dem + cur.break_penalty_; - if (isinf (dem)) continue; + Real dem = combine_demerits (cur.force_, prev_f) + prev_dem + cur.break_penalty_; Constrained_break_node &n = st.at (max_index, sys); - if (isinf (n.demerits_) || dem < n.demerits_) + if (dem < n.demerits_) { found_something = true; n.demerits_ = dem; @@ -140,71 +140,6 @@ { systems_ = systems; - if (!breaks_.size () && pscore_) - { - Output_def *l = pscore_->layout (); - System *sys = pscore_->root_system (); - Real padding = robust_scm2double (l->c_variable ("between-system-padding"), 0); - Real space = robust_scm2double (l->c_variable ("ideal-system-space"), 0); - bool ragged_right = to_boolean (pscore_->layout ()->c_variable ("ragged-right")); - bool ragged_last = to_boolean (pscore_->layout ()->c_variable ("ragged-last")); - - Interval first_line = line_dimensions_int (pscore_->layout (), 0); - Interval other_lines = line_dimensions_int (pscore_->layout (), 1); - /* do all the rod/spring problems */ - breaks_ = pscore_->find_break_indices (); - all_ = pscore_->root_system ()->columns (); - lines_.resize (breaks_.size (), breaks_.size (), Line_details ()); - vector forces = get_line_forces (all_, - other_lines.length (), - other_lines.length () - first_line.length (), - ragged_right); - for (vsize i = 0; i < breaks_.size () - 1; i++) - { - Real max_ext = 0; - for (vsize j = i + 1; j < breaks_.size (); j++) - { - int start = Paper_column::get_rank (all_[breaks_[i]]); - int end = Paper_column::get_rank (all_[breaks_[j]]); - Interval extent = sys->pure_height (sys, start, end); - bool last = j == breaks_.size () - 1; - bool ragged = ragged_right || (last && ragged_last); - Line_details &line = lines_.at (j, i); - - line.force_ = forces[i*breaks_.size () + j]; - if (ragged && last && !isinf (line.force_)) - line.force_ = 0; - if (isinf (line.force_)) - break; - - Grob *c = all_[breaks_[j]]; - line.break_penalty_ = robust_scm2double (c->get_property ("line-break-penalty"), 0); - line.page_penalty_ = robust_scm2double (c->get_property ("page-break-penalty"), 0); - line.turn_penalty_ = robust_scm2double (c->get_property ("page-turn-penalty"), 0); - line.break_permission_ = c->get_property ("line-break-permission"); - line.page_permission_ = c->get_property ("page-break-permission"); - line.turn_permission_ = c->get_property ("page-turn-permission"); - - max_ext = max (max_ext, extent.length ()); - line.extent_ = extent; - line.padding_ = padding; - line.space_ = space; - line.inverse_hooke_ = 1; - } - } - - /* work out all the starting indices */ - for (vsize i = 0; i < start_.size (); i++) - { - vsize j; - for (j = 0; j < breaks_.size () - 1 && breaks_[j] < start_[i]; j++) - ; - starting_breakpoints_.push_back (j); - start_[i] = breaks_[j]; - } - state_.resize (start_.size ()); - } - if (pscore_ && systems_ > valid_systems_) { for (vsize i = 0; i < state_.size (); i++) @@ -359,22 +294,97 @@ return brk; } -Constrained_breaking::Constrained_breaking () +Constrained_breaking::Constrained_breaking (Paper_score *ps) { valid_systems_ = systems_ = 0; start_.push_back (0); + pscore_ = ps; + initialize (); } -Constrained_breaking::Constrained_breaking (vector const &start) +Constrained_breaking::Constrained_breaking (Paper_score *ps, vector const &start) : start_ (start) { valid_systems_ = systems_ = 0; + pscore_ = ps; + initialize (); +} + +/* find the forces for all possible lines and cache ragged_ and ragged_right_ */ +void +Constrained_breaking::initialize () +{ + if (!pscore_) + return; + + ragged_right_ = to_boolean (pscore_->layout ()->c_variable ("ragged-right")); + ragged_last_ = to_boolean (pscore_->layout ()->c_variable ("ragged-last")); + + Output_def *l = pscore_->layout (); + System *sys = pscore_->root_system (); + Real padding = robust_scm2double (l->c_variable ("between-system-padding"), 0); + Real space = robust_scm2double (l->c_variable ("ideal-system-space"), 0); + + Interval first_line = line_dimensions_int (pscore_->layout (), 0); + Interval other_lines = line_dimensions_int (pscore_->layout (), 1); + /* do all the rod/spring problems */ + breaks_ = pscore_->find_break_indices (); + all_ = pscore_->root_system ()->columns (); + lines_.resize (breaks_.size (), breaks_.size (), Line_details ()); + vector forces = get_line_forces (all_, + other_lines.length (), + other_lines.length () - first_line.length (), + ragged_right_); + for (vsize i = 0; i < breaks_.size () - 1; i++) + { + Real max_ext = 0; + for (vsize j = i + 1; j < breaks_.size (); j++) + { + int start = Paper_column::get_rank (all_[breaks_[i]]); + int end = Paper_column::get_rank (all_[breaks_[j]]); + Interval extent = sys->pure_height (sys, start, end); + bool last = j == breaks_.size () - 1; + bool ragged = ragged_right_ || (last && ragged_last_); + Line_details &line = lines_.at (j, i); + + line.force_ = forces[i*breaks_.size () + j]; + if (ragged && last && !isinf (line.force_)) + line.force_ = 0; + if (isinf (line.force_)) + break; + + Grob *c = all_[breaks_[j]]; + line.break_penalty_ = robust_scm2double (c->get_property ("line-break-penalty"), 0); + line.page_penalty_ = robust_scm2double (c->get_property ("page-break-penalty"), 0); + line.turn_penalty_ = robust_scm2double (c->get_property ("page-turn-penalty"), 0); + line.break_permission_ = c->get_property ("line-break-permission"); + line.page_permission_ = c->get_property ("page-break-permission"); + line.turn_permission_ = c->get_property ("page-turn-permission"); + + max_ext = max (max_ext, extent.length ()); + line.extent_ = extent; + line.padding_ = padding; + line.space_ = space; + line.inverse_hooke_ = 1; + } + } + + /* work out all the starting indices */ + for (vsize i = 0; i < start_.size (); i++) + { + vsize j; + for (j = 0; j < breaks_.size () - 1 && breaks_[j] < start_[i]; j++) + ; + starting_breakpoints_.push_back (j); + start_[i] = breaks_[j]; + } + state_.resize (start_.size ()); } Real Constrained_breaking::combine_demerits (Real force, Real prev_force) { - if (to_boolean (pscore_->layout ()->c_variable ("ragged-right"))) + if (ragged_right_) return force * force; return force * force + (prev_force - force) * (prev_force - force); Index: lily/page-breaking.cc =================================================================== RCS file: /sources/lilypond/lilypond/lily/page-breaking.cc,v retrieving revision 1.6 diff -u -r1.6 page-breaking.cc --- lily/page-breaking.cc 28 Sep 2006 22:40:05 -0000 1.6 +++ lily/page-breaking.cc 1 Oct 2006 09:10:29 -0000 @@ -283,8 +283,7 @@ if ((break_point || chunk_end) && !last) line_breaker_columns.push_back (j); } - line_breaking_.push_back (Constrained_breaking (line_breaker_columns)); - line_breaking_.back ().set_pscore (all_[i].pscore_); + line_breaking_.push_back (Constrained_breaking (all_[i].pscore_, line_breaker_columns)); } else { @@ -293,7 +292,7 @@ breaks_.push_back (Break_position (i)); chunks_.push_back (Break_position (i)); - line_breaking_.push_back (Constrained_breaking ()); + line_breaking_.push_back (Constrained_breaking (NULL)); } } } Index: lily/paper-score.cc =================================================================== RCS file: /sources/lilypond/lilypond/lily/paper-score.cc,v retrieving revision 1.104 diff -u -r1.104 paper-score.cc --- lily/paper-score.cc 4 Sep 2006 05:31:27 -0000 1.104 +++ lily/paper-score.cc 1 Oct 2006 09:10:29 -0000 @@ -99,7 +99,7 @@ vector Paper_score::calc_breaking () { - Constrained_breaking algorithm; + Constrained_breaking algorithm (this); vector sol; message (_ ("Calculating line breaks...") + " "); @@ -107,11 +107,8 @@ int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0); if (system_count) algorithm.resize (system_count); - - algorithm.set_pscore (this); - sol = algorithm.solve (); - return sol; + return algorithm.solve (); } void Index: lily/include/constrained-breaking.hh =================================================================== RCS file: /sources/lilypond/lilypond/lily/include/constrained-breaking.hh,v retrieving revision 1.10 diff -u -r1.10 constrained-breaking.hh --- lily/include/constrained-breaking.hh 8 Aug 2006 10:12:09 -0000 1.10 +++ lily/include/constrained-breaking.hh 1 Oct 2006 09:10:29 -0000 @@ -90,12 +90,12 @@ /* A dynamic programming solution to breaking scores into lines */ -class Constrained_breaking : public Break_algorithm +class Constrained_breaking { public: vector solve (); - Constrained_breaking (); - Constrained_breaking (vector const &start_col_posns); + Constrained_breaking (Paper_score *ps); + Constrained_breaking (Paper_score *ps, vector const &start_col_posns); vector get_solution (vsize start, vsize end, vsize sys_count); vector get_best_solution (vsize start, vsize end); @@ -106,8 +106,11 @@ void resize (vsize systems); private: + Paper_score *pscore_; vsize valid_systems_; vsize systems_; + bool ragged_right_; + bool ragged_last_; /* the (i,j)th entry is the configuration for breaking between columns i and j */ @@ -123,6 +126,8 @@ vector all_; vector breaks_; + void initialize (); + Column_x_positions space_line (vsize start_col, vsize end_col); vsize prepare_solution (vsize start, vsize end, vsize sys_count);