]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/page-layout-problem.cc
Looser spacing for ragged-last-bottom; issue 1377
[lilypond.git] / lily / page-layout-problem.cc
index fe0058ed448a69966dd3763217ca7ee37bbc8e99..b21ee1e87367a2b063133831eaf4ab0d93efbda9 100644 (file)
@@ -385,6 +385,7 @@ Page_layout_problem::Page_layout_problem (Paper_book *pb, SCM page_scm, SCM syst
   header_padding_ = 0;
   footer_padding_ = 0;
   page_height_ = 100;
+  force_ = 0;
 
   if (page)
     {
@@ -670,16 +671,35 @@ Page_layout_problem::append_prob (Prob *prob, Spring const &spring, Real padding
   elements_.push_back (Element (prob, padding));
 }
 
+/**
+   For ragged-last pages, we usually want to stretch the page so that it
+   is not much more compressed than the previous page.  Here, if ragged is
+   true and you pass a value of fixed_force that !isinf, then I will try
+   to space this page using the given force.  If it does not fit, I will
+   resort to just filling the page (non-raggedly).
+*/
 void
-Page_layout_problem::solve_rod_spring_problem (bool ragged)
+Page_layout_problem::solve_rod_spring_problem (bool ragged, Real fixed_force)
 {
   Simple_spacer spacer;
 
   for (vsize i = 0; i < springs_.size (); ++i)
     spacer.add_spring (springs_[i]);
 
-  spacer.solve (page_height_, ragged);
+  if (ragged && !isinf (fixed_force))
+    {
+      // We need to tell the spacer it isn't ragged.  Otherwise, it will
+      // refuse to stretch.
+      spacer.solve (page_height_, false);
+
+      if (spacer.configuration_length (fixed_force) <= page_height_)
+        spacer.set_force (fixed_force);
+    }
+  else
+    spacer.solve (page_height_, ragged);
+
   solution_ = spacer.spring_positions ();
+  force_ = spacer.force ();
 
   if (!spacer.fits ())
     {
@@ -700,6 +720,12 @@ Page_layout_problem::solve_rod_spring_problem (bool ragged)
     }
 }
 
+Real
+Page_layout_problem::force () const
+{
+  return force_;
+}
+
 // The solution_ vector stores the position of every live VerticalAxisGroup
 // and every title. From that information,
 // 1) within each system, stretch the staves so they land at the right position
@@ -890,10 +916,17 @@ Page_layout_problem::distribute_loose_lines (vector<Grob *> const &loose_lines,
     }
 }
 
+SCM
+Page_layout_problem::fixed_force_solution (Real force)
+{
+  solve_rod_spring_problem (true, force);
+  return find_system_offsets ();
+}
+
 SCM
 Page_layout_problem::solution (bool ragged)
 {
-  solve_rod_spring_problem (ragged);
+  solve_rod_spring_problem (ragged, -infinity_f);
   return find_system_offsets ();
 }