]> git.donarmstrong.com Git - lilypond.git/commitdiff
* Documentation/user/page.itely (Page formatting):
authorJoe Neeman <joeneeman@gmail.com>
Mon, 2 Oct 2006 08:17:49 +0000 (08:17 +0000)
committerJoe Neeman <joeneeman@gmail.com>
Mon, 2 Oct 2006 08:17:49 +0000 (08:17 +0000)
document auto-first-page-number

* lily/page-breaking.cc (find_chunks_and_breaks):
* lily/paper-score.cc (calc_breaking): Follow changes to the
Constrained_breaking interface

* lily/constrained-breaking.cc (calc_subproblem): run the main loop
here backwards, as an optimisation
(initialize): new function; move most of the code in resize () here
(combine_demerits): cache ragged_right_
(Constrained_breaking): constructor now takes the Paper_score

ChangeLog
Documentation/user/page.itely
lily/constrained-breaking.cc
lily/include/constrained-breaking.hh
lily/page-breaking.cc
lily/paper-score.cc

index c25ca8cd037e36281b710f0fbca0242328b45b9d..4bae29130212404de5a5824b0eb31f3d04b4fde5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2006-10-02  Joe Neeman  <joeneeman@gmail.com>
+
+       * Documentation/user/page.itely (Page formatting): 
+       document auto-first-page-number
+
+       * lily/page-breaking.cc (find_chunks_and_breaks): 
+       * lily/paper-score.cc (calc_breaking): Follow changes to the
+       Constrained_breaking interface
+
+       * lily/constrained-breaking.cc (calc_subproblem): run the main loop
+       here backwards, as an optimisation
+       (initialize): new function; move most of the code in resize () here
+       (combine_demerits): cache ragged_right_
+       (Constrained_breaking): constructor now takes the Paper_score
+
 2006-10-02  Erik Sandberg  <mandolaerik@gmail.com>
        
        * lily/lexer.ll, lily/parser.yy: Add EXPECT_NO_MORE_ARGS token, to
index 4aa6f228c25e665c9f2b3bc8786217b9ca2174d2..c40a1da91068d81959a7137987e4a0f808957a76 100644 (file)
@@ -268,6 +268,13 @@ The relative importance of page (vertical) spacing and line (horizontal)
 spacing. High values will make page spacing more important. Default
 value is 1.
 
+@funindex auto-first-page-number
+@item auto-first-page-number
+The page breaking algorithm is affected by the first page number being
+odd or even.  If this variable is set to #t, the page breaking algorithm
+will decide whether to start with an odd or even number.  This will 
+result in the first page number remaining as is or being increased by one.
+
 @end table
 @end quotation
 
index 4e5de38254a45df3b81d016d298ffc546bab97f4..b8253ac4e93ce5b0a3970393c29b991938745071 100644 (file)
@@ -76,12 +76,15 @@ Constrained_breaking::calc_subproblem (vsize start, vsize sys, vsize brk)
   vsize start_col = starting_breakpoints_[start];
   Matrix<Constrained_break_node> &st = state_[start];
   vsize max_index = brk - start_col;
-  for (vsize j=sys; j < max_index; j++)
+  for (vsize j=max_index; j-- > sys;)
     {
       if (0 == sys && j > 0)
-        break; /* the first line cannot have its first break after the beginning */
+        continue; /* the first line cannot have its first break after the beginning */
 
       Line_details const &cur = lines_.at (brk, j + start_col);
+      if (isinf (cur.force_))
+       break;
+
       Real prev_f = 0;
       Real prev_dem = 0;
 
@@ -91,14 +94,11 @@ Constrained_breaking::calc_subproblem (vsize start, vsize sys, vsize brk)
           prev_dem = st.at (j, sys-1).demerits_;
         }
       if (isinf (prev_dem))
-        break;
-
-      Real dem = combine_demerits (cur.force_, prev_f) + prev_dem + cur.break_penalty_;
-      if (isinf (dem))
         continue;
 
+      Real dem = combine_demerits (cur.force_, prev_f) + prev_dem + cur.break_penalty_;
       Constrained_break_node &n = st.at (max_index, sys);
