]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/page-breaking.cc
Update German manual skeletons
[lilypond.git] / lily / page-breaking.cc
index 0d88338935d56e0269d133d30704f82790f6a553..2c137e36842f108b22da3b7583a4a0f67bf38611 100644 (file)
@@ -53,6 +53,28 @@ compress_lines (const vector<Line_details> &orig)
   return ret;
 }
 
+/* translate the number of systems-per-page into something meaningful for
+   the uncompressed lines.
+*/
+static vector<vsize>
+uncompress_solution (vector<vsize> const &systems_per_page,
+                    vector<Line_details> const &compressed)
+{
+  vector<vsize> ret;
+  vsize start_sys = 0;
+
+  for (vsize i = 0; i < systems_per_page.size (); i++)
+    {
+      int compressed_count = 0;
+      for (vsize j = start_sys; j < start_sys + systems_per_page[i]; j++)
+       compressed_count += (int)compressed[j].force_;
+
+      ret.push_back (systems_per_page[i] + compressed_count);
+      start_sys += systems_per_page[i];
+    }
+  return ret;
+}
+
 /* for Page_breaking, the start index (when we are dealing with the stuff
    between a pair of breakpoints) refers to the break_ index of the end of
    the previous page. So the system index of the start of the current page
@@ -218,6 +240,7 @@ Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
   int first_page_number
     = robust_scm2int (book_->paper_->c_variable ("first-page-number"), 1);
   SCM ret = SCM_EOL;
+  SCM label_page_table = SCM_EOL;
 
   for (vsize i = 0; i < lines_per_page.size (); i++)
     {
@@ -231,10 +254,28 @@ Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
                              scm_list_n (book, lines, page_num,
                                          rag, last, SCM_UNDEFINED));
 
+      /* collect labels */
+      for (SCM l = lines ; scm_is_pair (l)  ; l = scm_cdr (l))
+       {
+         SCM labels = SCM_EOL;
+         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)))
+           labels = prob->get_property ("labels");
+
+         for (SCM lbls = labels ; scm_is_pair (lbls) ; lbls = scm_cdr (lbls))
+           label_page_table = scm_cons (scm_cons (scm_car (lbls), page_num),
+                                        label_page_table);
+       }
+
       scm_apply_1 (page_stencil, page, SCM_EOL);
       ret = scm_cons (page, ret);
       systems = scm_list_tail (systems, line_count);
     }
+  book_->paper_->set_variable (ly_symbol2scm ("label-page-table"), label_page_table);
   ret = scm_reverse (ret);
   return ret;
 }
