From b351803c2aad0f5e92d379a59ef17e9e292e5d4d Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Sat, 8 Nov 2008 18:53:30 -0800 Subject: [PATCH] Implement space_systems_with_fixed_number_per_page. --- lily/page-breaking.cc | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/lily/page-breaking.cc b/lily/page-breaking.cc index feaaa61010..777eab34db 100644 --- a/lily/page-breaking.cc +++ b/lily/page-breaking.cc @@ -796,11 +796,44 @@ Page_breaking::space_systems_on_best_pages (vsize configuration, vsize first_pag return finalize_spacing_result (configuration, best); } -Page_spacing_result space_systems_with_fixed_number_per_page (vsize configuration_index, - int systems_per_page, - vsize first_page_num) +Page_spacing_result +Page_breaking::space_systems_with_fixed_number_per_page (vsize configuration, + int systems_per_page, + vsize first_page_num) { - return Page_spacing_result (); + Page_spacing_result res; + Page_spacing space (page_height (first_page_num, false), page_top_space_); + vsize line = 0; + vsize page = 0; + vsize page_first_line = 0; + + cache_line_details (configuration); + while (line < cached_line_details_.size ()) + { + page++; + space.clear (); + space.resize (page_height (first_page_num + page, false)); + + int system_count_on_this_page = 0; + while (system_count_on_this_page < systems_per_page + && line < cached_line_details_.size ()) + { + space.append_system (cached_line_details_[line]); + system_count_on_this_page += cached_line_details_[line].compressed_nontitle_lines_count_; + line++; + } + + res.systems_per_page_.push_back (line - page_first_line); + res.force_.push_back (space.force_); + res.penalty_ += cached_line_details_[line-1].page_penalty_; + page_first_line = line; + } + + /* Recalculate forces for the last page because we know now that is + was really the last page. */ + space.resize (page_height (first_page_num + page, true)); + res.force_.back () = space.force_; + return finalize_spacing_result (configuration, res); } Page_spacing_result -- 2.39.5