]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/page.cc
(output_def): push scope of parent_ Output_def
[lilypond.git] / lily / page.cc
index 801e9c9c50af7cc07ac3c7681505d3f556c1b3f4..a3dcdb6d1094a0931fb9dffd8a7cc842e20c9be5 100644 (file)
@@ -9,49 +9,40 @@
 #include "dimensions.hh"
 #include "ly-module.hh"
 #include "page.hh"
-#include "paper-def.hh"
+#include "output-def.hh"
 #include "paper-outputter.hh"
 #include "paper-line.hh"
 #include "stencil.hh"
 #include "warn.hh"
 
+
 int Page::page_count_ = 0;
 Real Page::MIN_COVERAGE_ = 0.66;
 
-Page::Page (Paper_def *paper, int number)
+Page::Page (Output_def *paper, int number)
 {
-  paper_ = paper;
-  number_ = number;
-
   copyright_ = SCM_EOL;
   footer_ = SCM_EOL;
   header_ = SCM_EOL;
   lines_ = SCM_EOL;
   tagline_ = SCM_EOL;
   
+  paper_ = paper;
+  number_ = number;
+
   height_ = 0;
   line_count_ = 0;
   
   page_count_++;
 
-  hsize_ = paper->get_dimension (ly_symbol2scm ("hsize"));
-  vsize_ = paper->get_dimension (ly_symbol2scm ("vsize"));
-  top_margin_ = paper->get_dimension (ly_symbol2scm ("top-margin"));
-  bottom_margin_ = paper->get_dimension (ly_symbol2scm ("bottom-margin"));
-  head_sep_ = paper->get_dimension (ly_symbol2scm ("head-sep"));
-  foot_sep_ = paper->get_dimension (ly_symbol2scm ("foot-sep"));
-  text_width_ = paper->get_dimension (ly_symbol2scm ("linewidth"));
-  left_margin_ = (hsize_ - text_width_) / 2;
-  
-  SCM make_header = ly_scheme_function ("make-header");
-  SCM make_footer = ly_scheme_function ("make-footer");
-
-  header_ = scm_call_2 (make_header, paper_->self_scm (),
+  header_ = scm_call_2 (paper_->c_variable ("make-header"),
+                       paper_->self_scm (),
                        scm_int2num (number_));
   if (unsmob_stencil (header_))
     unsmob_stencil (header_)->align_to (Y_AXIS, UP);
     
-  footer_ = scm_call_2 (make_footer, paper_->self_scm (),
+  footer_ = scm_call_2 (paper_->c_variable ("make-footer"),
+                       paper_->self_scm (),
                        scm_int2num (number_));
   if (unsmob_stencil (footer_))
     unsmob_stencil (footer_)->align_to (Y_AXIS, UP);
@@ -73,11 +64,17 @@ SCM
 Page::mark_smob (SCM smob)
 {
   Page *p = (Page*) SCM_CELL_WORD_1 (smob);
-  scm_gc_mark (p->lines_);
   scm_gc_mark (p->header_);
   scm_gc_mark (p->footer_);
+
+  if (p->paper_)
+    {
+      scm_gc_mark (p->paper_->self_scm ());
+    }
+  
   scm_gc_mark (p->copyright_);
   scm_gc_mark (p->tagline_);
+  //scm_gc_mark (p->lines_);
   return p->lines_;
 }
 
@@ -93,10 +90,10 @@ Page::print_smob (SCM smob, SCM port, scm_print_state*)
   return 1;
 }
 
-static void
-stack_stencils (Stencil &a, Stencil *b, Offset *origin)
+static Stencil
+stack_stencils (Stencil a, Stencil b, Offset *origin)
 {
-  Real height = b->extent (Y_AXIS).length ();
+  Real height = b.extent (Y_AXIS).length ();
   if (height > 50 CM)
     {
       programming_error (to_string ("Improbable stencil height: %f", height));
@@ -104,16 +101,25 @@ stack_stencils (Stencil &a, Stencil *b, Offset *origin)
     }
   Offset o = *origin;
   o.mirror (Y_AXIS);
-  b->translate (o);
-  a.add_stencil (*b);
+  b.translate (o);
+  a.add_stencil (b);
   (*origin)[Y_AXIS] += height;
+  return a;
 }
 
-SCM
+Stencil
 Page::to_stencil () const
 {
   SCM proc = paper_->lookup_variable (ly_symbol2scm ("page-to-stencil"));
-  return scm_call_1 (proc, self_scm ());
+  return *unsmob_stencil (scm_call_1 (proc, self_scm ()));
+}
+
+//urg
+Real
+Page::left_margin () const
+{
+  return (paper_->get_dimension (ly_symbol2scm ("hsize"))
+         - paper_->get_dimension (ly_symbol2scm ("linewidth"))) / 2;
 }
 
 LY_DEFINE (ly_page_header_lines_footer_stencil, "ly:page-header-lines-footer-stencil",
@@ -124,7 +130,9 @@ LY_DEFINE (ly_page_header_lines_footer_stencil, "ly:page-header-lines-footer-ste
   SCM_ASSERT_TYPE (p, page, SCM_ARG1, __FUNCTION__, "page");
   
   Stencil stencil;
-  Offset o (p->left_margin_, p->top_margin_);
+  Offset o (p->left_margin (),
+           p->paper_->get_dimension (ly_symbol2scm ("top-margin")));
+
   Real vfill = (p->line_count_ > 1
                ? (p->text_height () - p->height_) / (p->line_count_ - 1)
                : 0);
@@ -138,14 +146,14 @@ LY_DEFINE (ly_page_header_lines_footer_stencil, "ly:page-header-lines-footer-ste
 
   if (Stencil *s = unsmob_stencil (p->header_))
     {
-      stack_stencils (stencil, s, &o);
-      o[Y_AXIS] += p->head_sep_;
+      stencil = stack_stencils (stencil, *s, &o);
+      o[Y_AXIS] += p->paper_->get_dimension (ly_symbol2scm ("head-sep"));
     }
 
   for (SCM s = p->lines_; s != SCM_EOL; s = ly_cdr (s))
     {
       Paper_line *p = unsmob_paper_line (ly_car (s));
-      stack_stencils (stencil, unsmob_stencil (p->to_stencil ()), &o);
+      stencil = stack_stencils (stencil, p->to_stencil (), &o);
       /* Do not put vfill between title and its music, */
       if (ly_cdr (s) != SCM_EOL
          && (!p->is_title () || vfill < 0))
@@ -156,7 +164,8 @@ LY_DEFINE (ly_page_header_lines_footer_stencil, "ly:page-header-lines-footer-ste
        o[Y_AXIS] += vfill;
     }
 
-  o[Y_AXIS] = p->vsize_ - p->bottom_margin_;
+  o[Y_AXIS] = p->paper_->get_dimension (ly_symbol2scm ("vsize"))
+    - p->paper_->get_dimension (ly_symbol2scm ("bottom-margin"));
   if (unsmob_stencil (p->copyright_))
     o[Y_AXIS] -= unsmob_stencil (p->copyright_)->extent (Y_AXIS).length ();
   if (unsmob_stencil (p->tagline_))
@@ -165,11 +174,11 @@ LY_DEFINE (ly_page_header_lines_footer_stencil, "ly:page-header-lines-footer-ste
     o[Y_AXIS] -= unsmob_stencil (p->footer_)->extent (Y_AXIS).length ();
 
   if (Stencil *s = unsmob_stencil (p->copyright_))
-    stack_stencils (stencil, s, &o);
+    stencil = stack_stencils (stencil, *s, &o);
   if (Stencil *s = unsmob_stencil (p->tagline_))
-    stack_stencils (stencil, s, &o);
+    stencil = stack_stencils (stencil, *s, &o);
   if (Stencil *s = unsmob_stencil (p->footer_))
-    stack_stencils (stencil, s, &o);
+    stencil = stack_stencils (stencil, *s, &o);
 
   return stencil.smobbed_copy ();
 }
@@ -177,11 +186,16 @@ LY_DEFINE (ly_page_header_lines_footer_stencil, "ly:page-header-lines-footer-ste
 Real
 Page::text_height () const
 {
-  Real h = vsize_ - top_margin_ - bottom_margin_;
+  Real h = paper_->get_dimension (ly_symbol2scm ("vsize"))
+    - paper_->get_dimension (ly_symbol2scm ("top-margin"))
+    - paper_->get_dimension (ly_symbol2scm ("bottom-margin"));
   if (unsmob_stencil (header_))
-    h -= unsmob_stencil (header_)->extent (Y_AXIS).length () + head_sep_;
-  if (unsmob_stencil (copyright_) || unsmob_stencil (tagline_) || unsmob_stencil (footer_))
-    h -= foot_sep_;
+    h -= unsmob_stencil (header_)->extent (Y_AXIS).length ()
+      + paper_->get_dimension (ly_symbol2scm ("head-sep"));
+  if (unsmob_stencil (copyright_)
+      || unsmob_stencil (tagline_)
+      || unsmob_stencil (footer_))
+    h -= paper_->get_dimension (ly_symbol2scm ("foot-sep"));
   if (unsmob_stencil (copyright_))
     h -= unsmob_stencil (copyright_)->extent (Y_AXIS).length ();
   if (unsmob_stencil (tagline_))