From: Jan Nieuwenhuizen Date: Mon, 8 Mar 2004 23:49:41 +0000 (+0000) Subject: * lily/paper-book.cc (get_pages): Simplistic page breaking. X-Git-Tag: release/2.1.30~29 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=58d70e865ebf68e038244fca99110bd2e2917912;p=lilypond.git * lily/paper-book.cc (get_pages): Simplistic page breaking. * scm/output-tex.scm (start-page): (stop-page): New interface function. --- diff --git a/ChangeLog b/ChangeLog index 011cb40c54..d50fdc43a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-03-09 Jan Nieuwenhuizen + + * 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 * lily/paper-outputter.cc (output_expr): diff --git a/lily/paper-book.cc b/lily/paper-book.cc index f1d6ff9196..6c1c21c75b 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -6,6 +6,8 @@ (c) 2004 Jan Nieuwenhuizen */ +#include + #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 *pages = new Link_array; 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; } diff --git a/scm/output-tex.scm b/scm/output-tex.scm index 0ef9f4727a..f4aa7b7cf2 100644 --- a/scm/output-tex.scm +++ b/scm/output-tex.scm @@ -352,3 +352,11 @@ (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"))