From b5cf8a41dcd7dfb96628c21f40a7ad8b35eafaba Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Mon, 21 May 2007 09:57:19 +1000 Subject: [PATCH] Revert "Fix disappearing last page problem." This reverts commit e0bffa5a02d173f02a2f259eb2916d06c777d5f8. --- lily/include/page-breaking.hh | 1 - lily/page-breaking.cc | 87 +++++++++++++---------------------- 2 files changed, 33 insertions(+), 55 deletions(-) diff --git a/lily/include/page-breaking.hh b/lily/include/page-breaking.hh index 8f1e55e5bf..082384d0fe 100644 --- a/lily/include/page-breaking.hh +++ b/lily/include/page-breaking.hh @@ -176,6 +176,5 @@ 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 0d88338935..1d96f7359f 100644 --- a/lily/page-breaking.cc +++ b/lily/page-breaking.cc @@ -53,6 +53,28 @@ 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 @@ -497,8 +519,8 @@ Page_breaking::cache_line_details (vsize configuration_index) vsize sys = next_system (current_chunks_[i]); if (system_specs_[sys].pscore_) { - vsize start = 0; - vsize end = 0; + vsize start; + vsize end; line_breaker_args (sys, current_chunks_[i], current_chunks_[i+1], &start, &end); vector details = line_breaking_[sys].line_details (start, end, div[i]); @@ -630,18 +652,11 @@ 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 ())); - - uncompress_page_spacing_results (&ret); - } + ret = space_systems_on_1_page (cached_line_details_, + page_height (first_page_num, is_last ()), + ragged () || (is_last () && ragged_last ())); else if (n == 2) - { - ret = space_systems_on_2_pages (configuration, first_page_num); - uncompress_page_spacing_results (&ret); - } + ret = space_systems_on_2_pages (configuration, first_page_num); else { Page_spacer ps (cached_line_details_, first_page_num, this); @@ -676,16 +691,9 @@ 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); - uncompress_page_spacing_results (&n_res); - } + n_res = ps.solve (n); if (n < cached_line_details_.size ()) - { - m_res = ps.solve (n+1); - uncompress_page_spacing_results (&m_res); - } - + m_res = ps.solve (n+1); } Real penalty = blank_page_penalty (); @@ -720,44 +728,14 @@ 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); - uncompress_page_spacing_results (&res); - + res.systems_per_page_ = uncompress_solution (res.systems_per_page_, cached_line_details_); + Real line_force = 0; Real line_penalty = 0; Real page_force = 0; @@ -785,6 +763,7 @@ 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