From 5abf10a3f05d1264b3dc8d92f56639df27e11bbc Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Sun, 11 Nov 2007 09:37:14 +1100 Subject: [PATCH] When working out page breaks, take into account the fact that titles ignore page-top-space. --- lily/include/constrained-breaking.hh | 4 ++++ lily/include/page-breaking.hh | 2 ++ lily/include/page-spacing.hh | 5 ++++- lily/page-breaking.cc | 18 +++++++++++++----- lily/page-spacing.cc | 15 ++++++++++++--- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lily/include/constrained-breaking.hh b/lily/include/constrained-breaking.hh index 9aa5862761..5759a12c05 100644 --- a/lily/include/constrained-breaking.hh +++ b/lily/include/constrained-breaking.hh @@ -31,6 +31,8 @@ struct Line_details { Real page_penalty_; Real turn_penalty_; + bool title_; + Line_details () { force_ = infinity_f; @@ -44,6 +46,7 @@ struct Line_details { break_penalty_ = 0; page_penalty_ = 0; turn_penalty_ = 0; + title_ = false; } Line_details (Prob *pb) @@ -60,6 +63,7 @@ struct Line_details { break_penalty_ = 0; page_penalty_ = robust_scm2double (pb->get_property ("page-break-penalty"), 0); turn_penalty_ = robust_scm2double (pb->get_property ("page-turn-penalty"), 0); + title_ = to_boolean (pb->get_property ("is-title")); } }; diff --git a/lily/include/page-breaking.hh b/lily/include/page-breaking.hh index 52a95812c4..18704fd36b 100644 --- a/lily/include/page-breaking.hh +++ b/lily/include/page-breaking.hh @@ -101,6 +101,7 @@ public: bool ragged_last () const; bool is_last () const; Real page_height (int page_number, bool last) const; + Real page_top_space () const; protected: Paper_book *book_; @@ -147,6 +148,7 @@ private: vector line_breaking_; bool ragged_; bool ragged_last_; + Real page_top_space_; vector current_configurations_; vector current_chunks_; diff --git a/lily/include/page-spacing.hh b/lily/include/page-spacing.hh index 9bb37804a7..fe7056c597 100644 --- a/lily/include/page-spacing.hh +++ b/lily/include/page-spacing.hh @@ -61,12 +61,15 @@ struct Page_spacing Real rod_height_; Real spring_len_; Real inverse_spring_k_; + Real page_top_space_; Line_details last_line_; + Line_details first_line_; - Page_spacing (Real page_height) + Page_spacing (Real page_height, Real page_top_space) { page_height_ = page_height; + page_top_space_ = page_top_space; clear (); } diff --git a/lily/page-breaking.cc b/lily/page-breaking.cc index b6951925ad..be11ffa3ea 100644 --- a/lily/page-breaking.cc +++ b/lily/page-breaking.cc @@ -36,6 +36,7 @@ compress_lines (const vector &orig) compressed.extent_[UP] = old.extent_[UP] + orig[i].extent_.length () + old.padding_; compressed.space_ += old.space_; compressed.inverse_hooke_ += old.inverse_hooke_; + compressed.title_ = old.title_; /* we don't need the force_ field for the vertical spacing, so we use force_ = n to signal that the line was compressed, @@ -99,6 +100,7 @@ Page_breaking::Page_breaking (Paper_book *pb, Break_predicate is_break) book_ = pb; ragged_ = to_boolean (pb->paper_->c_variable ("ragged-bottom")); ragged_last_ = to_boolean (pb->paper_->c_variable ("ragged-last-bottom")); + page_top_space_ = robust_scm2double (pb->paper_->c_variable ("page-top-space"), 0); create_system_list (); find_chunks_and_breaks (is_break); } @@ -119,6 +121,12 @@ Page_breaking::ragged_last () const return ragged_last_; } +Real +Page_breaking::page_top_space () const +{ + return page_top_space_; +} + /* translate indices into breaks_ into start-end parameters for the line breaker */ void Page_breaking::line_breaker_args (vsize sys, @@ -210,7 +218,7 @@ Page_breaking::page_height (int page_num, bool last) const ly_symbol2scm ("is-last"), scm_from_bool (last), SCM_UNDEFINED)); SCM height = scm_apply_1 (calc_height, page, SCM_EOL); - return scm_to_double (height) - scm_to_double (book_->paper_->c_variable ("page-top-space")); + return scm_to_double (height) - page_top_space_; } SCM @@ -765,7 +773,7 @@ Page_breaking::pack_systems_on_least_pages (vsize configuration, vsize first_pag Page_spacing_result res; vsize page = 0; vsize page_first_line = 0; - Page_spacing space (page_height (first_page_num, false)); + Page_spacing space (page_height (first_page_num, false), page_top_space_); cache_line_details (configuration); for (vsize line = 0; line < cached_line_details_.size (); line++) @@ -869,7 +877,7 @@ Page_breaking::finalize_spacing_result (vsize configuration, Page_spacing_result Page_spacing_result Page_breaking::space_systems_on_1_page (vector const &lines, Real page_height, bool ragged) { - Page_spacing space (page_height); + Page_spacing space (page_height, page_top_space_); Page_spacing_result ret; for (vsize i = 0; i < lines.size (); i++) @@ -909,8 +917,8 @@ Page_breaking::space_systems_on_2_pages (vsize configuration, vsize first_page_n vector page1_force; vector page2_force; - Page_spacing page1 (page1_height); - Page_spacing page2 (page2_height); + Page_spacing page1 (page1_height, page_top_space_); + Page_spacing page2 (page2_height, page_top_space_); page1_force.resize (cached_line_details_.size () - 1, infinity_f); page2_force.resize (cached_line_details_.size () - 1, infinity_f); diff --git a/lily/page-spacing.cc b/lily/page-spacing.cc index 82a037bde5..384ce44022 100644 --- a/lily/page-spacing.cc +++ b/lily/page-spacing.cc @@ -16,10 +16,13 @@ void Page_spacing::calc_force () { - if (rod_height_ + last_line_.bottom_padding_ >= page_height_) + /* If the first system is a title, we add back in the page-top-space. */ + Real height = first_line_.title_ ? page_height_ + page_top_space_ : page_height_; + + if (rod_height_ + last_line_.bottom_padding_ >= height) force_ = infinity_f; else - force_ = (page_height_ - rod_height_ - last_line_.bottom_padding_ - spring_len_) + force_ = (height - rod_height_ - last_line_.bottom_padding_ - spring_len_) / max (0.1, inverse_spring_k_); } @@ -33,6 +36,9 @@ Page_spacing::resize (Real new_height) void Page_spacing::append_system (const Line_details &line) { + if (!rod_height_) + first_line_ = line; + rod_height_ += last_line_.padding_; rod_height_ += line.extent_.length (); @@ -56,6 +62,8 @@ Page_spacing::prepend_system (const Line_details &line) spring_len_ += line.space_; inverse_spring_k_ += line.inverse_hooke_; + first_line_ = line; + calc_force (); } @@ -153,7 +161,8 @@ bool Page_spacer::calc_subproblem (vsize page, vsize line) { bool last = line == lines_.size () - 1; - Page_spacing space (breaker_->page_height (page + first_page_num_, last)); + Page_spacing space (breaker_->page_height (page + first_page_num_, last), + breaker_->page_top_space ()); Page_spacing_node &cur = state_.at (line, page); bool ragged = ragged_ || (ragged_last_ && last); -- 2.39.5