-      if (isinf (n.demerits_) || dem < n.demerits_)
+      if (dem < n.demerits_)
         {
           found_something = true;
           n.demerits_ = dem;
@@ -140,71 +140,6 @@ Constrained_breaking::resize (vsize systems)
 {
   systems_ = systems;
 
-  if (!breaks_.size () && pscore_)
-    {
-      Output_def *l = pscore_->layout ();
-      System *sys = pscore_->root_system ();
-      Real padding = robust_scm2double (l->c_variable ("between-system-padding"), 0);
-      Real space = robust_scm2double (l->c_variable ("ideal-system-space"), 0);
-      bool ragged_right = to_boolean (pscore_->layout ()->c_variable ("ragged-right"));
-      bool ragged_last = to_boolean (pscore_->layout ()->c_variable ("ragged-last"));
-
-      Interval first_line = line_dimensions_int (pscore_->layout (), 0);
-      Interval other_lines = line_dimensions_int (pscore_->layout (), 1);
-      /* do all the rod/spring problems */
-      breaks_ = pscore_->find_break_indices ();
-      all_ = pscore_->root_system ()->columns ();
-      lines_.resize (breaks_.size (), breaks_.size (), Line_details ());
-      vector<Real> forces = get_line_forces (all_,
-                                            other_lines.length (),
-                                            other_lines.length () - first_line.length (),
-                                            ragged_right);
-      for (vsize i = 0; i < breaks_.size () - 1; i++)
-       {
-         Real max_ext = 0;
-          for (vsize j = i + 1; j < breaks_.size (); j++)
-            {
-             int start = Paper_column::get_rank (all_[breaks_[i]]);
-             int end = Paper_column::get_rank (all_[breaks_[j]]);
-             Interval extent = sys->pure_height (sys, start, end);
-             bool last = j == breaks_.size () - 1;
-             bool ragged = ragged_right || (last && ragged_last);
-             Line_details &line = lines_.at (j, i);
-
-             line.force_ = forces[i*breaks_.size () + j];
-             if (ragged && last && !isinf (line.force_))
-               line.force_ = 0;
-             if (isinf (line.force_))
-               break;
-
-             Grob *c = all_[breaks_[j]];
-             line.break_penalty_ = robust_scm2double (c->get_property ("line-break-penalty"), 0);
-             line.page_penalty_ = robust_scm2double (c->get_property ("page-break-penalty"), 0);
-             line.turn_penalty_ = robust_scm2double (c->get_property ("page-turn-penalty"), 0);
-             line.break_permission_ = c->get_property ("line-break-permission");
-             line.page_permission_ = c->get_property ("page-break-permission");
-             line.turn_permission_ = c->get_property ("page-turn-permission");
-
-             max_ext = max (max_ext, extent.length ());
-              line.extent_ = extent;
-              line.padding_ = padding;
-              line.space_ = space;
-              line.inverse_hooke_ = 1;
-            }
-       }
-
-      /* work out all the starting indices */
-      for (vsize i = 0; i < start_.size (); i++)
-        {
-          vsize j;
-          for (j = 0; j < breaks_.size () - 1 && breaks_[j] < start_[i]; j++)
-            ;
-          starting_breakpoints_.push_back (j);
-          start_[i] = breaks_[j];
-        }
-      state_.resize (start_.size ());
-    }
-
   if (pscore_ && systems_ > valid_systems_)
     {
       for (vsize i = 0; i < state_.size (); i++)
@@ -359,22 +294,97 @@ Constrained_breaking::prepare_solution (vsize start, vsize end, vsize sys_count)
   return brk;
 }
 
-Constrained_breaking::Constrained_breaking ()
+Constrained_breaking::Constrained_breaking (Paper_score *ps)
 {
   valid_systems_ = systems_ = 0;
   start_.push_back (0);
+  pscore_ = ps;
+  initialize ();
 }
 
-Constrained_breaking::Constrained_breaking (vector<vsize> const &start)
+Constrained_breaking::Constrained_breaking (Paper_score *ps, vector<vsize> const &start)
   : start_ (start)
 {
   valid_systems_ = systems_ = 0;
+  pscore_ = ps;
+  initialize ();
+}
+
+/* find the forces for all possible lines and cache ragged_ and ragged_right_ */
+void
+Constrained_breaking::initialize ()
+{
+  if (!pscore_)
+    return;
+
+  ragged_right_ = to_boolean (pscore_->layout ()->c_variable ("ragged-right"));
+  ragged_last_ = to_boolean (pscore_->layout ()->c_variable ("ragged-last"));
+      
+  Output_def *l = pscore_->layout ();
+  System *sys = pscore_->root_system ();
+  Real padding = robust_scm2double (l->c_variable ("between-system-padding"), 0);
+  Real space = robust_scm2double (l->c_variable ("ideal-system-space"), 0);
+
+  Interval first_line = line_dimensions_int (pscore_->layout (), 0);
+  Interval other_lines = line_dimensions_int (pscore_->layout (), 1);
+  /* do all the rod/spring problems */
+  breaks_ = pscore_->find_break_indices ();
+  all_ = pscore_->root_system ()->columns ();
+  lines_.resize (breaks_.size (), breaks_.size (), Line_details ());
+  vector<Real> forces = get_line_forces (all_,
+                                        other_lines.length (),
+                                        other_lines.length () - first_line.length (),
+                                        ragged_right_);
+  for (vsize i = 0; i < breaks_.size () - 1; i++)
+    {
+      Real max_ext = 0;
+      for (vsize j = i + 1; j < breaks_.size (); j++)
+       {
+         int start = Paper_column::get_rank (all_[breaks_[i]]);
+         int end = Paper_column::get_rank (all_[breaks_[j]]);
+         Interval extent = sys->pure_height (sys, start, end);
+         bool last = j == breaks_.size () - 1;
+         bool ragged = ragged_right_ || (last && ragged_last_);
+         Line_details &line = lines_.at (j, i);
+
+         line.force_ = forces[i*breaks_.size () + j];
+         if (ragged && last && !isinf (line.force_))
+           line.force_ = 0;
+         if (isinf (line.force_))
+           break;
+
+         Grob *c = all_[breaks_[j]];
+         line.break_penalty_ = robust_scm2double (c->get_property ("line-break-penalty"), 0);
+         line.page_penalty_ = robust_scm2double (c->get_property ("page-break-penalty"), 0);
+         line.turn_penalty_ = robust_scm2double (c->get_property ("page-turn-penalty"), 0);
+         line.break_permission_ = c->get_property ("line-break-permission");
+         line.page_permission_ = c->get_property ("page-break-permission");
+         line.turn_permission_ = c->get_property ("page-turn-permission");
+
+         max_ext = max (max_ext, extent.length ());
+         line.extent_ = extent;
+         line.padding_ = padding;
+         line.space_ = space;
+         line.inverse_hooke_ = 1;
+       }
+    }
+
+  /* work out all the starting indices */
+  for (vsize i = 0; i < start_.size (); i++)
+    {
+      vsize j;
+      for (j = 0; j < breaks_.size () - 1 && breaks_[j] < start_[i]; j++)
+       ;
+      starting_breakpoints_.push_back (j);
+      start_[i] = breaks_[j];
+    }
+  state_.resize (start_.size ());
 }
 
 Real
 Constrained_breaking::combine_demerits (Real force, Real prev_force)
 {
-  if (to_boolean (pscore_->layout ()->c_variable ("ragged-right")))
+  if (ragged_right_)
     return force * force;
 
   return force * force + (prev_force - force) * (prev_force - force);
index b0c1f7891d09979b8244cf8052f32b9ccb9e4141..9fe3223f988486de25fabf562969ef921c6a85aa 100644 (file)
@@ -90,12 +90,12 @@ struct Constrained_break_node
 /*
    A dynamic programming solution to breaking scores into lines
 */
-class Constrained_breaking : public Break_algorithm
+class Constrained_breaking
 {
 public:
   vector<Column_x_positions> solve ();
-  Constrained_breaking ();
-  Constrained_breaking (vector<vsize> const &start_col_posns);
+  Constrained_breaking (Paper_score *ps);
+  Constrained_breaking (Paper_score *ps, vector<vsize> const &start_col_posns);
 
   vector<Column_x_positions> get_solution (vsize start, vsize end, vsize sys_count);
   vector<Column_x_positions> get_best_solution (vsize start, vsize end);
@@ -106,8 +106,11 @@ public:
   void resize (vsize systems);
 
 private:
+  Paper_score *pscore_;
   vsize valid_systems_;
   vsize systems_;
+  bool ragged_right_;
+  bool ragged_last_;
 
   /* the (i,j)th entry is the configuration for breaking between
     columns i and j */
@@ -123,6 +126,8 @@ private:
   vector<Grob*> all_;
   vector<vsize> breaks_;
 
+  void initialize ();
+
   Column_x_positions space_line (vsize start_col, vsize end_col);
   vsize prepare_solution (vsize start, vsize end, vsize sys_count);
 
index c431c1ea25299dd4ad9d1e6d6552259a691b308a..b43c302367053bf5418ea7f77db00530f2cf2fcc 100644 (file)
@@ -277,8 +277,7 @@ Page_breaking::find_chunks_and_breaks (Break_predicate is_break)
              if ((break_point || chunk_end) && !last)
                line_breaker_columns.push_back (j);
            }
-         line_breaking_.push_back (Constrained_breaking (line_breaker_columns));
-         line_breaking_.back ().set_pscore (all_[i].pscore_);
+         line_breaking_.push_back (Constrained_breaking (all_[i].pscore_, line_breaker_columns));
        }
       else
        {
@@ -287,7 +286,7 @@ Page_breaking::find_chunks_and_breaks (Break_predicate is_break)
            breaks_.push_back (Break_position (i));
 
          chunks_.push_back (Break_position (i));
-         line_breaking_.push_back (Constrained_breaking ());
+         line_breaking_.push_back (Constrained_breaking (NULL));
        }
     }
 }
index e7a5f51247a9ac69ae1c6ffa603881255cc22c9f..028fb37a146e080a988ef63756fb50176054d3f6 100644 (file)
@@ -99,7 +99,7 @@ Paper_score::get_columns () const
 vector<Column_x_positions>
 Paper_score::calc_breaking ()
 {
-  Constrained_breaking algorithm;
+  Constrained_breaking algorithm (this);
   vector<Column_x_positions> sol;
 
   message (_ ("Calculating line breaks...") + " ");
@@ -107,11 +107,8 @@ Paper_score::calc_breaking ()
   int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0);
   if (system_count)
     algorithm.resize (system_count);
-  
-  algorithm.set_pscore (this);
-  sol = algorithm.solve ();
 
-  return sol;
+  return algorithm.solve ();
 }
 
 void