2 paper-book.cc -- implement Paper_book
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2005 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "paper-book.hh"
12 #include "output-def.hh"
13 #include "paper-score.hh"
14 #include "paper-system.hh"
15 #include "text-item.hh"
18 #include "ly-smobs.icc"
20 Paper_book::Paper_book ()
25 systems_ = SCM_BOOL_F;
31 Paper_book::~Paper_book ()
35 IMPLEMENT_DEFAULT_EQUAL_P (Paper_book);
36 IMPLEMENT_SMOBS (Paper_book)
37 IMPLEMENT_TYPE_P (Paper_book, "ly:paper-book?")
40 Paper_book::mark_smob (SCM smob)
42 Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob);
44 scm_gc_mark (b->paper_->self_scm ());
45 scm_gc_mark (b->header_);
46 scm_gc_mark (b->pages_);
47 scm_gc_mark (b->scores_);
52 Paper_book::print_smob (SCM smob, SCM port, scm_print_state*)
54 Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob);
56 scm_puts ("#<", port);
57 scm_puts (classname (b), port);
67 for (int i = dump_header_fieldnames_global.size (); i--; )
69 = scm_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
75 Paper_book::add_score (SCM s)
77 scores_ = scm_cons (s, scores_);
81 Paper_book::output (String outname)
83 if (scores_ == SCM_EOL)
86 /* Generate all stencils to trigger font loads. */
90 if (ly_c_module_p (header_))
91 scopes = scm_cons (header_, scopes);
93 String mod_nm = "scm framework-" + output_backend_global;
95 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
98 SCM func = scm_c_module_lookup (mod, "output-framework");
100 func = scm_variable_ref (func);
101 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
110 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
111 func = scm_variable_ref (func);
112 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
118 progress_indication ("\n");
122 Paper_book::classic_output (String outname)
124 /* Generate all stencils to trigger font loads. */
128 SCM scopes = SCM_EOL;
129 if (ly_c_module_p (header_))
130 scopes = scm_cons (header_, scopes);
133 if (ly_c_module_p (scores_[0].header_))
134 scopes = scm_cons (scores_[0].header_, scopes);
138 String format = output_backend_global;
139 String mod_nm = "scm framework-" + format;
141 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
142 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
145 func = scm_variable_ref (func);
146 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
152 progress_indication ("\n");
156 /* TODO: resurrect more complex user-tweaks for titling? */
158 Paper_book::book_title ()
160 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
163 SCM scopes = SCM_EOL;
164 if (ly_c_module_p (header_))
165 scopes = scm_cons (header_, scopes);
169 if (ly_c_procedure_p (title_func))
170 tit = scm_call_2 (title_func,
174 if (unsmob_stencil (tit))
175 title = *unsmob_stencil (tit);
177 if (!title.is_empty ())
178 title.align_to (Y_AXIS, UP);
184 Paper_book::score_title (SCM header)
186 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
190 SCM scopes = SCM_EOL;
191 if (ly_c_module_p (header_))
192 scopes = scm_cons (header_, scopes);
194 if (ly_c_module_p (header))
195 scopes = scm_cons (header, scopes);
198 if (ly_c_procedure_p (title_func))
199 tit = scm_call_2 (title_func,
203 if (unsmob_stencil (tit))
204 title = *unsmob_stencil (tit);
206 if (!title.is_empty ())
207 title.align_to (Y_AXIS, UP);
213 set_system_penalty (Paper_system * ps, SCM header)
215 if (ly_c_module_p (header))
217 SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
218 if (SCM_VARIABLEP(force)
219 && scm_is_bool (SCM_VARIABLE_REF(force)))
221 ps->break_before_penalty_ = to_boolean (SCM_VARIABLE_REF(force))
229 Paper_book::systems ()
231 if (systems_ != SCM_BOOL_F)
235 Stencil title = book_title ();
237 if (!title.is_empty ())
239 Paper_system *ps = new Paper_system (title, true);
240 set_system_penalty (ps, header_);
242 systems_ = scm_cons (ps->self_scm (), systems_);
243 scm_gc_unprotect_object (ps->self_scm ());
247 = scm_call_1 (ly_lily_module_constant ("layout-extract-page-properties"),
248 paper_->self_scm ());
250 SCM header = SCM_EOL;
251 for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
253 if (ly_c_module_p (scm_car (s)))
254 header = scm_car (s);
255 else if (scm_is_vector (scm_car (s)))
257 Stencil title = score_title (header);
258 if (!title.is_empty ())
260 Paper_system *ps = new Paper_system (title, true);
261 systems_ = scm_cons (ps->self_scm (), systems_);
262 scm_gc_unprotect_object (ps->self_scm ());
263 set_system_penalty (ps, header);
267 SCM system_list = scm_vector_to_list (scm_car (s));
268 system_list = scm_reverse (system_list);
269 systems_ = scm_append (scm_list_2 (system_list, systems_));
271 else if (Text_interface::markup_p (scm_car (s)))
273 SCM t = Text_interface::interpret_markup (paper_->self_scm (),
276 // FIXME: title=true?
277 Paper_system *ps = new Paper_system (*unsmob_stencil (t), true);
278 systems_ = scm_cons (ps->self_scm (), systems_);
279 scm_gc_unprotect_object (ps->self_scm ());
280 // FIXME: figure out penalty.
281 //set_system_penalty (ps, scores_[i].header_);
287 systems_ = scm_reverse (systems_);
290 Paper_system *last = 0;
291 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
293 Paper_system *ps = unsmob_paper_system (scm_car (s));
298 && !ps->break_before_penalty_)
299 ps->break_before_penalty_ = 10000;
309 if (SCM_BOOL_F != pages_)
313 SCM proc = paper_->c_variable ("page-breaking");
314 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));