]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/gourlay-breaking.cc
*** empty log message ***
[lilypond.git] / lily / gourlay-breaking.cc
index 8f7b0ec9f896776a7474519568ffa2e04b6c2353..93192d1a289ad5fc0927f108de501fac7e257e99 100644 (file)
@@ -66,7 +66,6 @@ print_break_nodes (Array<Break_node> const & arr)
   This algorithms is adapted from the OSU Tech report on breaking lines.
 
   this function is longish, but not very complicated.
   This algorithms is adapted from the OSU Tech report on breaking lines.
 
   this function is longish, but not very complicated.
-  
  */
 Array<Column_x_positions>
 Gourlay_breaking::do_solve () const
  */
 Array<Column_x_positions>
 Gourlay_breaking::do_solve () const
@@ -80,9 +79,11 @@ Gourlay_breaking::do_solve () const
   Break_node first_node ;
   optimal_paths.push (first_node);
 
   Break_node first_node ;
   optimal_paths.push (first_node);
 
+  bool ragged_right = to_boolean (pscore_->paper_->get_scmvar ("raggedright"));
+  bool ragged_last = to_boolean (pscore_->paper_->get_scmvar ("raggedlast"));
+
   Real worst_force = 0.0;
   Real worst_force = 0.0;
-  
-  for (int break_idx=1; break_idx< breaks.size (); break_idx++) 
+  for (int break_idx = 1; break_idx< breaks.size (); break_idx++) 
     {
       /*
        start with a short line, add measures. At some point 
     {
       /*
        start with a short line, add measures. At some point 
@@ -94,13 +95,11 @@ Gourlay_breaking::do_solve () const
       
       Real minimal_demerits = infinity_f;
 
       
       Real minimal_demerits = infinity_f;
 
-      bool ragged = to_boolean (pscore_->paper_->get_scmvar ("raggedright"));
-
       for (int start_idx = break_idx; start_idx--;)
        {
          Link_array<Grob> line = all.slice (breaks[start_idx], breaks[break_idx]+1);
   
       for (int start_idx = break_idx; start_idx--;)
        {
          Link_array<Grob> line = all.slice (breaks[start_idx], breaks[break_idx]+1);
   
-         line[0]     = dynamic_cast<Item*> (line[0])    ->find_prebroken_piece (RIGHT);
+         line[0]     = dynamic_cast<Item*> (line[0])->find_prebroken_piece (RIGHT);
          line.top () = dynamic_cast<Item*> (line.top ())->find_prebroken_piece (LEFT);
            
          Column_x_positions cp;
          line.top () = dynamic_cast<Item*> (line.top ())->find_prebroken_piece (LEFT);
            
          Column_x_positions cp;
@@ -109,9 +108,17 @@ Gourlay_breaking::do_solve () const
          Interval line_dims
            = pscore_->paper_->line_dimensions_int (optimal_paths[start_idx].line_);
          Simple_spacer * sp = generate_spacing_problem (line, line_dims);
          Interval line_dims
            = pscore_->paper_->line_dimensions_int (optimal_paths[start_idx].line_);
          Simple_spacer * sp = generate_spacing_problem (line, line_dims);
+         bool last_line = break_idx == breaks.size ()-1;
+         bool ragged = ragged_right
+           || (last_line && ragged_last);
+         
          sp->solve (&cp, ragged);
          sp->solve (&cp, ragged);
+         
          delete sp;
 
          delete sp;
 
+         if (ragged && last_line)
+           cp.force_ = 0.0;
+         
          if (fabs (cp.force_) > worst_force)
            worst_force = fabs (cp.force_);
 
          if (fabs (cp.force_) > worst_force)
            worst_force = fabs (cp.force_);
 
@@ -140,7 +147,7 @@ Gourlay_breaking::do_solve () const
            we couldn't satisfy the constraints, this won't get better
            if we add more columns, so we get on with the next one
          */
            we couldn't satisfy the constraints, this won't get better
            if we add more columns, so we get on with the next one
          */
-         if (!cp.satisfies_constraints_b_)
+         if (!cp.satisfies_constraints_)
            break ; 
        }
 
            break ; 
        }
 
@@ -167,7 +174,7 @@ Gourlay_breaking::do_solve () const
 
   /* do the last one */
   if (breaks.size () % HAPPY_DOTS_I)
 
   /* do the last one */
   if (breaks.size () % HAPPY_DOTS_I)
-    progress_indication (String ("[") + to_string (breaks.size()) + "]");    
+    progress_indication (String ("[") + to_string (breaks.size ()) + "]");    
 
   progress_indication ("\n");
 
 
   progress_indication ("\n");
 
@@ -197,7 +204,7 @@ Gourlay_breaking::do_solve () const
       Column_x_positions cp (optimal_paths[final_breaks[i]].line_config_);
       
       lines.push (cp);
       Column_x_positions cp (optimal_paths[final_breaks[i]].line_config_);
       
       lines.push (cp);
-      if(!cp.satisfies_constraints_b_)
+      if (!cp.satisfies_constraints_)
        warning ("Could not find line breaking that satisfies constraints.");
     }
   return lines;
        warning ("Could not find line breaking that satisfies constraints.");
     }
   return lines;
@@ -225,7 +232,7 @@ Gourlay_breaking::combine_demerits (Column_x_positions const &prev,
   Grob * pc = this_one.cols_.top ();
   if (pc->original_)
     {
   Grob * pc = this_one.cols_.top ();
   if (pc->original_)
     {
-      SCM pen = pc->get_grob_property ("penalty");
+      SCM pen = pc->get_property ("penalty");
       if (gh_number_p (pen) && fabs (gh_scm2double (pen)) < 10000)
        {
          break_penalties += gh_scm2double (pen);
       if (gh_number_p (pen) && fabs (gh_scm2double (pen)) < 10000)
        {
          break_penalties += gh_scm2double (pen);
@@ -247,7 +254,7 @@ Gourlay_breaking::combine_demerits (Column_x_positions const &prev,
   Real demerit = abs (this_one.force_) +  abs (prev.force_ - this_one.force_)
     + break_penalties;
   
   Real demerit = abs (this_one.force_) +  abs (prev.force_ - this_one.force_)
     + break_penalties;
   
-  if (!this_one.satisfies_constraints_b_)
+  if (!this_one.satisfies_constraints_)
      {
        /*
         If it doesn't satisfy constraints, we make this one
      {
        /*
         If it doesn't satisfy constraints, we make this one