]> git.donarmstrong.com Git - lilypond.git/commitdiff
When working out page breaks, take into account the fact that titles
authorJoe Neeman <joeneeman@gmail.com>
Sat, 10 Nov 2007 22:37:14 +0000 (09:37 +1100)
committerJoe Neeman <joeneeman@gmail.com>
Sun, 11 Nov 2007 00:49:26 +0000 (11:49 +1100)
ignore page-top-space.

lily/include/constrained-breaking.hh
lily/include/page-breaking.hh
lily/include/page-spacing.hh
lily/page-breaking.cc
lily/page-spacing.cc

index 9aa5862761e4a4b78c5256524696721ac369b3da..5759a12c05666f78877391c3c972a8f8464f6454 100644 (file)
@@ -31,6 +31,8 @@ struct Line_details {
   Real page_penalty_;
   Real turn_penalty_;
 
+  bool title_;
+
   Line_details ()
   {
     force_ = infinity_f;
@@ -44,6 +46,7 @@ struct Line_details {
     break_penalty_ = 0;
     page_penalty_ = 0;
     turn_penalty_ = 0;
+    title_ = false;
   }
 
   Line_details (Prob *pb)
@@ -60,6 +63,7 @@ struct Line_details {
     break_penalty_ = 0;
     page_penalty_ = robust_scm2double (pb->get_property ("page-break-penalty"), 0);
     turn_penalty_ = robust_scm2double (pb->get_property ("page-turn-penalty"), 0);
+    title_ = to_boolean (pb->get_property ("is-title"));
   }
 };
 
index 52a95812c41f9d707b4395d7cbd8c401b02f846e..18704fd36b61f68a25ee50858983078ebcc1c9c8 100644 (file)
@@ -101,6 +101,7 @@ public:
   bool ragged_last () const;
   bool is_last () const;
   Real page_height (int page_number, bool last) const;
+  Real page_top_space () const;
 
 protected:
   Paper_book *book_;
@@ -147,6 +148,7 @@ private:
   vector<Constrained_breaking> line_breaking_;
   bool ragged_;
   bool ragged_last_;
+  Real page_top_space_;
 
   vector<Line_division> current_configurations_;
   vector<Break_position> current_chunks_;
index 9bb37804a7e7aba5214e8dc6e68ae21a2381d826..fe7056c597c1fa1bcdf30a19c7b979756ef3ba16 100644 (file)
@@ -61,12 +61,15 @@ struct Page_spacing
   Real rod_height_;
   Real spring_len_;
   Real inverse_spring_k_;
+  Real page_top_space_;
 
   Line_details last_line_;
+  Line_details first_line_;
 
-  Page_spacing (Real page_height)
+  Page_spacing (Real page_height, Real page_top_space)
   {
     page_height_ = page_height;
+    page_top_space_ = page_top_space;
     clear ();
   }
 
index b6951925ad7ce7cc518b6b68f90efc225201eb78..be11ffa3eaf45790b4182c8ace501426c43e64ad 100644 (file)
@@ -36,6 +36,7 @@ compress_lines (const vector<Line_details> &orig)
          compressed.extent_[UP] = old.extent_[UP] + orig[i].extent_.length () + old.padding_;
          compressed.space_ += old.space_;
          compressed.inverse_hooke_ += old.inverse_hooke_;
+         compressed.title_ = old.title_;
 
          /* we don't need the force_ field for the vertical spacing,
             so we use force_ = n to signal that the line was compressed,
@@ -99,6 +100,7 @@ Page_breaking::Page_breaking (Paper_book *pb, Break_predicate is_break)
   book_ = pb;
   ragged_ = to_boolean (pb->paper_->c_variable ("ragged-bottom"));
   ragged_last_ = to_boolean (pb->paper_->c_variable ("ragged-last-bottom"));
+  page_top_space_ = robust_scm2double (pb->paper_->c_variable ("page-top-space"), 0);
   create_system_list ();
   find_chunks_and_breaks (is_break);
 }
@@ -119,6 +121,12 @@ Page_breaking::ragged_last () const
   return ragged_last_;
 }
 
+Real
+Page_breaking::page_top_space () const
+{
+  return page_top_space_;
+}
+
 /* translate indices into breaks_ into start-end parameters for the line breaker */
 void
 Page_breaking::line_breaker_args (vsize sys,
@@ -210,7 +218,7 @@ Page_breaking::page_height (int page_num, bool last) const
                   ly_symbol2scm ("is-last"), scm_from_bool (last),
                   SCM_UNDEFINED));
   SCM height = scm_apply_1 (calc_height, page, SCM_EOL);
