]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/page-breaking.cc
Fix 1460.
[lilypond.git] / lily / page-breaking.cc
index 22fe336da513e5c49cb969cd86bb67b5e4185f9a..3272e02eefbb3471efab3be5e04a8ed28a11683f 100644 (file)
@@ -343,9 +343,8 @@ Page_breaking::systems ()
            ->get_broken_system_grobs ();
          ret = scm_cons (lines, ret);
        }
-      else
+      else if (Prob *pb = system_specs_[sys].prob_)
        {
-         Prob *pb = system_specs_[sys].prob_;
          ret = scm_cons (scm_list_1 (pb->self_scm ()), ret);
          pb->unprotect ();
        }
@@ -465,6 +464,9 @@ Page_breaking::draw_page (SCM systems, SCM configuration, int page_num, bool las
 SCM
 Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
 {
+  if (scm_is_null (systems))
+    return SCM_EOL;
+
   int first_page_number
     = robust_scm2int (book_->paper_->c_variable ("first-page-number"), 1);
   SCM ret = SCM_EOL;
@@ -554,6 +556,8 @@ Page_breaking::create_system_list ()
           system_specs_.push_back (System_spec (pb));
         }
     }
+  if (!system_specs_.size ())
+    system_specs_.push_back (System_spec ());
 }
 
 void
@@ -630,7 +634,7 @@ Page_breaking::find_chunks_and_breaks (Break_predicate is_break, Prob_break_pred
            }
          line_breaking_.push_back (Constrained_breaking (system_specs_[i].pscore_, line_breaker_columns));
        }
-      else
+      else if (system_specs_[i].prob_)
        {
          bool break_point = prob_is_break && prob_is_break (system_specs_[i].prob_);
          if (break_point || i == system_specs_.size () - 1)
@@ -832,7 +836,9 @@ Page_breaking::cache_line_details (vsize configuration_index)
          else
            {
              assert (div[i] == 1);
-             uncompressed_line_details_.push_back (Line_details (system_specs_[sys].prob_, book_->paper_));
+             uncompressed_line_details_.push_back (system_specs_[sys].prob_
+                                                   ? Line_details (system_specs_[sys].prob_, book_->paper_)
+                                                   : Line_details ());
            }
        }
       cached_line_details_ = compress_lines (uncompressed_line_details_);
@@ -999,18 +1005,21 @@ Page_breaking::min_page_count (vsize configuration, vsize first_page_num)
      calculations that treated it as a non-last page were ok.
   */
 
-  cur_page_height = page_height (first_page_num + ret - 1, true);
-  cur_page_height -= min_whitespace_at_top_of_page (cached_line_details_[page_starter]);
-  cur_page_height -= min_whitespace_at_bottom_of_page (cached_line_details_.back ());
-
-  Real cur_height = cur_rod_height + ((ragged_last () || ragged ()) ? cur_spring_height : 0);
-  if (!too_few_lines (line_count - cached_line_details_.back ().compressed_nontitle_lines_count_)
-      && cur_height > cur_page_height
-      /* don't increase the page count if the last page had only one system */
-      && cur_rod_height > cached_line_details_.back ().full_height ())
-    ret++;
+  if (is_last ())
+    {
+      cur_page_height = page_height (first_page_num + ret - 1, true);
+      cur_page_height -= min_whitespace_at_top_of_page (cached_line_details_[page_starter]);
+      cur_page_height -= min_whitespace_at_bottom_of_page (cached_line_details_.back ());
+
+      Real cur_height = cur_rod_height + ((ragged_last () || ragged ()) ? cur_spring_height : 0);
+      if (!too_few_lines (line_count - cached_line_details_.back ().compressed_nontitle_lines_count_)
+         && cur_height > cur_page_height
+         /* don't increase the page count if the last page had only one system */
+         && cur_rod_height > cached_line_details_.back ().full_height ())
+       ret++;
+      assert (ret <= cached_line_details_.size ());
+    }
 
-  assert (ret <= cached_line_details_.size ());
   return ret;
 }
 
@@ -1128,6 +1137,9 @@ Page_breaking::space_systems_on_n_or_one_more_pages (vsize configuration, vsize
 Page_spacing_result
 Page_breaking::space_systems_on_best_pages (vsize configuration, vsize first_page_num)
 {
+  if (systems_per_page_ > 0)
+    return space_systems_with_fixed_number_per_page (configuration, first_page_num);
+
   cache_line_details (configuration);
   Page_spacer ps (cached_line_details_, first_page_num, this);