]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/page-spacing.cc
Merge with master
[lilypond.git] / lily / page-spacing.cc
index dd468e7ea9f337ecaff30d366f8aa176a8377b42..2ebd53814e3927c3a8120b23befe94847561c3f3 100644 (file)
@@ -4,7 +4,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2006 Joe Neeman <joeneeman@gmail.com>
+  (c) 2006--2007 Joe Neeman <joeneeman@gmail.com>
 */
 
 #include "page-spacing.hh"
@@ -91,26 +91,26 @@ compress_lines (const vector<Line_details> &orig)
 
   for (vsize i = 0; i < orig.size (); i++)
     {
-      if (i < orig.size () - 1 && orig[i].page_permission_ == SCM_EOL)
+      if (ret.size () && ret.back ().page_permission_ == SCM_EOL)
        {
-         Line_details compressed = orig[i+1];
-         compressed.extent_[DOWN] = orig[i].extent_[DOWN];
-         compressed.extent_[UP] = orig[i].extent_[UP] + orig[i+1].extent_.length () + orig[i].padding_;
-         compressed.space_ += orig[i].space_;
-         compressed.inverse_hooke_ += orig[i].inverse_hooke_;
+         Line_details const &old = ret.back ();
+         Line_details compressed = orig[i];
+         compressed.extent_[DOWN] = old.extent_[DOWN];
+         compressed.extent_[UP] = old.extent_[UP] + orig[i].extent_.length () + old.padding_;
+         compressed.space_ += old.space_;
+         compressed.inverse_hooke_ += old.inverse_hooke_;
 
          /* we don't need the force_ field for the vertical spacing,
-            so we use force_ = -1 to signal that the line was compressed
-            (and force_ = +1 otherwise).
+            so we use force_ = n to signal that the line was compressed,
+            reducing the number of lines by n (and force_ = 0 otherwise).
             This makes uncompression much easier. */
-         compressed.force_ = -1;
-         ret.push_back (compressed);
-         i++;
+         compressed.force_ = old.force_ + 1;
+         ret.back () = compressed;
        }
       else
        {
          ret.push_back (orig[i]);
-         ret.back ().force_ = 1;
+         ret.back ().force_ = 0;
        }
     }
   return ret;
@@ -130,8 +130,7 @@ uncompress_solution (vector<vsize> const &systems_per_page,
     {
       int compressed_count = 0;
       for (vsize j = start_sys; j < start_sys + systems_per_page[i]; j++)
-       if (compressed[j].force_ < 0)
-         compressed_count++;
+       compressed_count += (int)compressed[j].force_;
 
       ret.push_back (systems_per_page[i] + compressed_count);
       start_sys += systems_per_page[i];
@@ -165,7 +164,7 @@ space_systems_on_2_pages (vector<Line_details> const &lines,
                          bool ragged_last)
 {
   /* if there is a forced break, this reduces to 2 1-page problems */
-  for (vsize i = 0; i < lines.size () - 1; i++)
+  for (vsize i = 0; i + 1 < lines.size (); i++)
     if (lines[i].page_permission_ == ly_symbol2scm ("force"))
       {
        vector<Line_details> lines1 (lines.begin (), lines.begin () + i + 1);
@@ -196,7 +195,7 @@ space_systems_on_2_pages (vector<Line_details> const &lines,
 
       if (ragged || ragged_last)
        page2_force[page2_force.size () - 1 - i] =
-         (page2.force_ < 0 && i < page1_force.size () - 1) ? infinity_f : 0;
+         (page2.force_ < 0 && i + 1 < page1_force.size ()) ? infinity_f : 0;
       else
        page2_force[page2_force.size () - 1 - i] = page2.force_;
     }
@@ -359,7 +358,7 @@ min_page_count (vector<Line_details> const &uncompressed_lines,
        + ((cur_rod_height > 0) ? lines[i].padding_: 0);
 
       if ((next_height > page_height && cur_rod_height > 0)
-         || (i < lines.size () - 1 && lines[i].page_permission_ == ly_symbol2scm ("force")))
+         || (i + 1 < lines.size () && lines[i].page_permission_ == ly_symbol2scm ("force")))
        {
          ret++;
          cur_rod_height = ext_len + (rag ? lines[i].space_ : 0);