]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/page-breaking.cc
input/regression/bookparts.ly fails at PDF conversion stage
[lilypond.git] / lily / page-breaking.cc
index 7220857d9194e1c7ff4ff5c0c89b91b78b484645..94a76f9a19af835867ea8550d2ce0da1ac9d2336 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2006--2012 Joe Neeman <joeneeman@gmail.com>
+  Copyright (C) 2006--2015 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
 #include "system.hh"
 #include "warn.hh"
 
+using std::pair;
+using std::vector;
+
 /* for each forbidden page break, merge the systems around it into one
    system. */
 static vector<Line_details>
@@ -248,9 +251,9 @@ Page_breaking::Page_breaking (Paper_book *pb, Break_predicate is_break, Prob_bre
   paper_height_ = robust_scm2double (pb->paper_->c_variable ("paper-height"), 1.0);
   ragged_ = to_boolean (pb->paper_->c_variable ("ragged-bottom"));
   ragged_last_ = to_boolean (pb->paper_->c_variable ("ragged-last-bottom"));
-  systems_per_page_ = max (0, robust_scm2int (pb->paper_->c_variable ("systems-per-page"), 0));
-  max_systems_per_page_ = max (0, robust_scm2int (pb->paper_->c_variable ("max-systems-per-page"), 0));
-  min_systems_per_page_ = max (0, robust_scm2int (pb->paper_->c_variable ("min-systems-per-page"), 0));
+  systems_per_page_ = std::max (0, robust_scm2int (pb->paper_->c_variable ("systems-per-page"), 0));
+  max_systems_per_page_ = std::max (0, robust_scm2int (pb->paper_->c_variable ("max-systems-per-page"), 0));
+  min_systems_per_page_ = std::max (0, robust_scm2int (pb->paper_->c_variable ("min-systems-per-page"), 0));
   orphan_penalty_ = robust_scm2int (pb->paper_->c_variable ("orphan-penalty"), 100000);
 
   Stencil footnote_separator = Page_layout_problem::get_footnote_separator_stencil (pb->paper_);
@@ -554,7 +557,7 @@ Page_breaking::draw_page (SCM systems, SCM configuration, int page_num, bool las
   for (SCM s = systems; scm_is_pair (s); s = scm_cdr (s))
     {
       SCM paper_system = scm_car (s);
-      if (Grob *g = unsmob_grob (scm_car (s)))
+      if (Grob *g = unsmob<Grob> (scm_car (s)))
         {
           System *sys = dynamic_cast<System *> (g);
           paper_system = sys->get_paper_system ();
@@ -567,11 +570,11 @@ Page_breaking::draw_page (SCM systems, SCM configuration, int page_num, bool las
   // Create the page and draw it.
   SCM page = make_page (page_num, last);
 
-  Prob *p = unsmob_prob (page);
+  Prob *p = unsmob<Prob> (page);
   p->set_property ("lines", paper_systems);
   p->set_property ("configuration", configuration);
 
-  Stencil *foot_p = unsmob_stencil (p->get_property ("foot-stencil"));
+  Stencil *foot_p = unsmob<Stencil> (p->get_property ("foot-stencil"));
   Stencil foot = foot_p ? *foot_p : Stencil ();
 
   SCM footnotes = Page_layout_problem::get_footnotes_from_lines (systems);
@@ -594,7 +597,7 @@ Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
   SCM ret = SCM_EOL;
   bool reset_footnotes_on_new_page = to_boolean (book_->top_paper ()->c_variable ("reset-footnotes-on-new-page"));
   SCM label_page_table = book_->top_paper ()->c_variable ("label-page-table");
-  if (label_page_table == SCM_UNDEFINED)
+  if (SCM_UNBNDP (label_page_table))
     label_page_table = SCM_EOL;
 
   // Build a list of (systems configuration . footnote-count) triples.
@@ -658,12 +661,12 @@ Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
       for (SCM l = lines; scm_is_pair (l); l = scm_cdr (l))
         {
           SCM labels = SCM_EOL;
-          if (Grob *line = unsmob_grob (scm_car (l)))
+          if (Grob *line = unsmob<Grob> (scm_car (l)))
             {
               System *system = dynamic_cast<System *> (line);
               labels = system->get_property ("labels");
             }
-          else if (Prob *prob = unsmob_prob (scm_car (l)))
+          else if (Prob *prob = unsmob<Prob> (scm_car (l)))
             labels = prob->get_property ("labels");
 
           for (SCM lbls = labels; scm_is_pair (lbls); lbls = scm_cdr (lbls))
@@ -689,13 +692,13 @@ Page_breaking::create_system_list ()
   SCM specs = book_->get_system_specs ();
   for (SCM s = specs; scm_is_pair (s); s = scm_cdr (s))
     {
-      if (Paper_score *ps = dynamic_cast<Paper_score *> (unsmob_music_output (scm_car (s))))
+      if (Paper_score *ps = unsmob<Paper_score> (scm_car (s)))
         {
           system_specs_.push_back (System_spec (ps));
         }
       else
         {
-          Prob *pb = unsmob_prob (scm_car (s));
+          Prob *pb = unsmob<Prob> (scm_car (s));
           assert (pb);
 
           pb->protect ();
@@ -747,7 +750,7 @@ Page_breaking::find_chunks_and_breaks (Break_predicate is_break, Prob_break_pred
           vector<vsize> line_breaker_columns;
           line_breaker_columns.push_back (0);
 
-          for (vsize j = 1; j < cols.size (); j++)
+          for (vsize j = 0; j < cols.size (); j++)
             {
               if (forced_line_break_cols.size ())
                 {
@@ -924,7 +927,7 @@ Page_breaking::set_current_breakpoints (vsize start,
 
           dems_and_indices.push_back (pair<Real, vsize> (dem, i));
         }
-      vector_sort (dems_and_indices, less<pair<Real, vsize> > ());
+      vector_sort (dems_and_indices, std::less<pair<Real, vsize> > ());
 
       vector<Line_division> best_5_configurations;
       for (vsize i = 0; i < 5; i++)
@@ -1028,9 +1031,9 @@ Page_breaking::line_divisions_rec (vsize system_count,
       others_min += min_sys[i];
       others_max += max_sys[i];
     }
-  others_max = min (others_max, (int) system_count);
-  int real_min = max ((int) min_sys[my_index], (int) system_count - others_max);
-  int real_max = min ((int) max_sys[my_index], (int) system_count - others_min);
+  others_max = std::min (others_max, (int) system_count);
+  int real_min = std::max ((int) min_sys[my_index], (int) system_count - others_max);
+  int real_max = std::min ((int) max_sys[my_index], (int) system_count - others_min);
 
   if (real_min > real_max || real_min < 0)
     {
@@ -1070,7 +1073,7 @@ Page_breaking::compute_line_heights ()
       Real a = shape.begin_[UP];
       Real b = shape.rest_[UP];
       bool title = cur.title_;
-      Real refpoint_hanging = max (prev_hanging_begin + a, prev_hanging_rest + b);
+      Real refpoint_hanging = std::max (prev_hanging_begin + a, prev_hanging_rest + b);
 
       if (i > 0)
         {
@@ -1083,14 +1086,14 @@ Page_breaking::compute_line_heights ()
           Real min_dist = title
                           ? prev.title_min_distance_
                           : prev.min_distance_;
-          refpoint_hanging = max (refpoint_hanging + padding,
+          refpoint_hanging = std::max (refpoint_hanging + padding,
                                   prev_refpoint_hanging - prev.refpoint_extent_[DOWN]
                                   + cur.refpoint_extent_[UP] + min_dist);
         }
 
       Real hanging_begin = refpoint_hanging - shape.begin_[DOWN];
       Real hanging_rest = refpoint_hanging - shape.rest_[DOWN];
-      Real hanging = max (hanging_begin, hanging_rest);
+      Real hanging = std::max (hanging_begin, hanging_rest);
       cur.tallness_ = hanging - prev_hanging;
       prev_hanging = hanging;
       prev_hanging_begin = hanging_begin;
@@ -1133,7 +1136,7 @@ Page_breaking::min_page_count (vsize configuration, vsize first_page_num)
 
       if ((!too_few_lines (line_count) && (next_height > cur_page_height && cur_rod_height > 0))
           || too_many_lines (next_line_count)
-          || (prev && prev->page_permission_ == ly_symbol2scm ("force")))
+          || (prev && scm_is_eq (prev->page_permission_, ly_symbol2scm ("force"))))
         {
           line_count = cur.compressed_nontitle_lines_count_;
           cur_rod_height = cur.full_height ();
@@ -1332,7 +1335,7 @@ Page_breaking::space_systems_with_fixed_number_per_page (vsize configuration,
           system_count_on_this_page += cur_line.compressed_nontitle_lines_count_;
           line++;
 
-          if (cur_line.page_permission_ == ly_symbol2scm ("force"))
+          if (scm_is_eq (cur_line.page_permission_, ly_symbol2scm ("force")))
             break;
         }
 
@@ -1374,7 +1377,8 @@ Page_breaking::pack_systems_on_least_pages (vsize configuration, vsize first_pag
       if ((line > page_first_line)
           && (isinf (space.force_)
               || ((line > 0)
-                  && (cached_line_details_[line - 1].page_permission_ == ly_symbol2scm ("force")))))
+                  && scm_is_eq (cached_line_details_[line - 1].page_permission_,
+                                ly_symbol2scm ("force")))))
         {
           res.systems_per_page_.push_back (line - page_first_line);
           res.force_.push_back (prev_force);
@@ -1440,12 +1444,12 @@ Page_breaking::finalize_spacing_result (vsize configuration, Page_spacing_result
     }
 
   for (vsize i = ragged () ? res.force_.size () - 1 : 0;
-       i < res.force_.size () - ragged_last ();
+       i < res.force_.size () - (is_last () && ragged_last ());
        i++)
     {
       Real f = res.force_[i];
 
-      page_demerits += min (f * f, BAD_SPACING_PENALTY);
+      page_demerits += std::min (f * f, BAD_SPACING_PENALTY);
     }
 
   /* for a while we tried averaging page and line forces across pages instead
@@ -1479,7 +1483,7 @@ Page_breaking::space_systems_on_1_page (vector<Line_details> const &lines, Real
     }
 
   ret.systems_per_page_.push_back (lines.size ());
-  ret.force_.push_back (ragged ? min (space.force_, 0.0) : space.force_);
+  ret.force_.push_back (ragged ? std::min (space.force_, 0.0) : space.force_);
   ret.penalty_ = line_count_penalty (line_count) + lines.back ().page_penalty_ + lines.back ().turn_penalty_;
   ret.system_count_status_ |= line_count_status (line_count);
 
@@ -1498,7 +1502,8 @@ Page_breaking::space_systems_on_2_pages (vsize configuration, vsize first_page_n
   /* if there is a forced break, this reduces to 2 1-page problems */
   cache_line_details (configuration);
   for (vsize i = 0; i + 1 < cached_line_details_.size (); i++)
-    if (cached_line_details_[i].page_permission_ == ly_symbol2scm ("force"))
+    if (scm_is_eq (cached_line_details_[i].page_permission_,
+        ly_symbol2scm ("force")))
       {
         vector<Line_details> lines1 (cached_line_details_.begin (), cached_line_details_.begin () + i + 1);
         vector<Line_details> lines2 (cached_line_details_.begin () + i + 1, cached_line_details_.end ());
@@ -1652,8 +1657,8 @@ Page_breaking::min_whitespace_at_top_of_page (Line_details const &line) const
                                           ly_symbol2scm ("padding"));
 
   // FIXME: take into account the height of the header
-  Real translate = max (line.shape_.begin_[UP], line.shape_.rest_[UP]);
-  return max (0.0, max (padding, min_distance - translate));
+  Real translate = std::max (line.shape_.begin_[UP], line.shape_.rest_[UP]);
+  return std::max (0.0, std::max (padding, min_distance - translate));
 }
 
 Real
@@ -1671,8 +1676,8 @@ Page_breaking::min_whitespace_at_bottom_of_page (Line_details const &line) const
                                           ly_symbol2scm ("padding"));
 
   // FIXME: take into account the height of the footer
-  Real translate = min (line.shape_.begin_[DOWN], line.shape_.rest_[DOWN]);
-  return max (0.0, max (padding, min_distance + translate));
+  Real translate = std::min (line.shape_.begin_[DOWN], line.shape_.rest_[DOWN]);
+  return std::max (0.0, std::max (padding, min_distance + translate));
 }
 
 int