]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/simple-spacer.cc
move from abe.ly
[lilypond.git] / lily / simple-spacer.cc
index aa6269be08087d869d625dd96c44a0a8b44f81c4..a44e9f8d7546d8262d7a74af30fae5226a9f82c9 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1999--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1999--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
   TODO:
   - add support for different stretch/shrink constants?
@@ -144,13 +144,7 @@ Simple_spacer::active_blocking_force () const
 Real
 Simple_spacer::active_springs_stiffness () const
 {
-  Real den = 0.0;
-  for (int i=0; i < springs_.size (); i++)
-    if (springs_[i].active_b_)
-      {
-       den += 1 / springs_[i].hooke_;
-      }
-  return 1/den;
+  return range_stiffness (0, springs_.size ());
 }
 
 void
@@ -302,13 +296,7 @@ Simple_spacer::add_columns (Link_array<Grob> const &icols)
        }
     }
 
-  /*
-    TODO: should support natural length on only the last line.
-   */
-  if (line_len_ < 0)
-    my_solve_natural_len ();
-  else
-    my_solve_linelen ();
+
 }
 
 /*
@@ -327,21 +315,22 @@ Simple_spacer::add_columns (Link_array<Grob> const &icols)
   
  */
 void
-Simple_spacer::solve (Column_x_positions *positions, bool ragged) const
+Simple_spacer::solve (Column_x_positions *positions, bool ragged) 
 {
-  positions->force_ = force_;
-  if ((force_ < 0))
-    {
-
-      /*
-       We used to have a penalty for compression, no matter what, but that
-       fucked up wtk1-fugue2 (taking 3 full pages.)
+  /*
+    TODO: should support natural length on only the last line.
+   */
+  ragged = ragged || (line_len_ < 0) ;
+  if (ragged)
+    my_solve_natural_len ();
+  else
+    my_solve_linelen ();
 
-       maybe this should be tunable?
-       */
-      if (compression_penalty_b_)
-       ; //    positions->force_ *= 2; //  hmm.
-    }
+  positions->force_ = force_;
+  /*
+    We used to have a penalty for compression, no matter what, but that
+    fucked up wtk1-fugue2 (taking 3 full pages.)
+  */
   
   positions->config_.push (indent_);
   for (int i=0; i <springs_.size (); i++)
@@ -352,12 +341,22 @@ Simple_spacer::solve (Column_x_positions *positions, bool ragged) const
        we have l>= 0 here, up to rounding errors 
       */
     }
+
+  /*
+    For raggedright, we must have a measure of music density: this is
+    to prevent lots of short lines (which all have force = 0).
+    */
+  if (ragged && line_len_ > 0)
+    {
+      Real len = positions->config_.top ();
+      positions->force_ = (line_len_ - len) *  active_springs_stiffness ();
+    }
+
+
   positions->cols_ = spaced_cols_;
   positions->loose_cols_ = loose_cols_;
-  
   positions->satisfies_constraints_b_ = (line_len_ < 0) || active_b ();
 
-
   /*
     Check if breaking constraints are met.
    */