]> git.donarmstrong.com Git - lilypond.git/commitdiff
Looser spacing for ragged-last-bottom; issue 1377
authorKeith OHara <k-ohara5a5a@oco.net>
Tue, 13 Dec 2011 05:56:57 +0000 (21:56 -0800)
committerKeith OHara <k-ohara5a5a@oco.net>
Mon, 19 Dec 2011 05:34:07 +0000 (21:34 -0800)
Under ragged-last-bottom, try to make the last page match the
previous page by using the same 'force' for spacing it.

lily/include/page-layout-problem.hh
lily/include/simple-spacer.hh
lily/page-breaking.cc
lily/page-layout-problem.cc
lily/simple-spacer.cc

index c0577b9ab072b37e4d1a9a996d9415d92b2d9c0c..9f879558dc2cc2697bb6f6b6a9a1ad62a2b96383 100644 (file)
@@ -29,8 +29,10 @@ public:
   Page_layout_problem (Paper_book *, SCM page, SCM systems);
 
   SCM solution (bool ragged);
+  SCM fixed_force_solution (Real force);
   void set_header_height (Real);
   void set_footer_height (Real);
+  Real force () const;
   static bool read_spacing_spec (SCM spec, Real *dest, SCM sym);
   static bool is_spaceable (Grob *g);
   static SCM get_details (Grob *g);
@@ -47,7 +49,7 @@ protected:
   void append_system (System *, Spring const &, Real indent, Real padding);
   void append_prob (Prob *, Spring const &, Real padding);
 
-  void solve_rod_spring_problem (bool ragged);
+  void solve_rod_spring_problem (bool ragged, Real fixed_force);
   SCM find_system_offsets ();
   void distribute_loose_lines (vector<Grob *> const &, vector<Real> const &, Real, Real);
 
@@ -91,6 +93,7 @@ protected:
   vector<Spring> springs_;
   vector<Element> elements_;
   vector<Real> solution_;
+  Real force_;
   Skyline bottom_skyline_;
   Real page_height_;
   Real header_height_;
index b5aeeb200d9e28f02a17eafa2d43dbcede37779c..9aa6e8bdcd8e0c7051ab89ef715100e207eddc9c 100644 (file)
@@ -40,6 +40,7 @@ public:
   Real configuration_length (Real) const;
   vector<Real> spring_positions () const;
 
+  void set_force (Real force);
   Real force () const;
   Real line_len () const;
   Real force_penalty (bool ragged) const;
index 01d7469f52ed80ff45a1f9e5c102e1b262076ca3..36ef0a13726d621f9888cd14e854ea5260bd945e 100644 (file)
@@ -601,7 +601,8 @@ Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
   if (label_page_table == SCM_UNDEFINED)
     label_page_table = SCM_EOL;
 
-  // Build a list of (systems . configuration) pairs. Note that we lay out
+  // Build a list of (systems configuration . footnote-count) triples.
+  // Note that we lay out
   // the staves and find the configurations before drawing anything. Some
   // grobs (like tuplet brackets) look at their neighbours while drawing
   // themselves. If this happens before the neighbouring staves have
@@ -609,6 +610,7 @@ Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
   // Align_interface::align_to_ideal_distances might be called).
   SCM systems_configs_fncounts = SCM_EOL;
   vsize footnote_count = 0;
+  Real last_page_force = 0;
 
   for (vsize i = 0; i < lines_per_page.size (); i++)
     {
@@ -620,7 +622,19 @@ Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
       int fn_lines = Page_layout_problem::get_footnote_count (lines);
       Page_layout_problem::add_footnotes_to_lines (lines, reset_footnotes_on_new_page ? 0 : footnote_count, book_);
 
-      SCM config = get_page_configuration (lines, page_num, rag, bookpart_last_page);
+      SCM config = SCM_EOL;
+      SCM dummy_page = make_page (page_num, bookpart_last_page);
+      Page_layout_problem layout (book_, dummy_page, lines);
+      if (!scm_is_pair (systems))
+        config = SCM_EOL;
+      else if (rag && !ragged ())
+        // If we're ragged-last but not ragged, make the last page
+        // have the same force as the previous page.
+        config = layout.fixed_force_solution (last_page_force);
+      else
+        config = layout.solution (rag);
+
+      last_page_force = layout.force ();
 
       systems_configs_fncounts = scm_cons (scm_cons (lines, config), systems_configs_fncounts);
       footnote_count += fn_lines;
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 ();
 }
 
index a870ee3dcc98df502de70532b3f0c752fbc4dd36..c6b3c06f5d3a710fdb2c875aa6e27f8aaaf33ed6 100644 (file)
@@ -167,6 +167,12 @@ Simple_spacer::configuration_length (Real force) const
   return l;
 }
 
+void
+Simple_spacer::set_force (Real force)
+{
+  force_ = force;
+}
+
 void
 Simple_spacer::solve (Real line_len, bool ragged)
 {