]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/constrained-breaking.cc
Fix 1112.
[lilypond.git] / lily / constrained-breaking.cc
index 2fead2460d504499cd5bfa89763a2d01ad313b07..0779c133a1d807e73ad3a3485ce0165f4cfb39b1 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2006--2009 Joe Neeman <joeneeman@gmail.com>
+  Copyright (C) 2006--2010 Joe Neeman <joeneeman@gmail.com>
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -383,30 +383,51 @@ Constrained_breaking::initialize ()
   /* NOTE: currently, we aren't using the space_ field of a
      Line_details for anything.  That's because the approximations
      used for scoring a page configuration don't actually space things
-     properly (for speed reasong) using springs anchored at the staff
+     properly (for speed reasons) using springs anchored at the staff
      refpoints.  Rather, the "space" is placed between the extent
      boxes.  To get a good result, therefore, the "space" value for
      page breaking needs to be much smaller than the "space" value for
-     page layout.  Currently, we just make it zero always.
+     page layout.  Currently, we just make it zero always, which means
+     that we will always prefer a tighter vertical layout.
   */
   between_system_space_ = 0;
   between_system_padding_ = 0;
+  between_system_min_distance_ = 0;
+  between_scores_system_padding_ = 0;
+  between_scores_system_min_distance_ = 0;
   before_title_padding_ = 0;
+  before_title_min_distance_ = 0;
 
   Output_def *l = pscore_->layout ();
 
   SCM spacing_spec = l->c_variable ("between-system-spacing");
+  SCM between_scores_spec = l->c_variable ("between-scores-system-spacing");
   SCM title_spec = l->c_variable ("before-title-spacing");
   SCM page_breaking_spacing_spec = l->c_variable ("page-breaking-between-system-spacing");
   Page_layout_problem::read_spacing_spec (spacing_spec,
                                          &between_system_padding_,
                                          ly_symbol2scm ("padding"));
+  Page_layout_problem::read_spacing_spec (between_scores_spec,
+                                         &between_scores_system_padding_,
+                                         ly_symbol2scm ("padding"));
   Page_layout_problem::read_spacing_spec (page_breaking_spacing_spec,
                                          &between_system_padding_,
                                          ly_symbol2scm ("padding"));
   Page_layout_problem::read_spacing_spec (title_spec,
                                          &before_title_padding_,
                                          ly_symbol2scm ("padding"));
+  Page_layout_problem::read_spacing_spec (between_scores_spec,
+                                         &between_scores_system_min_distance_,
+                                         ly_symbol2scm ("minimum-distance"));
+  Page_layout_problem::read_spacing_spec (spacing_spec,
+                                         &between_system_min_distance_,
+                                         ly_symbol2scm ("minimum-distance"));
+  Page_layout_problem::read_spacing_spec (page_breaking_spacing_spec,
+                                         &between_system_min_distance_,
+                                         ly_symbol2scm ("minimum-distance"));
+  Page_layout_problem::read_spacing_spec (title_spec,
+                                         &before_title_min_distance_,
+                                         ly_symbol2scm ("minimum-distance"));
 
   Interval first_line = line_dimensions_int (pscore_->layout (), 0);
   Interval other_lines = line_dimensions_int (pscore_->layout (), 1);
