From: Keith OHara Date: Tue, 13 Dec 2011 05:56:57 +0000 (-0800) Subject: Looser spacing for ragged-last-bottom; issue 1377 X-Git-Tag: release/2.15.23-1~11 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=968e4722ea19df8485b5fec506c3b2dc9a29c664;p=lilypond.git Looser spacing for ragged-last-bottom; issue 1377 Under ragged-last-bottom, try to make the last page match the previous page by using the same 'force' for spacing it. --- diff --git a/lily/include/page-layout-problem.hh b/lily/include/page-layout-problem.hh index c0577b9ab0..9f879558dc 100644 --- a/lily/include/page-layout-problem.hh +++ b/lily/include/page-layout-problem.hh @@ -29,8 +29,10 @@ public: Page_layout_problem (Paper_book *, SCM page, SCM systems); SCM solution (bool ragged); + SCM fixed_force_solution (Real force); void set_header_height (Real); void set_footer_height (Real); + Real force () const; static bool read_spacing_spec (SCM spec, Real *dest, SCM sym); static bool is_spaceable (Grob *g); static SCM get_details (Grob *g); @@ -47,7 +49,7 @@ protected: void append_system (System *, Spring const &, Real indent, Real padding); void append_prob (Prob *, Spring const &, Real padding); - void solve_rod_spring_problem (bool ragged); + void solve_rod_spring_problem (bool ragged, Real fixed_force); SCM find_system_offsets (); void distribute_loose_lines (vector const &, vector const &, Real, Real); @@ -91,6 +93,7 @@ protected: vector springs_; vector elements_; vector solution_; + Real force_; Skyline bottom_skyline_; Real page_height_; Real header_height_; diff --git a/lily/include/simple-spacer.hh b/lily/include/simple-spacer.hh index b5aeeb200d..9aa6e8bdcd 100644 --- a/lily/include/simple-spacer.hh +++ b/lily/include/simple-spacer.hh @@ -40,6 +40,7 @@ public: Real configuration_length (Real) const; vector spring_positions () const; + void set_force (Real force); Real force () const; Real line_len () const; Real force_penalty (bool ragged) const; diff --git a/lily/page-breaking.cc b/lily/page-breaking.cc index 01d7469f52..36ef0a1372 100644 --- a/lily/page-breaking.cc +++ b/lily/page-breaking.cc @@ -601,7 +601,8 @@ Page_breaking::make_pages (vector lines_per_page, SCM systems) if (label_page_table == SCM_UNDEFINED) label_page_table = SCM_EOL; - // Build a list of (systems . configuration) pairs. Note that we lay out + // Build a list of (systems configuration . footnote-count) triples. + // Note that we lay out // the staves and find the configurations before drawing anything. Some // grobs (like tuplet brackets) look at their neighbours while drawing // themselves. If this happens before the neighbouring staves have @@ -609,6 +610,7 @@ Page_breaking::make_pages (vector lines_per_page, SCM systems) // Align_interface::align_to_ideal_distances might be called). SCM systems_configs_fncounts = SCM_EOL; vsize footnote_count = 0; + Real last_page_force = 0; for (vsize i = 0; i < lines_per_page.size (); i++) { @@ -620,7 +622,19 @@ Page_breaking::make_pages (vector lines_per_page, SCM systems) int fn_lines = Page_layout_problem::get_footnote_count (lines); Page_layout_problem::add_footnotes_to_lines (lines, reset_footnotes_on_new_page ? 0 : footnote_count, book_); - SCM config = get_page_configuration (lines, page_num, rag, bookpart_last_page); + SCM config = SCM_EOL; + SCM dummy_page = make_page (page_num, bookpart_last_page); + Page_layout_problem layout (book_, dummy_page, lines); + if (!scm_is_pair (systems)) + config = SCM_EOL; + else if (rag && !ragged ()) + // If we're ragged-last but not ragged, make the last page + // have the same force as the previous page. + config = layout.fixed_force_solution (last_page_force); + else + config = layout.solution (rag); + + last_page_force = layout.force (); systems_configs_fncounts = scm_cons (scm_cons (lines, config), systems_configs_fncounts); footnote_count += fn_lines; diff --git a/lily/page-layout-problem.cc b/lily/page-layout-problem.cc index fe0058ed44..b21ee1e873 100644 --- a/lily/page-layout-problem.cc +++ b/lily/page-layout-problem.cc @@ -385,6 +385,7 @@ Page_layout_problem::Page_layout_problem (Paper_book *pb, SCM page_scm, SCM syst header_padding_ = 0; footer_padding_ = 0; page_height_ = 100; + force_ = 0; if (page) { @@ -670,16 +671,35 @@ Page_layout_problem::append_prob (Prob *prob, Spring const &spring, Real padding elements_.push_back (Element (prob, padding)); } +/** + For ragged-last pages, we usually want to stretch the page so that it + is not much more compressed than the previous page. Here, if ragged is + true and you pass a value of fixed_force that !isinf, then I will try + to space this page using the given force. If it does not fit, I will + resort to just filling the page (non-raggedly). +*/ void -Page_layout_problem::solve_rod_spring_problem (bool ragged) +Page_layout_problem::solve_rod_spring_problem (bool ragged, Real fixed_force) { Simple_spacer spacer; for (vsize i = 0; i < springs_.size (); ++i) spacer.add_spring (springs_[i]); - spacer.solve (page_height_, ragged); + if (ragged && !isinf (fixed_force)) + { + // We need to tell the spacer it isn't ragged. Otherwise, it will + // refuse to stretch. + spacer.solve (page_height_, false); + + if (spacer.configuration_length (fixed_force) <= page_height_) + spacer.set_force (fixed_force); + } + else + spacer.solve (page_height_, ragged); + solution_ = spacer.spring_positions (); + force_ = spacer.force (); if (!spacer.fits ()) { @@ -700,6 +720,12 @@ Page_layout_problem::solve_rod_spring_problem (bool ragged) } } +Real +Page_layout_problem::force () const +{ + return force_; +} + // The solution_ vector stores the position of every live VerticalAxisGroup // and every title. From that information, // 1) within each system, stretch the staves so they land at the right position @@ -890,10 +916,17 @@ Page_layout_problem::distribute_loose_lines (vector const &loose_lines, } } +SCM +Page_layout_problem::fixed_force_solution (Real force) +{ + solve_rod_spring_problem (true, force); + return find_system_offsets (); +} + SCM Page_layout_problem::solution (bool ragged) { - solve_rod_spring_problem (ragged); + solve_rod_spring_problem (ragged, -infinity_f); return find_system_offsets (); } diff --git a/lily/simple-spacer.cc b/lily/simple-spacer.cc index a870ee3dcc..c6b3c06f5d 100644 --- a/lily/simple-spacer.cc +++ b/lily/simple-spacer.cc @@ -167,6 +167,12 @@ Simple_spacer::configuration_length (Real force) const return l; } +void +Simple_spacer::set_force (Real force) +{ + force_ = force; +} + void Simple_spacer::solve (Real line_len, bool ragged) {