From 58d1c2f39c091da0325d54b19476ee7532d8889f Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Sun, 11 Oct 2009 19:19:59 -0700 Subject: [PATCH] Fix 850. When page breaking, take into account the padding before, after and between titles. --- .../regression/page-breaking-title-padding.ly | 18 +++++++++++ .../page-breaking-title-padding2.ly | 18 +++++++++++ .../page-breaking-title-padding3.ly | 21 +++++++++++++ lily/constrained-breaking.cc | 31 +++++++++++++++++++ lily/include/constrained-breaking.hh | 23 +++----------- lily/page-breaking.cc | 22 ++++++------- lily/page-spacing.cc | 4 +-- 7 files changed, 104 insertions(+), 33 deletions(-) create mode 100644 input/regression/page-breaking-title-padding.ly create mode 100644 input/regression/page-breaking-title-padding2.ly create mode 100644 input/regression/page-breaking-title-padding3.ly diff --git a/input/regression/page-breaking-title-padding.ly b/input/regression/page-breaking-title-padding.ly new file mode 100644 index 0000000000..203fbde731 --- /dev/null +++ b/input/regression/page-breaking-title-padding.ly @@ -0,0 +1,18 @@ +\version "2.13.4" + +#(set-default-paper-size "a6") + +\book { + \header { + texidoc = "Padding between titles is honoured by the page breaker. +This should take up two pages." + } + + \paper { + between-title-spacing = #'((padding . 300)) + } + + \markup "00" + \markup "01" + { c' } +} diff --git a/input/regression/page-breaking-title-padding2.ly b/input/regression/page-breaking-title-padding2.ly new file mode 100644 index 0000000000..60ec2cf465 --- /dev/null +++ b/input/regression/page-breaking-title-padding2.ly @@ -0,0 +1,18 @@ +\version "2.13.4" + +#(set-default-paper-size "a6") + +\book { + \header { + texidoc = "Padding after titles is honoured by the page breaker. +This should take up two pages." + } + + \paper { + after-title-spacing = #'((padding . 300)) + } + + \markup "00" + \markup "01" + { c' } +} diff --git a/input/regression/page-breaking-title-padding3.ly b/input/regression/page-breaking-title-padding3.ly new file mode 100644 index 0000000000..945e828354 --- /dev/null +++ b/input/regression/page-breaking-title-padding3.ly @@ -0,0 +1,21 @@ +\version "2.13.4" + +#(set-default-paper-size "a6") + +\book { + \header { + texidoc = "Padding before titles is honoured by the page breaker. +This should take up two pages." + } + + \paper { + before-title-spacing = #'((padding . 300)) + } + + \markup "00" + \markup "01" + \score { + { c'1 \allowPageTurn } + } + \markup "02" +} diff --git a/lily/constrained-breaking.cc b/lily/constrained-breaking.cc index f0f96164df..44c2abc70a 100644 --- a/lily/constrained-breaking.cc +++ b/lily/constrained-breaking.cc @@ -381,10 +381,12 @@ Constrained_breaking::initialize () */ between_system_space_ = 0; between_system_padding_ = 0; + before_title_padding_ = 0; Output_def *l = pscore_->layout (); SCM spacing_spec = l->c_variable ("between-system-spacing"); + SCM title_spec = l->c_variable ("before-title-spacing"); SCM page_breaking_spacing_spec = l->c_variable ("page-breaking-between-system-spacing"); Page_layout_problem::read_spacing_spec (spacing_spec, &between_system_padding_, @@ -392,6 +394,9 @@ Constrained_breaking::initialize () Page_layout_problem::read_spacing_spec (page_breaking_spacing_spec, &between_system_padding_, ly_symbol2scm ("padding")); + Page_layout_problem::read_spacing_spec (title_spec, + &before_title_padding_, + ly_symbol2scm ("padding")); Interval first_line = line_dimensions_int (pscore_->layout (), 0); Interval other_lines = line_dimensions_int (pscore_->layout (), 1); @@ -472,6 +477,7 @@ Constrained_breaking::fill_line_details (Line_details *const out, vsize start, v || isnan (extent[RIGHT])) ? Interval (0, 0) : extent; out->padding_ = between_system_padding_; + out->title_padding_ = before_title_padding_; out->space_ = between_system_space_; out->inverse_hooke_ = extent.length () + between_system_space_; } @@ -485,3 +491,28 @@ Constrained_breaking::combine_demerits (Real force, Real prev_force) return force * force + (prev_force - force) * (prev_force - force); } +Line_details::Line_details (Prob *pb, Output_def *paper) +{ + SCM spec = paper->c_variable ("after-title-spacing"); + SCM title_spec = paper->c_variable ("between-title-spacing"); + padding_ = 0; + title_padding_ = 0; + Page_layout_problem::read_spacing_spec (spec, &padding_, ly_symbol2scm ("padding")); + Page_layout_problem::read_spacing_spec (title_spec, &title_padding_, ly_symbol2scm ("padding")); + + last_column_ = 0; + force_ = 0; + extent_ = unsmob_stencil (pb->get_property ("stencil")) ->extent (Y_AXIS); + bottom_padding_ = 0; + space_ = robust_scm2double (pb->get_property ("next-space"), 1.0); + inverse_hooke_ = 1.0; + break_permission_ = ly_symbol2scm ("allow"); + page_permission_ = pb->get_property ("page-break-permission"); + turn_permission_ = pb->get_property ("page-turn-permission"); + 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")); + compressed_lines_count_ = 1; + compressed_nontitle_lines_count_ = title_ ? 0 : 1; +} diff --git a/lily/include/constrained-breaking.hh b/lily/include/constrained-breaking.hh index 4767902da9..1562dc1d17 100644 --- a/lily/include/constrained-breaking.hh +++ b/lily/include/constrained-breaking.hh @@ -21,6 +21,7 @@ struct Line_details { Real padding_; /* compulsory space after this system (if we're not last on a page) */ + Real title_padding_; Real bottom_padding_; Real space_; /* spring length */ Real inverse_hooke_; @@ -47,6 +48,7 @@ struct Line_details { last_column_ = 0; force_ = infinity_f; padding_ = 0; + title_padding_ = 0; bottom_padding_ = 0; space_ = 0; inverse_hooke_ = 1; @@ -61,25 +63,7 @@ struct Line_details { compressed_nontitle_lines_count_ = 1; } - Line_details (Prob *pb) - { - last_column_ = 0; - force_ = 0; - extent_ = unsmob_stencil (pb->get_property ("stencil")) ->extent (Y_AXIS); - padding_ = robust_scm2double (pb->get_property ("next-padding"), 0); - bottom_padding_ = 0; - space_ = robust_scm2double (pb->get_property ("next-space"), 1.0); - inverse_hooke_ = 1.0; - break_permission_ = ly_symbol2scm ("allow"); - page_permission_ = pb->get_property ("page-break-permission"); - turn_permission_ = pb->get_property ("page-turn-permission"); - 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")); - compressed_lines_count_ = 1; - compressed_nontitle_lines_count_ = title_ ? 0 : 1; - } + Line_details (Prob *pb, Output_def *paper); }; /* @@ -131,6 +115,7 @@ private: bool ragged_right_; bool ragged_last_; Real between_system_space_; + Real before_title_padding_; Real between_system_padding_; /* the (i,j)th entry is the configuration for breaking between diff --git a/lily/page-breaking.cc b/lily/page-breaking.cc index 038b0af247..5020a33eba 100644 --- a/lily/page-breaking.cc +++ b/lily/page-breaking.cc @@ -89,8 +89,10 @@ compress_lines (const vector &orig) { Line_details const &old = ret.back (); Line_details compressed = orig[i]; + Real padding = orig[i].title_ ? old.title_padding_ : old.padding_; + compressed.extent_[DOWN] = old.extent_[DOWN]; - compressed.extent_[UP] = old.extent_[UP] + orig[i].extent_.length () + old.padding_; + compressed.extent_[UP] = old.extent_[UP] + orig[i].extent_.length () + padding; compressed.space_ += old.space_; compressed.inverse_hooke_ += old.inverse_hooke_; @@ -751,11 +753,6 @@ Page_breaking::cache_line_details (vsize configuration_index) if (cached_configuration_index_ != configuration_index) { cached_configuration_index_ = configuration_index; - Real padding = 0; - SCM spacing_spec = book_->paper_->c_variable ("between-system-spacing"); - SCM page_breaking_spacing_spec = book_->paper_->c_variable ("page-breaking-between-system-spacing"); - Page_layout_problem::read_spacing_spec (spacing_spec, &padding, ly_symbol2scm ("padding")); - Page_layout_problem::read_spacing_spec (page_breaking_spacing_spec, &padding, ly_symbol2scm ("padding")); Line_division &div = current_configurations_[configuration_index]; uncompressed_line_details_.clear (); @@ -774,10 +771,7 @@ Page_breaking::cache_line_details (vsize configuration_index) else { assert (div[i] == 1); - uncompressed_line_details_.push_back (Line_details (system_specs_[sys].prob_)); - uncompressed_line_details_.back ().padding_ = - robust_scm2double (system_specs_[sys].prob_->get_property ("next-padding"), - padding); + uncompressed_line_details_.push_back (Line_details (system_specs_[sys].prob_, book_->paper_)); } } cached_line_details_ = compress_lines (uncompressed_line_details_); @@ -849,8 +843,12 @@ Page_breaking::min_page_count (vsize configuration, vsize first_page_num) for (vsize i = 0; i < cached_line_details_.size (); i++) { Real ext_len = cached_line_details_[i].extent_.length (); - Real next_rod_height = cur_rod_height + ext_len - + ((cur_rod_height > 0) ? cached_line_details_[i].padding_: 0); + Real padding = 0; + if (cur_rod_height > 0) + padding = cached_line_details_[i].title_ ? + cached_line_details_[i-1].title_padding_ : cached_line_details_[i-1].padding_; + + Real next_rod_height = cur_rod_height + ext_len + padding; Real next_spring_height = cur_spring_height + cached_line_details_[i].space_; Real next_height = next_rod_height + (ragged () ? next_spring_height : 0) + min_whitespace_at_bottom_of_page (cached_line_details_[i]); diff --git a/lily/page-spacing.cc b/lily/page-spacing.cc index ab8085c1d5..e6112e095e 100644 --- a/lily/page-spacing.cc +++ b/lily/page-spacing.cc @@ -40,7 +40,7 @@ Page_spacing::append_system (const Line_details &line) if (!rod_height_) first_line_ = line; - rod_height_ += last_line_.padding_; + rod_height_ += line.title_ ? last_line_.title_padding_ : last_line_.padding_; rod_height_ += line.extent_.length (); spring_len_ += line.space_; @@ -55,7 +55,7 @@ void Page_spacing::prepend_system (const Line_details &line) { if (rod_height_) - rod_height_ += line.padding_; + rod_height_ += first_line_.title_ ? line.title_padding_ : line.padding_; else last_line_ = line; -- 2.39.2