2 paper-book.cc -- implement Paper_book
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
12 #include "paper-book.hh"
13 #include "paper-score.hh"
14 #include "paper-def.hh"
16 #include "paper-outputter.hh"
18 // -- this simply adds one Page per \score
19 // #define ONE_SCORE_PER_PAGE
21 // WIP -- simplistic page interface
22 // Do we need this at all? SCM, smob?
32 /* actual height filled with text. */
35 //HMMM all this size stuff to paper/paper-outputter?
41 /* available area for text. */
45 void output (Paper_outputter*, bool);
48 Page::Page (Paper_def *paper)
56 hsize_ = paper->get_realvar (ly_symbol2scm ("hsize"));
57 vsize_ = paper->get_realvar (ly_symbol2scm ("vsize"));
58 head_sep_ = 0; //paper->get_realvar (ly_symbol2scm ("head-sep"));
59 foot_sep_ = 0; //paper->get_realvar (ly_symbol2scm ("foot-sep"));
63 Page::output (Paper_outputter *out, bool is_last)
65 #if ONE_SCORE_PER_PAGE
66 int line_count = SCM_VECTOR_LENGTH ((SCM) lines_);
67 for (int i = 0; i < line_count; i++)
68 out->output_line (scm_vector_ref (lines_, scm_int2num (i)),
69 is_last && i == line_count - 1);
71 // TODO: header/footer etc
72 out->output_scheme (scm_list_1 (ly_symbol2scm ("start-page")));
73 for (SCM s = lines_; gh_pair_p (s); s = ly_cdr (s))
74 out->output_line (ly_car (s), is_last && gh_pair_p (ly_cdr (s)));
75 out->output_scheme (scm_list_2 (ly_symbol2scm ("stop-page"),
76 gh_bool2scm (is_last)));
85 h -= header_->extent (Y_AXIS).length () + head_sep_;
87 h -= footer_->extent (Y_AXIS).length () + foot_sep_;
92 Paper_book *paper_book;
94 Paper_book::Paper_book ()
101 Paper_outputter *out = paper_scores_[0]->outputter_;
103 Paper_def *paper = paper_scores_[0]->paper_;
104 out->output_header (paper);
106 if (paper_scores_[0]->book_title_)
107 out->output_expr (paper_scores_[0]->book_title_->get_expr (),
110 Link_array<Page> *pages = get_pages ();
111 int page_count = pages->size ();
112 for (int i = 0; i < page_count; i++)
113 (*pages)[i]->output (out, i + 1 == page_count);
115 out->output_scheme (scm_list_1 (ly_symbol2scm ("end-output")));
116 progress_indication ("\n");
122 FIXME: titling is broken.
126 * decent page breaking algorithm
127 * header / footer (generate per Page, with page#)
128 * override: # pages, or pageBreakLines= #'(3 3 4), ?
129 * what about between-system-breaking, can we junk that?
133 Paper_book::get_pages ()
135 Link_array<Page> *pages = new Link_array<Page>;
136 Paper_def *paper = paper_scores_[0]->paper_;
137 int score_count = paper_scores_.size ();
139 /* Calculate the full book height. Hmm, can't we cache system
140 heights while making stencils? */
141 Real book_height = 0;
142 for (int i = 0; i < score_count; i++)
144 Paper_score *pscore = paper_scores_[i];
145 Stencil *title = (i == 0 ? pscore->book_title_ : pscore->score_title_);
147 book_height += title->extent (Y_AXIS).length ();
149 int line_count = SCM_VECTOR_LENGTH ((SCM) pscore->lines_);
150 for (int j = 0; j < line_count; j++)
152 SCM line = scm_vector_ref (pscore->lines_, scm_int2num (j));
153 book_height += ly_scm2offset (ly_car (line))[Y_AXIS];
157 Page *page = new Page (paper);
158 fprintf (stderr, "book_height: %f\n", book_height);
159 fprintf (stderr, "vsize: %f\n", page->vsize_);
160 fprintf (stderr, "pages: %f\n", book_height / page->text_height ());
162 #if ONE_SCORE_PER_PAGE
163 for (int i = 0; i < score_count; i++)
165 page->lines_ = paper_scores_[i]->lines_;
169 /* Simplistic page breaking. */
170 Real text_height = page->text_height ();
171 for (int i = 0; i < score_count; i++)
173 Paper_score *pscore = paper_scores_[i];
174 Stencil *title = (i == 0 ? pscore->book_title_ : pscore->score_title_);
177 h = title->extent (Y_AXIS).length ();
179 int line_count = SCM_VECTOR_LENGTH ((SCM) pscore->lines_);
180 for (int j = 0; j < line_count; j++)
182 SCM line = scm_vector_ref (pscore->lines_, scm_int2num (j));
183 h += ly_scm2offset (ly_car (line))[Y_AXIS];
184 if (page->height_ + h > text_height)
187 page = new Page (paper);
189 if (page->height_ + h <= text_height || page->height_ == 0)
193 = ly_snoc (scm_cons (ly_offset2scm (Offset (0, 0)),
196 (ly_offset2scm (Offset (0, 0)),
197 title->smobbed_copy ()))),
199 page->lines_ = ly_snoc (line, page->lines_);