]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/page-breaking.cc
Merge branch 'master' of git://git.savannah.gnu.org/lilypond.git
[lilypond.git] / lily / page-breaking.cc
index 4e386b81832186cf48f7014f0b879b025cb616db..5d55c7a9f41e26114d796dd8e22fa0c84136afcc 100644 (file)
 
 #include "international.hh"
 #include "item.hh"
+#include "line-interface.hh"
 #include "output-def.hh"
 #include "page-layout-problem.hh"
 #include "page-spacing.hh"
 #include "paper-book.hh"
 #include "paper-score.hh"
 #include "paper-system.hh"
+#include "text-interface.hh"
 #include "system.hh"
 #include "warn.hh"
 
@@ -178,7 +180,12 @@ compress_lines (const vector<Line_details> &orig)
 
          // compressed.title_ is true if and only if the first of its
          // compressed lines was a title.
-         compressed.title_ = old.title_;
+          compressed.title_ = old.title_;
+
+          // adds footnotes of one line to the footnotes of another
+          compressed.footnotes_.insert (compressed.footnotes_.begin (),
+            old.footnotes_.begin (), old.footnotes_.end ());
+          
          ret.back () = compressed;
        }
       else
@@ -243,6 +250,25 @@ Page_breaking::Page_breaking (Paper_book *pb, Break_predicate is_break, Prob_bre
   min_systems_per_page_ = 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_);
+
+  if (footnote_separator)
+    {
+      Interval separator_extent = footnote_separator->extent (Y_AXIS);
+      Real separator_span = separator_extent.length ();
+
+      footnote_separator_stencil_height_ = separator_span;
+    }
+  else
+    footnote_separator_stencil_height_ = 0.0;
+
+  footnote_padding_ = robust_scm2double (pb->paper_->c_variable ("footnote-padding"), 0.0);
+  footnote_footer_padding_ = robust_scm2double (pb->paper_->c_variable ("footnote-footer-padding"), 0.0);
+
+  footnote_number_raise_ = (to_boolean (pb->paper_->c_variable ("footnote-auto-numbering"))
+                            ? robust_scm2double (pb->paper_->c_variable ("footnote-number-raise"), 0.0)
+                            : 0.0);
+  
   if (systems_per_page_ && (max_systems_per_page_ || min_systems_per_page_))
     {
       warning (_f ("ignoring min-systems-per-page and max-systems-per-page because systems-per-page was set"));
@@ -302,6 +328,30 @@ Page_breaking::system_count () const
   return system_count_;
 }
 
+Real
+Page_breaking::footnote_separator_stencil_height () const
+{
+  return footnote_separator_stencil_height_;
+}
+
+Real
+Page_breaking::footnote_padding () const
+{
+  return footnote_padding_;
+}
+
+Real
+Page_breaking::footnote_footer_padding () const
+{
+  return footnote_footer_padding_;
+}
+
+Real
+Page_breaking::footnote_number_raise () const
+{
+  return footnote_number_raise_;
+}
+
 bool
 Page_breaking::too_many_lines (int line_count) const
 {
@@ -481,15 +531,15 @@ Page_breaking::breakpoint_property (vsize breakpoint, char const *str)
 }
 
 SCM
-Page_breaking::get_page_configuration (SCM systems, int page_num, bool ragged, bool last)
+Page_breaking::get_page_configuration (SCM systems, int page_num, int footnote_count, bool ragged, bool last)
 {
   SCM dummy_page = make_page (page_num, last);
-  Page_layout_problem layout (book_, dummy_page, systems);
+  Page_layout_problem layout (book_, dummy_page, systems, footnote_count);
   return scm_is_pair (systems) ? layout.solution (ragged) : SCM_EOL;
 }
 
 SCM
-Page_breaking::draw_page (SCM systems, SCM configuration, int page_num, bool last)
+Page_breaking::draw_page (SCM systems, SCM configuration, int page_num, int footnote_num, bool last)
 {
   // Create a stencil for each system.
   SCM paper_systems = SCM_EOL;
@@ -514,6 +564,20 @@ Page_breaking::draw_page (SCM systems, SCM configuration, int page_num, bool las
   Prob *p = unsmob_prob (page);
   p->set_property ("lines", paper_systems);
   p->set_property ("configuration", configuration);
+
+  Stencil *foot = unsmob_stencil (p->get_property ("foot-stencil"));
+
+  footnote_num = (to_boolean (book_->paper_->c_variable ("reset-footnotes-on-new-page"))
+                  ? 0
+                  : footnote_num);
+
+  SCM footnotes = Page_layout_problem::get_footnotes_from_lines (systems,
+                                                                 footnote_num,
+                                                                 book_);
+
+  Page_layout_problem::add_footnotes_to_footer (footnotes, foot, book_);
+
+  p->set_property ("foot-stencil", foot->smobbed_copy ());
   scm_apply_1 (page_stencil, page, SCM_EOL);
 
   return page;
@@ -538,8 +602,9 @@ Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
   // themselves. If this happens before the neighbouring staves have
   // been laid out, bad side-effects could happen (in particular,
   // Align_interface::align_to_ideal_distances might be called).
-  SCM systems_and_configs = SCM_EOL;
-
+  SCM systems_configs_fncounts = SCM_EOL;
+  vsize footnote_count = 0;
+    
   for (vsize i = 0; i < lines_per_page.size (); i++)
     {
       int page_num = i + first_page_number;
@@ -547,21 +612,24 @@ Page_breaking::make_pages (vector<vsize> lines_per_page, SCM systems)
       bool rag = ragged () || (bookpart_last_page && ragged_last ());
       SCM line_count = scm_from_int (lines_per_page[i]);
       SCM lines = scm_list_head (systems, line_count);
-      SCM config = get_page_configuration (lines, page_num, rag, bookpart_last_page);
-
-      systems_and_configs = scm_cons (scm_cons (lines, config), systems_and_configs);
+      int fn_lines = Page_layout_problem::get_footnote_count (lines);
+      SCM config = get_page_configuration (lines, page_num, footnote_count, rag, bookpart_last_page);
+      
+      systems_configs_fncounts = scm_cons (scm_list_3 (lines, config, scm_from_int ((int)footnote_count)), systems_configs_fncounts);
+      footnote_count += fn_lines;
       systems = scm_list_tail (systems, line_count);
     }
 
   // Now it's safe to make the pages.
   int page_num = first_page_number + lines_per_page.size () - 1;
-  for (SCM s = systems_and_configs; scm_is_pair (s); s = scm_cdr (s))
+  for (SCM s = systems_configs_fncounts; scm_is_pair (s); s = scm_cdr (s))
     {
       SCM lines = scm_caar (s);
-      SCM config = scm_cdar (s);
-      bool bookpart_last_page = (s == systems_and_configs);
-      SCM page = draw_page (lines, config, page_num, bookpart_last_page);
+      SCM config = scm_cadar (s);
+      int footnote_num = scm_to_int (scm_caddar (s));
 
+      bool bookpart_last_page = (s == systems_configs_fncounts);
+      SCM page = draw_page (lines, config, page_num, footnote_num, bookpart_last_page);
       /* collect labels */
       SCM page_num_scm = scm_from_int (page_num);
       for (SCM l = lines ; scm_is_pair (l)  ; l = scm_cdr (l))