]> git.donarmstrong.com Git - lilypond.git/commitdiff
Add more robustness when the requested number of pages is too small.
authorJoe Neeman <joeneeman@gmail.com>
Sat, 17 Nov 2007 21:47:03 +0000 (08:47 +1100)
committerJoe Neeman <joeneeman@gmail.com>
Sat, 17 Nov 2007 22:59:37 +0000 (09:59 +1100)
input/regression/page-breaking-page-count2.ly
input/regression/page-breaking-page-count3.ly [new file with mode: 0644]
lily/optimal-page-breaking.cc
lily/page-breaking.cc

index 645243a0fec835713c857899b6dc57acdc1ea0f7..c7e01a3517b4ccd62325f260aed6f12de3a5687b 100644 (file)
@@ -2,7 +2,8 @@
 
 \header {
   texidoc = "The number of pages in a score can be forced by setting
-@code{page-count} in the (book-level) paper block."
+@code{page-count} in the (book-level) paper block. If there are too
+few systems for the number of pages, we append blank pages."
 }
 
 #(set-default-paper-size "a6")
diff --git a/input/regression/page-breaking-page-count3.ly b/input/regression/page-breaking-page-count3.ly
new file mode 100644 (file)
index 0000000..5f5b8b6
--- /dev/null
@@ -0,0 +1,14 @@
+\version "2.11.34"
+
+\header {
+  texidoc = "The number of pages in a score can be forced by setting
+@code{page-count} in the (book-level) paper block. Even if there are
+too many systems for that number of pages, we will squeeze them in."
+}
+
+#(set-default-paper-size "a6")
+
+\book {
+  \paper { page-count = 1}
+  \score { { \repeat unfold 10 {c'1 \break} } }
+}
\ No newline at end of file
index 4aa8bececc6ea328384e9bcb5462aef6b33ea381..fa1e72b31ac4ea3cc3ee14841a12450734f58753 100644 (file)
@@ -45,8 +45,8 @@ Optimal_page_breaking::solve ()
 
   Page_spacing_result best;
   vsize page_count = robust_scm2int (forced_page_count, 1);
-  Line_division ideal_line_division;
-  Line_division best_division;
+  Line_division ideal_line_division = current_configuration (0);
+  Line_division best_division = ideal_line_division;
   vsize min_sys_count = 1;
   vsize ideal_sys_count = system_count ();
   
@@ -57,8 +57,6 @@ Optimal_page_breaking::solve ()
   
       best = space_systems_on_best_pages (0, first_page_num);
       page_count = best.systems_per_page_.size ();
-      ideal_line_division = current_configuration (0);
-      best_division = ideal_line_division;
 
       ideal_sys_count = best.system_count ();
       min_sys_count = ideal_sys_count - best.systems_per_page_.back ();
@@ -66,6 +64,8 @@ Optimal_page_breaking::solve ()
       if (page_count > 1 && best.systems_per_page_[page_count - 2] > 1)
        min_sys_count -= best.systems_per_page_[page_count - 2];
     }
+  else
+    best = space_systems_on_n_pages (0, page_count, first_page_num);
 
   if (page_count == 1)
     message (_ ("Fitting music on 1 page..."));
@@ -86,9 +86,7 @@ Optimal_page_breaking::solve ()
          vsize min_p_count = min_page_count (i, first_page_num);
          Page_spacing_result cur;
 
-         if (min_p_count > page_count)
-           continue;
-         else if (min_p_count == page_count)
+         if (min_p_count == page_count)
            cur = space_systems_on_n_pages (i, page_count, first_page_num);
          else
            cur = space_systems_on_n_or_one_more_pages (i, page_count-1, first_page_num);
index 46e0caf90c1248c4f211c8c218e5905606e1acab..d3a2762bbb350285dd3d00141976c9c235e793e8 100644 (file)
@@ -687,15 +687,19 @@ Page_spacing_result
 Page_breaking::space_systems_on_n_pages (vsize configuration, vsize n, vsize first_page_num)
 {
   Page_spacing_result ret;
-  assert (n >= min_page_count (configuration, first_page_num));
 
   cache_line_details (configuration);
+  bool valid_n = (n >= min_page_count (configuration, first_page_num)
+                 && n <= cached_line_details_.size ());
 
-  if (n == 1 && n <= cached_line_details_.size ())
+  if (!valid_n)
+    programming_error ("number of pages is out of bounds");
+
+  if (n == 1 && valid_n)
     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 && n <= cached_line_details_.size ())
+  else if (n == 2 && valid_n)
     ret = space_systems_on_2_pages (configuration, first_page_num);
   else
     {
@@ -721,8 +725,12 @@ Page_breaking::space_systems_on_n_or_one_more_pages (vsize configuration, vsize
 
   cache_line_details (configuration);
   vsize min_p_count = min_page_count (configuration, first_page_num);
+  bool valid_n = n >= min_p_count || n <= cached_line_details_.size ();
+
+  if (!valid_n)
+    programming_error ("both page counts are out of bounds");
 
-  if (n == 1)
+  if (n == 1 && valid_n)
     {
       bool rag = ragged () || (is_last () && ragged_last ());
       Real height = page_height (first_page_num, is_last ());
@@ -736,9 +744,9 @@ Page_breaking::space_systems_on_n_or_one_more_pages (vsize configuration, vsize
     {
       Page_spacer ps (cached_line_details_, first_page_num, this);
       
-      if (n >= min_p_count)
+      if (n >= min_p_count || !valid_n)
        n_res = ps.solve (n);
-      if (n < cached_line_details_.size ())
+      if (n < cached_line_details_.size () || !valid_n)
        m_res = ps.solve (n+1);
     }