]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/page-breaking.cc
Add beam typenames to typename list.
[lilypond.git] / lily / page-breaking.cc
index bc9016ff6aef0bebdaed23bd0363f06a25777f74..d5f71297b8390f4219969660a39c348c45f6c22b 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2006--2010 Joe Neeman <joeneeman@gmail.com>
+  Copyright (C) 2006--2011 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
@@ -229,12 +229,16 @@ Page_breaking::systems_per_page () const
 int
 Page_breaking::max_systems_per_page () const
 {
+  if (systems_per_page_)
+    return systems_per_page_;
   return max_systems_per_page_;
 }
 
 int
 Page_breaking::min_systems_per_page () const
 {
+  if (systems_per_page_)
+    return systems_per_page_;
   return min_systems_per_page_;
 }
 
@@ -525,6 +529,11 @@ Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
       ret = scm_cons (page, ret);
       --page_num;
     }
+
+  // By reversing the table, we ensure that duplicated labels (eg. those
+  // straddling a page turn) will appear in the table with their last
+  // occurence first.
+  label_page_table = scm_reverse_x (label_page_table, SCM_EOL);
   book_->top_paper ()->set_variable (ly_symbol2scm ("label-page-table"), label_page_table);
   return ret;
 }
@@ -667,6 +676,7 @@ Page_breaking::chunk_list (vsize start_index, vsize end_index)
   return ret;
 }
 
+// Returns the minimum number of _non-title_ lines.
 vsize
 Page_breaking::min_system_count (vsize start, vsize end)
 {
@@ -679,6 +689,7 @@ Page_breaking::min_system_count (vsize start, vsize end)
   return ret;
 }
 
+// Returns the maximum number of _non-title_ lines.
 vsize
 Page_breaking::max_system_count (vsize start, vsize end)
 {
@@ -691,6 +702,9 @@ Page_breaking::max_system_count (vsize start, vsize end)
   return ret;
 }
 
+// The numbers returned by this function represent either
+// the maximum or minimum number of _non-title_ lines
+// per chunk.
 Page_breaking::Line_division
 Page_breaking::system_count_bounds (vector<Break_position> const &chunks,
                                    bool min)
@@ -698,7 +712,7 @@ Page_breaking::system_count_bounds (vector<Break_position> const &chunks,
   assert (chunks.size () >= 2);
 
   Line_division ret;
-  ret.resize (chunks.size () - 1, 1);
+  ret.resize (chunks.size () - 1, 0);
 
   for (vsize i = 0; i + 1 < chunks.size (); i++)
     {
@@ -798,7 +812,7 @@ Page_breaking::set_to_ideal_line_configuration (vsize start, vsize end)
          div.push_back (line_breaking_[sys].best_solution (start, end).size ());
        }
       else
-       div.push_back (1);
+       div.push_back (0);
 
       system_count_ += div.back ();
     }
@@ -835,7 +849,7 @@ Page_breaking::cache_line_details (vsize configuration_index)
            }
          else
            {
-             assert (div[i] == 1);
+             assert (div[i] == 0);
              uncompressed_line_details_.push_back (system_specs_[sys].prob_
                                                    ? Line_details (system_specs_[sys].prob_, book_->paper_)
                                                    : Line_details ());
@@ -873,7 +887,7 @@ Page_breaking::line_divisions_rec (vsize system_count,
   int real_min = max ((int) min_sys[my_index], (int) system_count - others_max);
   int real_max = min ((int) max_sys[my_index], (int) system_count - others_min);
 
-  if (real_min > real_max || real_min <= 0)
+  if (real_min > real_max || real_min < 0)
     {
       /* this should never happen within a recursive call. If it happens
         at all, it means that we were called with an unsolvable problem
@@ -957,30 +971,32 @@ Page_breaking::min_page_count (vsize configuration, vsize first_page_num)
 
   for (vsize i = 0; i < cached_line_details_.size (); i++)
     {
+      Line_details const &cur = cached_line_details_[i];
+      Line_details const *const prev = (i > 0) ? &cached_line_details_[i-1] : 0;
       Real ext_len;
       if (cur_rod_height > 0)
-       ext_len = cached_line_details_[i].tallness_;
+       ext_len = cur.tallness_;
       else
-       ext_len = cached_line_details_[i].full_height();
+       ext_len = cur.full_height();
 
+      Real spring_len = (i > 0) ? prev->spring_length (cur) : 0;
       Real next_rod_height = cur_rod_height + ext_len;
-      Real next_spring_height = cur_spring_height + cached_line_details_[i].space_;
+      Real next_spring_height = cur_spring_height + spring_len;
       Real next_height = next_rod_height + (ragged () ? next_spring_height : 0)
-       + min_whitespace_at_bottom_of_page (cached_line_details_[i]);
-      int next_line_count = line_count + cached_line_details_[i].compressed_nontitle_lines_count_;
+       + min_whitespace_at_bottom_of_page (cur);
+      int next_line_count = line_count + cur.compressed_nontitle_lines_count_;
 
       if ((!too_few_lines (line_count) && (next_height > cur_page_height && cur_rod_height > 0))
          || too_many_lines (next_line_count)
-         || (i > 0
-             && cached_line_details_[i-1].page_permission_ == ly_symbol2scm ("force")))
+         || (prev && prev->page_permission_ == ly_symbol2scm ("force")))
        {
-         line_count = cached_line_details_[i].compressed_nontitle_lines_count_;
-         cur_rod_height = cached_line_details_[i].full_height();
-         cur_spring_height = cached_line_details_[i].space_;
+         line_count = cur.compressed_nontitle_lines_count_;
+         cur_rod_height = cur.full_height();
+         cur_spring_height = 0;
          page_starter = i;
 
          cur_page_height = page_height (first_page_num + ret, false);
-         cur_page_height -= min_whitespace_at_top_of_page (cached_line_details_[i]);
+         cur_page_height -= min_whitespace_at_top_of_page (cur);
 
          ret++;
        }
@@ -1137,6 +1153,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);
 
@@ -1179,7 +1198,7 @@ Page_breaking::space_systems_with_fixed_number_per_page (vsize configuration,
       res.penalty_ += cached_line_details_[line-1].page_penalty_;
       if (system_count_on_this_page != systems_per_page_)
        {
-         res.penalty_ += TERRIBLE_SPACING_PENALTY;
+         res.penalty_ += abs (system_count_on_this_page - systems_per_page_) * TERRIBLE_SPACING_PENALTY;
          res.system_count_status_ |= ((system_count_on_this_page < systems_per_page_))
            ? SYSTEM_COUNT_TOO_FEW : SYSTEM_COUNT_TOO_MANY;
        }