]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/page-turn-page-breaking.cc
Web: really read search-box HTML file in UTF-8
[lilypond.git] / lily / page-turn-page-breaking.cc
index b818dc09a1cf85ad5b9f3c8408e7928cb64a700b..2641852faae7e418bfa290fc11f3209a1971f175 100644 (file)
@@ -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--2009 Joe Neeman <joeneeman@gmail.com>
 
-  (c) 2006--2007 Joe Neeman <joeneeman@gmail.com>
+  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 <http://www.gnu.org/licenses/>.
 */
 
 #include "page-turn-page-breaking.hh"
 static bool
 is_break (Grob *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)
@@ -65,14 +86,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);
     }
   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;
@@ -93,13 +114,13 @@ Page_turn_page_breaking::put_systems_on_pages (vsize start,
   return ret;
 }
 
-/* "final page" meaning the number of the final right-hand page,
-   which always has an odd page number */
+/* The number of pages taken up by a Break_node, including
+   the blank page if there is one */
 vsize
-Page_turn_page_breaking::final_page_num (Break_node const &b)
+Page_turn_page_breaking::total_page_count (Break_node const &b)
 {
   vsize end = b.first_page_number_ + b.page_count_;
-  return end - 1 + (end % 2);
+  return end - 1 + (end % 2) - b.first_page_number_;
 }
 
 extern bool debug_page_breaking_scoring;
@@ -160,7 +181,7 @@ Page_turn_page_breaking::calc_subproblem (vsize ending_breakpoint)
               if (isinf (cur.demerits_)
                  || (cur.page_count_  + (p_num % 2) > 2
                      && (!isinf (this_start_best.demerits_))
-                     && final_page_num (cur) > final_page_num (this_start_best)))
+                     && total_page_count (cur) > total_page_count (this_start_best)))
                 {
                   ok_page = false;
                   break;