-  return scm_to_double (height) - scm_to_double (book_->paper_->c_variable ("page-top-space"));
+  return scm_to_double (height) - page_top_space_;
 }
 
 SCM
@@ -765,7 +773,7 @@ Page_breaking::pack_systems_on_least_pages (vsize configuration, vsize first_pag
   Page_spacing_result res;
   vsize page = 0;
   vsize page_first_line = 0;
-  Page_spacing space (page_height (first_page_num, false));
+  Page_spacing space (page_height (first_page_num, false), page_top_space_);
 
   cache_line_details (configuration);
   for (vsize line = 0; line < cached_line_details_.size (); line++)
@@ -869,7 +877,7 @@ Page_breaking::finalize_spacing_result (vsize configuration, Page_spacing_result
 Page_spacing_result
 Page_breaking::space_systems_on_1_page (vector<Line_details> const &lines, Real page_height, bool ragged)
 {
-  Page_spacing space (page_height);
+  Page_spacing space (page_height, page_top_space_);
   Page_spacing_result ret;
 
   for (vsize i = 0; i < lines.size (); i++)
@@ -909,8 +917,8 @@ Page_breaking::space_systems_on_2_pages (vsize configuration, vsize first_page_n
 
   vector<Real> page1_force;
   vector<Real> page2_force;
-  Page_spacing page1 (page1_height);
-  Page_spacing page2 (page2_height);
+  Page_spacing page1 (page1_height, page_top_space_);
+  Page_spacing page2 (page2_height, page_top_space_);
 
   page1_force.resize (cached_line_details_.size () - 1, infinity_f);
   page2_force.resize (cached_line_details_.size () - 1, infinity_f);
index 82a037bde57c1c2f2d791c6ebe96053b2f238002..384ce440222a95cc1f5901dd0cdd54113e779eda 100644 (file)
 void
 Page_spacing::calc_force ()
 {
-  if (rod_height_ + last_line_.bottom_padding_ >= page_height_)
+  /* If the first system is a title, we add back in the page-top-space. */
+  Real height = first_line_.title_ ? page_height_ + page_top_space_ : page_height_;
+
+  if (rod_height_ + last_line_.bottom_padding_ >= height)
     force_ = infinity_f;
   else
-    force_ = (page_height_ - rod_height_ - last_line_.bottom_padding_ - spring_len_)
+    force_ = (height - rod_height_ - last_line_.bottom_padding_ - spring_len_)
       / max (0.1, inverse_spring_k_);
 }
 
@@ -33,6 +36,9 @@ Page_spacing::resize (Real new_height)
 void
 Page_spacing::append_system (const Line_details &line)
 {
+  if (!rod_height_)
+    first_line_ = line;
+
   rod_height_ += last_line_.padding_;
 
   rod_height_ += line.extent_.length ();
@@ -56,6 +62,8 @@ Page_spacing::prepend_system (const Line_details &line)
   spring_len_ += line.space_;
   inverse_spring_k_ += line.inverse_hooke_;
 
+  first_line_ = line;
+
   calc_force ();
 }
 
@@ -153,7 +161,8 @@ bool
 Page_spacer::calc_subproblem (vsize page, vsize line)
 {
   bool last = line == lines_.size () - 1;
-  Page_spacing space (breaker_->page_height (page + first_page_num_, last));
+  Page_spacing space (breaker_->page_height (page + first_page_num_, last),
+                     breaker_->page_top_space ());
   Page_spacing_node &cur = state_.at (line, page);
   bool ragged = ragged_ || (ragged_last_ && last);