]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/paper-book.cc (get_pages): Simplistic page breaking.
authorJan Nieuwenhuizen <janneke@gnu.org>
Mon, 8 Mar 2004 23:49:41 +0000 (23:49 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Mon, 8 Mar 2004 23:49:41 +0000 (23:49 +0000)
* scm/output-tex.scm (start-page):
(stop-page): New interface function.

ChangeLog
lily/paper-book.cc
scm/output-tex.scm

index 011cb40c54dcba6bad38955da76ec10bb79e424e..d50fdc43a7040703c0abcfb5be6edec963603ffc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-03-09  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * lily/paper-book.cc (get_pages): Simplistic page breaking.
+
+       * scm/output-tex.scm (start-page):
+       (stop-page): New interface function.
+
 2004-03-08  Jan Nieuwenhuizen  <janneke@gnu.org>
 
        * lily/paper-outputter.cc (output_expr):
index f1d6ff9196a84f5a39803f484c4522ddabce3a21..6c1c21c75b8e6b704362044ecc3e973f48ef0ea1 100644 (file)
@@ -6,6 +6,8 @@
   (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
+#include <stdio.h>
+
 #include "main.hh"
 #include "paper-book.hh"
 #include "paper-score.hh"
@@ -21,8 +23,20 @@ public:
   Paper_def *paper_;
 
   SCM lines_;
+  Stencil *header_;
+  Stencil *footer_;
+
+  /* actual height filled with text.  */
+  Real height_;
+  
+  //HMMM all this size stuff to paper/paper-outputter?
   Real hsize_;
   Real vsize_;
+  Real foot_sep_;
+  Real head_sep_;
+
+  /* available area for text.  */
+  Real text_height ();
 
   Page (Paper_def*);
   void output (Paper_outputter*, bool);
@@ -31,17 +45,44 @@ public:
 Page::Page (Paper_def *paper)
 {
   paper_ = paper;
+  height_ = 0;
+  header_ = 0;
+  footer_ = 0;
+  lines_ = SCM_EOL;
+  
   hsize_ = paper->get_realvar (ly_symbol2scm ("hsize"));
   vsize_ = paper->get_realvar (ly_symbol2scm ("vsize"));
+  head_sep_ = 0; //paper->get_realvar (ly_symbol2scm ("head-sep"));
+  foot_sep_ = 0; //paper->get_realvar (ly_symbol2scm ("foot-sep"));
 }
 
 void
 Page::output (Paper_outputter *out, bool is_last)
 {
+#if ONE_SCORE_PER_PAGE
   int line_count = SCM_VECTOR_LENGTH ((SCM) lines_);
   for (int i = 0; i < line_count; i++)
     out->output_line (scm_vector_ref (lines_, scm_int2num (i)),
                      is_last && i == line_count - 1);
+#else
+  // TODO: header/footer etc
+  out->output_scheme (scm_list_1 (ly_symbol2scm ("start-page")));
+  for (SCM s = lines_; gh_pair_p (s); s = ly_cdr (s))
+    out->output_line (ly_car (s), is_last && gh_pair_p (ly_cdr (s)));
+  out->output_scheme (scm_list_2 (ly_symbol2scm ("stop-page"),
+                                 gh_bool2scm (is_last)));
+#endif
+}
+
+Real
+Page::text_height ()
+{
+  Real h = vsize_;
+  if (header_)
+    h -= header_->extent (Y_AXIS).length () + head_sep_;
+  if (footer_)
+    h -= footer_->extent (Y_AXIS).length () + foot_sep_;
+  return h;
 }
 
 
@@ -74,11 +115,12 @@ Paper_book::output ()
 
 /*
   WIP -- this simply adds one Page per \score
+
+  FIXME: titling is broken.
+  
   TODO:
-     * get dimensions
-     * title: bookTitle vs scoreTitle
-     * start-page / stop-page in output-* interface
-     * some page breaking algorithm
+     * ->SCM?
+     * decent page breaking algorithm
      * header / footer (generate per Page, with page#)
      * override: # pages, or pageBreakLines= #'(3 3 4), ?
      * what about between-system-breaking, can we junk that?
@@ -90,15 +132,74 @@ Paper_book::get_pages ()
   Link_array<Page> *pages = new Link_array<Page>;
   Paper_def *paper = paper_scores_[0]->paper_;
   int score_count = paper_scores_.size ();
+
+  /* Calculate the full book height.  Hmm, can't we cache system
+     heights while making stencils?  */
+  Real book_height = 0;
   for (int i = 0; i < score_count; i++)
     {
-      Page *page = new Page (paper);
-      page->lines_ = paper_scores_[i]->lines_;
-      pages->push (page);
+      Paper_score *pscore = paper_scores_[i];
+      Stencil *title = (i == 0 ? pscore->book_title_ : pscore->score_title_);
+      if (title)
+       book_height += title->extent (Y_AXIS).length ();
+
+      int line_count = SCM_VECTOR_LENGTH ((SCM) pscore->lines_);
+      for (int j = 0; j < line_count; j++)
+       {
+         SCM line = scm_vector_ref (pscore->lines_, scm_int2num (j));
+         book_height += ly_scm2offset (ly_car (line))[Y_AXIS];
+       }
     }
 
-  //if (paper_scores_[0]->book_title_)
-  //  title = paper_scores_[0]->book_title_->extent (Y_AXIS).length ();
+  Page *page = new Page (paper);
+  fprintf (stderr, "book_height: %f\n", book_height);
+  fprintf (stderr, "vsize: %f\n", page->vsize_);
 
+#if ONE_SCORE_PER_PAGE
+  for (int i = 0; i < score_count; i++)
+    {
+      page->lines_ = paper_scores_[i]->lines_;
+      pages->push (page);
+    }
+#else
+  /* Simplistic page breaking.  */
+  Real text_height = page->text_height ();
+  for (int i = 0; i < score_count; i++)
+    {
+      Paper_score *pscore = paper_scores_[i];
+      Stencil *title = (i == 0 ? pscore->book_title_ : pscore->score_title_);
+      Real h = 0;
+      if (title)
+       h = title->extent (Y_AXIS).length ();
+
+      int line_count = SCM_VECTOR_LENGTH ((SCM) pscore->lines_);
+      for (int j = 0; j < line_count; j++)
+       {
+         SCM line = scm_vector_ref (pscore->lines_, scm_int2num (j));
+         h += ly_scm2offset (ly_car (line))[Y_AXIS];
+         if (page->height_ + h > text_height)
+           {
+             pages->push (page);
+             page = new Page (paper);
+           }
+         if (page->height_ + h <= text_height || page->height_ == 0)
+           {
+             if (j == 0 && title)
+               page->lines_
+                 = ly_snoc (scm_cons (ly_offset2scm (Offset (0, 0)),
+                                      scm_list_1
+                                      (scm_cons
+                                       (ly_offset2scm (Offset (0, 0)),
+                                        title->smobbed_copy ()))),
+                            page->lines_);
+             page->lines_ = ly_snoc (line, page->lines_);
+             page->height_ += h;
+             h = 0;
+           }
+       }
+    }
+#endif
+  
+  pages->push (page);
   return pages;
 }
index 0ef9f4727a2af36870ec2b521cb6d20f60253d59..f4aa7b7cf2bf216d4e9835105028276961d5cddc 100644 (file)
 
 (define-public (tex-output-expression expr port)
   (display (eval expr this-module) port ))
+
+(define-public (start-page)
+  "\n\\vbox{\n")
+
+(define-public (stop-page last?)
+  (if last?
+      "\n}\n"
+      "\n}\n\\newpage\n"))