@@ -497,8 +538,8 @@ Page_breaking::cache_line_details (vsize configuration_index)
          vsize sys = next_system (current_chunks_[i]);
          if (system_specs_[sys].pscore_)
            {
-             vsize start = 0;
-             vsize end = 0;
+             vsize start;
+             vsize end;
              line_breaker_args (sys, current_chunks_[i], current_chunks_[i+1], &start, &end);
 
              vector<Line_details> details = line_breaking_[sys].line_details (start, end, div[i]);
@@ -630,18 +671,11 @@ Page_breaking::space_systems_on_n_pages (vsize configuration, vsize n, vsize fir
   if (n > cached_line_details_.size ())
     return Page_spacing_result ();
   if (n == 1)
-    {
-      ret = space_systems_on_1_page (cached_line_details_,
-                                    page_height (first_page_num, is_last ()),
-                                    ragged () || (is_last () && ragged_last ()));
-
-      uncompress_page_spacing_results (&ret);
-    }
+    ret = space_systems_on_1_page (cached_line_details_,
+                                  page_height (first_page_num, is_last ()),
+                                  ragged () || (is_last () && ragged_last ()));
   else if (n == 2)
-    {
-      ret = space_systems_on_2_pages (configuration, first_page_num);
-      uncompress_page_spacing_results (&ret);
-    }
+    ret = space_systems_on_2_pages (configuration, first_page_num);
   else
     {
       Page_spacer ps (cached_line_details_, first_page_num, this);
@@ -664,37 +698,37 @@ Page_breaking::space_systems_on_n_or_one_more_pages (vsize configuration, vsize
   Page_spacing_result n_res;
   Page_spacing_result m_res;
 
-  if (n <= 2)
+  cache_line_details (configuration);
+  vsize min_p_count = min_page_count (configuration, first_page_num);
+
+  if (n == 1)
     {
-      n_res = space_systems_on_n_pages (configuration, n, first_page_num);
-      m_res = space_systems_on_n_pages (configuration, n+1, first_page_num);
+      bool rag = ragged () || (is_last () && ragged_last ());
+      Real height = page_height (first_page_num, is_last ());
+
+      if (1 >= min_p_count)
+       n_res = space_systems_on_1_page (cached_line_details_, height, rag);
+      if (1 < cached_line_details_.size ())
+       m_res = space_systems_on_2_pages (configuration, first_page_num);
     }
   else
     {
-      cache_line_details (configuration);
-
-      vsize min_p_count = min_page_count (configuration, first_page_num);
       Page_spacer ps (cached_line_details_, first_page_num, this);
+      
       if (n >= min_p_count)
-       {
-         n_res = ps.solve (n);
-         uncompress_page_spacing_results (&n_res);
-       }
+       n_res = ps.solve (n);
       if (n < cached_line_details_.size ())
-       {
-         m_res = ps.solve (n+1);
-         uncompress_page_spacing_results (&m_res);
-       }
-            
+       m_res = ps.solve (n+1);
     }
 
+  m_res = finalize_spacing_result (configuration, m_res);
+  n_res = finalize_spacing_result (configuration, n_res);
+
   Real penalty = blank_page_penalty ();
   n_res.demerits_ += penalty;
   n_res.force_.back () += penalty;
 
-  if (m_res.demerits_ < n_res.demerits_)
-    return m_res;
-  return n_res;
+  return (m_res.demerits_ < n_res.demerits_) ? m_res : n_res;
 }
 
 Page_spacing_result
@@ -720,44 +754,14 @@ Page_breaking::space_systems_on_best_pages (vsize configuration, vsize first_pag
   return finalize_spacing_result (configuration, best);
 }
 
-
-
-/* translate the number of systems-per-page into something meaningful for
-   the uncompressed lines.
-*/
-static vector<vsize>
-uncompress_solution (vector<vsize> const &systems_per_page,
-                    vector<Line_details> const &compressed)
-{
-  vector<vsize> ret;
-  vsize start_sys = 0;
-
-  for (vsize i = 0; i < systems_per_page.size (); i++)
-    {
-      int compressed_count = 0;
-      for (vsize j = start_sys; j < start_sys + systems_per_page[i]; j++)
-       compressed_count += (int)compressed[j].force_;
-
-      ret.push_back (systems_per_page[i] + compressed_count);
-      start_sys += systems_per_page[i];
-    }
-  return ret;
-}
-
-void
-Page_breaking::uncompress_page_spacing_results (Page_spacing_result *res)
-{
-  res->systems_per_page_ = uncompress_solution (res->systems_per_page_, cached_line_details_);
-}
-                                               
 /* Calculate demerits and fix res.systems_per_page_ so that
    it refers to the original line numbers, not the ones given by compress_lines (). */
 Page_spacing_result
 Page_breaking::finalize_spacing_result (vsize configuration, Page_spacing_result res)
 {
   cache_line_details (configuration);
-  uncompress_page_spacing_results (&res);
-  
+  res.systems_per_page_ = uncompress_solution (res.systems_per_page_, cached_line_details_);
+
   Real line_force = 0;
   Real line_penalty = 0;
   Real page_force = 0;
@@ -785,6 +789,7 @@ Page_breaking::finalize_spacing_result (vsize configuration, Page_spacing_result
      becomes averaged out over many pages. */
   res.demerits_ = line_force + line_penalty + (page_force + res.penalty_) * page_weighting;
   return res;
+
 }
 
 /* the cases for page_count = 1 or 2 can be done in O (n) time. Since they