From 87354fef0dcfb6014270d0311abfb45cc57d2726 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 20 May 2007 19:24:09 -0300 Subject: [PATCH] Fix disappearing last page problem. - Add Page_breaking::uncompress_page_spacing_results(). - Use on space_systems_on_n_.*() functions. --- lily/include/page-breaking.hh | 1 + lily/page-breaking.cc | 87 ++++++++++++++++++++++------------- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/lily/include/page-breaking.hh b/lily/include/page-breaking.hh index 082384d0fe..8f1e55e5bf 100644 --- a/lily/include/page-breaking.hh +++ b/lily/include/page-breaking.hh @@ -176,5 +176,6 @@ private: Page_spacing_result finalize_spacing_result (vsize configuration_index, Page_spacing_result); void create_system_list (); void find_chunks_and_breaks (Break_predicate); + void uncompress_page_spacing_results (Page_spacing_result*); }; #endif /* PAGE_BREAKING_HH */ diff --git a/lily/page-breaking.cc b/lily/page-breaking.cc index 1d96f7359f..0d88338935 100644 --- a/lily/page-breaking.cc +++ b/lily/page-breaking.cc @@ -53,28 +53,6 @@ compress_lines (const vector &orig) return ret; } -/* translate the number of systems-per-page into something meaningful for - the uncompressed lines. -*/ -static vector -uncompress_solution (vector const &systems_per_page, - vector const &compressed) -{ - vector ret; - vsize start_sys = 0; - - for (vsize i = 0; i < systems_per_page.size (); i++) - { - int compressed_count = 0; - for (vsize j = start_sys; j < start_sys + systems_per_page[i]; j++) - compressed_count += (int)compressed[j].force_; - - ret.push_back (systems_per_page[i] + compressed_count); - start_sys += systems_per_page[i]; - } - return ret; -} - /* for Page_breaking, the start index (when we are dealing with the stuff between a pair of breakpoints) refers to the break_ index of the end of the previous page. So the system index of the start of the current page @@ -519,8 +497,8 @@ Page_breaking::cache_line_details (vsize configuration_index) vsize sys = next_system (current_chunks_[i]); if (system_specs_[sys].pscore_) { - vsize start; - vsize end; + vsize start = 0; + vsize end = 0; line_breaker_args (sys, current_chunks_[i], current_chunks_[i+1], &start, &end); vector details = line_breaking_[sys].line_details (start, end, div[i]); @@ -652,11 +630,18 @@ Page_breaking::space_systems_on_n_pages (vsize configuration, vsize n, vsize fir if (n > cached_line_details_.size ()) return Page_spacing_result (); if (n == 1) - ret = space_systems_on_1_page (cached_line_details_, - page_height (first_page_num, is_last ()), - ragged () || (is_last () && ragged_last ())); + { + ret = space_systems_on_1_page (cached_line_details_, + page_height (first_page_num, is_last ()), + ragged () || (is_last () && ragged_last ())); + + uncompress_page_spacing_results (&ret); + } else if (n == 2) - ret = space_systems_on_2_pages (configuration, first_page_num); + { + ret = space_systems_on_2_pages (configuration, first_page_num); + uncompress_page_spacing_results (&ret); + } else { Page_spacer ps (cached_line_details_, first_page_num, this); @@ -691,9 +676,16 @@ Page_breaking::space_systems_on_n_or_one_more_pages (vsize configuration, vsize vsize min_p_count = min_page_count (configuration, first_page_num); Page_spacer ps (cached_line_details_, first_page_num, this); if (n >= min_p_count) - n_res = ps.solve (n); + { + n_res = ps.solve (n); + uncompress_page_spacing_results (&n_res); + } if (n < cached_line_details_.size ()) - m_res = ps.solve (n+1); + { + m_res = ps.solve (n+1); + uncompress_page_spacing_results (&m_res); + } + } Real penalty = blank_page_penalty (); @@ -728,14 +720,44 @@ Page_breaking::space_systems_on_best_pages (vsize configuration, vsize first_pag return finalize_spacing_result (configuration, best); } + + +/* translate the number of systems-per-page into something meaningful for + the uncompressed lines. +*/ +static vector +uncompress_solution (vector const &systems_per_page, + vector const &compressed) +{ + vector ret; + vsize start_sys = 0; + + for (vsize i = 0; i < systems_per_page.size (); i++) + { + int compressed_count = 0; + for (vsize j = start_sys; j < start_sys + systems_per_page[i]; j++) + compressed_count += (int)compressed[j].force_; + + ret.push_back (systems_per_page[i] + compressed_count); + start_sys += systems_per_page[i]; + } + return ret; +} + +void +Page_breaking::uncompress_page_spacing_results (Page_spacing_result *res) +{ + res->systems_per_page_ = uncompress_solution (res->systems_per_page_, cached_line_details_); +} + /* Calculate demerits and fix res.systems_per_page_ so that it refers to the original line numbers, not the ones given by compress_lines (). */ Page_spacing_result Page_breaking::finalize_spacing_result (vsize configuration, Page_spacing_result res) { cache_line_details (configuration); - res.systems_per_page_ = uncompress_solution (res.systems_per_page_, cached_line_details_); - + uncompress_page_spacing_results (&res); + Real line_force = 0; Real line_penalty = 0; Real page_force = 0; @@ -763,7 +785,6 @@ Page_breaking::finalize_spacing_result (vsize configuration, Page_spacing_result becomes averaged out over many pages. */ res.demerits_ = line_force + line_penalty + (page_force + res.penalty_) * page_weighting; return res; - } /* the cases for page_count = 1 or 2 can be done in O (n) time. Since they -- 2.39.2