@@ -458,7 +479,9 @@ Constrained_breaking::fill_line_details (Line_details *const out, vsize start, v
   int start_rank = Paper_column::get_rank (all_[breaks_[start]]);
   int end_rank = Paper_column::get_rank (all_[breaks_[end]]);
   System *sys = pscore_->root_system ();
-  Interval extent = sys->pure_height (sys, start_rank, end_rank);
+  Interval begin_of_line_extent = sys->begin_of_line_pure_height (start_rank, end_rank);
+  Interval rest_of_line_extent = sys->rest_of_line_pure_height (start_rank, end_rank);
+  bool last = (end == breaks_.size () - 1);
 
   Grob *c = all_[breaks_[end]];
   out->last_column_ = c;
@@ -476,20 +499,21 @@ Constrained_breaking::fill_line_details (Line_details *const out, vsize start, v
   out->turn_permission_ = min_permission (out->page_permission_,
                                          out->turn_permission_);
 
-  // TODO: see the hack regarding begin_of_line and
-  // rest_of_line extents in align-interface.  Perhaps we
-  // should do the same thing here so that the effect extends
-  // between systems as well as within systems.  It isn't as
-  // crucial here, however, because the effect is largest when
-  // dealing with large systems.
-  out->extent_ = (extent.is_empty ()
-                 || isnan (extent[LEFT])
-                 || isnan (extent[RIGHT]))
-    ? Interval (0, 0) : extent;
-  out->padding_ = between_system_padding_;
+  begin_of_line_extent = (begin_of_line_extent.is_empty ()
+                         || isnan (begin_of_line_extent[LEFT])
+                         || isnan (begin_of_line_extent[RIGHT]))
+    ? Interval (0, 0) : begin_of_line_extent;
+  rest_of_line_extent = (rest_of_line_extent.is_empty ()
+                        || isnan (rest_of_line_extent[LEFT])
+                        || isnan (rest_of_line_extent[RIGHT]))
+    ? Interval (0, 0) : rest_of_line_extent;
+  out->shape_ = Line_shape (begin_of_line_extent, rest_of_line_extent);
+  out->padding_ = last ? between_scores_system_padding_ : between_system_padding_;
   out->title_padding_ = before_title_padding_;
+  out->min_distance_ = last ? between_scores_system_min_distance_ : between_system_min_distance_;
+  out->title_min_distance_ = before_title_min_distance_;
   out->space_ = between_system_space_;
-  out->inverse_hooke_ = extent.length () + between_system_space_;
+  out->inverse_hooke_ = out->full_height () + between_system_space_;
 }
 
 Real
@@ -509,12 +533,16 @@ Line_details::Line_details (Prob *pb, Output_def *paper)
   title_padding_ = 0;
   Page_layout_problem::read_spacing_spec (spec, &padding_, ly_symbol2scm ("padding"));
   Page_layout_problem::read_spacing_spec (title_spec, &title_padding_, ly_symbol2scm ("padding"));
+  Page_layout_problem::read_spacing_spec (spec, &min_distance_, ly_symbol2scm ("minimum-distance"));
+  Page_layout_problem::read_spacing_spec (title_spec, &title_min_distance_, ly_symbol2scm ("minimum-distance"));
 
   last_column_ = 0;
   force_ = 0;
-  extent_ = unsmob_stencil (pb->get_property ("stencil")) ->extent (Y_AXIS);
+  Interval stencil_extent = unsmob_stencil (pb->get_property ("stencil"))->extent (Y_AXIS);
+  shape_ = Line_shape (stencil_extent, stencil_extent); // pretend it goes all the way across
+  tallness_ = 0;
   bottom_padding_ = 0;
-  space_ = robust_scm2double (pb->get_property ("next-space"), 1.0);
+  space_ = 0.0;
   inverse_hooke_ = 1.0;
   break_permission_ = ly_symbol2scm ("allow");
   page_permission_ = pb->get_property ("page-break-permission");
@@ -525,4 +553,40 @@ Line_details::Line_details (Prob *pb, Output_def *paper)
   title_ = to_boolean (pb->get_property ("is-title"));
   compressed_lines_count_ = 1;
   compressed_nontitle_lines_count_ = title_ ? 0 : 1;
+  SCM last_scm  = pb->get_property ("last-markup-line");
+  last_markup_line_  = to_boolean (last_scm);
+  SCM first_scm = pb->get_property ("first-markup-line");
+  first_markup_line_ = to_boolean (first_scm);
+  tight_spacing_ = to_boolean (pb->get_property ("tight-spacing"));
+  first_refpoint_offset_ = 0;
+}
+
+Real
+Line_details::full_height () const
+{
+  Interval ret;
+  ret.unite(shape_.begin_);
+  ret.unite(shape_.rest_);
+  return ret.length();
+}
+
+Real
+Line_details::tallness () const
+{
+  return tallness_;
+}
+
+Line_shape::Line_shape (Interval begin, Interval rest)
+{
+  begin_ = begin;
+  rest_ = rest;
+}
+
+Line_shape
+Line_shape::piggyback (Line_shape mount, Real padding) const
+{
+  Real elevation = max (begin_[UP]-mount.begin_[DOWN], rest_[UP]-mount.rest_[DOWN]);
+  Interval begin = Interval (begin_[DOWN], elevation + mount.begin_[UP] + padding);
+  Interval rest = Interval (rest_[DOWN], elevation + mount.rest_[UP] + padding);
+  return Line_shape (begin, rest);
 }