X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpage-turn-page-breaking.cc;h=09545020c482ca4277de5b888e96c6f31f1df3bc;hb=a6a51abfd0195a3cf7d6ea095cf69808852f21ce;hp=75e1a3bbf28204e5d6a52e36fba7a793d27ec020;hpb=7ce72b4325ac54d7f26770430d9bd632cb9cdb29;p=lilypond.git diff --git a/lily/page-turn-page-breaking.cc b/lily/page-turn-page-breaking.cc index 75e1a3bbf2..09545020c4 100644 --- a/lily/page-turn-page-breaking.cc +++ b/lily/page-turn-page-breaking.cc @@ -1,9 +1,20 @@ /* - page-turn-page-breaking.cc -- implement Page_turn_page_breaking + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2006--2015 Joe Neeman - (c) 2006--2007 Joe Neeman + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "page-turn-page-breaking.hh" @@ -18,14 +29,25 @@ #include "system.hh" #include "warn.hh" +template static bool -is_break (Grob *g) +is_break (T *g) { - return scm_is_symbol (g->get_property ("page-turn-permission")); + bool turnable = scm_is_symbol (g->get_property ("page-turn-permission")); + + if (turnable + && (!scm_is_symbol (g->get_property ("page-break-permission")) + || !scm_is_symbol (g->get_property ("line-break-permission")))) + { + programming_error ("found a page-turnable place which was not breakable"); + turnable = false; + } + + return turnable; } Page_turn_page_breaking::Page_turn_page_breaking (Paper_book *pb) - : Page_breaking (pb, is_break) + : Page_breaking (pb, is_break, is_break) { } @@ -35,9 +57,9 @@ Page_turn_page_breaking::~Page_turn_page_breaking () Page_turn_page_breaking::Break_node Page_turn_page_breaking::put_systems_on_pages (vsize start, - vsize end, - vsize configuration, - vsize page_number) + vsize end, + vsize configuration, + vsize page_number) { vsize min_p_count = min_page_count (configuration, page_number); bool auto_first = to_boolean (book_->paper_->c_variable ("auto-first-page-number")); @@ -65,14 +87,14 @@ Page_turn_page_breaking::put_systems_on_pages (vsize start, if (start == 0 && auto_first) { if (min_p_count % 2) - result = space_systems_on_n_or_one_more_pages (configuration, min_p_count, page_number); + result = space_systems_on_n_or_one_more_pages (configuration, min_p_count, page_number, 0); else - result = space_systems_on_n_pages (configuration, min_p_count, page_number); + result = space_systems_on_n_pages (configuration, min_p_count, page_number); } else if (page_number % 2 == min_p_count % 2) result = space_systems_on_n_pages (configuration, min_p_count, page_number); else - result = space_systems_on_n_or_one_more_pages (configuration, min_p_count, page_number); + result = space_systems_on_n_or_one_more_pages (configuration, min_p_count, page_number, blank_page_penalty ()); Break_node ret; ret.prev_ = start - 1; @@ -88,7 +110,7 @@ Page_turn_page_breaking::put_systems_on_pages (vsize start, ret.too_many_lines_ = all_lines_stretched (configuration); ret.demerits_ = result.demerits_; if (start > 0) - ret.demerits_ += state_[start-1].demerits_; + ret.demerits_ += state_[start - 1].demerits_; return ret; } @@ -115,22 +137,23 @@ Page_turn_page_breaking::calc_subproblem (vsize ending_breakpoint) for (vsize start = end; start--;) { - if (start < end-1 - && breakpoint_property (start+1, "page-turn-permission") == ly_symbol2scm ("force")) - break; + if (start < end - 1 + && scm_is_eq (breakpoint_property (start + 1, "page-turn-permission"), + ly_symbol2scm ("force"))) + break; - if (start > 0 && best.demerits_ < state_[start-1].demerits_) + if (start > 0 && best.demerits_ < state_[start - 1].demerits_) continue; int p_num = robust_scm2int (book_->paper_->c_variable ("first-page-number"), 1); if (start > 0) { - /* except possibly for the first page, enforce the fact that first_page_number_ - should always be even (left hand page). - TODO: are there different conventions in right-to-left languages? - */ - p_num = state_[start-1].first_page_number_ + state_[start-1].page_count_; - p_num += p_num % 2; + /* except possibly for the first page, enforce the fact that first_page_number_ + should always be even (left hand page). + TODO: are there different conventions in right-to-left languages? + */ + p_num = state_[start - 1].first_page_number_ + state_[start - 1].page_count_; + p_num += p_num % 2; } Line_division min_division; @@ -143,14 +166,14 @@ Page_turn_page_breaking::calc_subproblem (vsize ending_breakpoint) bool ok_page = true; if (debug_page_breaking_scoring) - message (_f ("page-turn-page-breaking: breaking from %d to %d", (int) start, (int) end)); + message (_f ("page-turn-page-breaking: breaking from %d to %d", (int) start, (int) end)); /* heuristic: we've just added a breakpoint, we'll need at least as many systems as before */ min_sys_count = max (min_sys_count, prev_best_system_count); for (vsize sys_count = min_sys_count; sys_count <= max_sys_count && ok_page; sys_count++) { - set_current_breakpoints (start, end, sys_count, min_division, max_division); + set_current_breakpoints (start, end, sys_count, min_division, max_division); bool found = false; for (vsize i = 0; i < current_configuration_count (); i++) @@ -158,9 +181,9 @@ Page_turn_page_breaking::calc_subproblem (vsize ending_breakpoint) cur = put_systems_on_pages (start, end, i, p_num); if (isinf (cur.demerits_) - || (cur.page_count_ + (p_num % 2) > 2 - && (!isinf (this_start_best.demerits_)) - && total_page_count (cur) > total_page_count (this_start_best))) + || (cur.page_count_ + (p_num % 2) > 2 + && (!isinf (this_start_best.demerits_)) + && total_page_count (cur) > total_page_count (this_start_best))) { ok_page = false; break; @@ -168,16 +191,16 @@ Page_turn_page_breaking::calc_subproblem (vsize ending_breakpoint) if (cur.demerits_ < this_start_best.demerits_) { - if (debug_page_breaking_scoring) - print_break_node (cur); + if (debug_page_breaking_scoring) + print_break_node (cur); found = true; this_start_best = cur; prev_best_system_count = sys_count; - /* heuristic: if we increase the number of systems, we can bound the - division from below by our current best division */ - min_division = current_configuration (i); + /* heuristic: if we increase the number of systems, we can bound the + division from below by our current best division */ + min_division = current_configuration (i); } } if (!found && this_start_best.too_many_lines_) @@ -190,13 +213,13 @@ Page_turn_page_breaking::calc_subproblem (vsize ending_breakpoint) } if (start == 0 && end == 1 - && this_start_best.first_page_number_ == 1 - && this_start_best.page_count_ > 1) - warning (_ ("cannot fit the first page turn onto a single page. " - "Consider setting first-page-number to an even number.")); + && this_start_best.first_page_number_ == 1 + && this_start_best.page_count_ > 1) + warning (_ ("cannot fit the first page turn onto a single page." + " Consider setting first-page-number to an even number.")); if (this_start_best.demerits_ < best.demerits_) - best = this_start_best; + best = this_start_best; } state_.push_back (best); } @@ -210,7 +233,7 @@ Page_turn_page_breaking::solve () for (vsize i = 0; i < last_break_position (); i++) { calc_subproblem (i); - progress_indication (string ("[") + to_string (i + 1) + "]"); + progress_indication (string ("[") + ::to_string (i + 1) + "]"); } progress_indication ("\n"); @@ -235,7 +258,7 @@ Page_turn_page_breaking::make_lines (vector *psoln) vector &soln = *psoln; for (vsize n = 0; n < soln.size (); n++) { - vsize start = n > 0 ? soln[n-1].break_pos_ : 0; + vsize start = n > 0 ? soln[n - 1].break_pos_ : 0; vsize end = soln[n].break_pos_; break_into_pieces (start, end, soln[n].div_); @@ -247,21 +270,24 @@ Page_turn_page_breaking::make_lines (vector *psoln) SCM Page_turn_page_breaking::make_pages (vector const &soln, SCM systems) { + if (scm_is_null (systems)) + return SCM_EOL; + vector lines_per_page; for (vsize i = 0; i < soln.size (); i++) { for (vsize j = 0; j < soln[i].page_count_; j++) - lines_per_page.push_back (soln[i].system_count_[j]); + lines_per_page.push_back (soln[i].system_count_[j]); if (i + 1 < soln.size () && (soln[i].first_page_number_ + soln[i].page_count_) % 2) - /* add a blank page */ - lines_per_page.push_back (0); + /* add a blank page */ + lines_per_page.push_back (0); } /* this should only actually modify first-page-number if auto-first-page-number was true. */ book_->paper_->set_variable (ly_symbol2scm ("first-page-number"), - scm_from_int (soln[0].first_page_number_)); + scm_from_int (soln[0].first_page_number_)); return Page_breaking::make_pages (lines_per_page, systems); }