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 ()
26 systems_ = SCM_BOOL_F;
32 Paper_book::~Paper_book ()
36 IMPLEMENT_DEFAULT_EQUAL_P (Paper_book);
37 IMPLEMENT_SMOBS (Paper_book)
38 IMPLEMENT_TYPE_P (Paper_book, "ly:paper-book?")
41 Paper_book::mark_smob (SCM smob)
43 Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob);
45 scm_gc_mark (b->paper_->self_scm ());
46 scm_gc_mark (b->header_);
47 scm_gc_mark (b->header_0_);
48 scm_gc_mark (b->pages_);
49 scm_gc_mark (b->scores_);
54 Paper_book::print_smob (SCM smob, SCM port, scm_print_state*)
56 Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob);
58 scm_puts ("#<", port);
59 scm_puts (classname (b), port);
69 for (int i = dump_header_fieldnames_global.size (); i--; )
71 = scm_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
77 Paper_book::add_score (SCM s)
79 scores_ = scm_cons (s, scores_);
83 Paper_book::output (String outname)
85 if (scores_ == SCM_EOL)
88 /* Generate all stencils to trigger font loads. */
92 if (ly_c_module_p (header_))
93 scopes = scm_cons (header_, scopes);
95 String mod_nm = "scm framework-" + output_backend_global;
97 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
100 SCM func = scm_c_module_lookup (mod, "output-framework");
102 func = scm_variable_ref (func);
103 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
112 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
113 func = scm_variable_ref (func);
114 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
120 progress_indication ("\n");
124 Paper_book::classic_output (String outname)
126 /* Generate all stencils to trigger font loads. */
129 SCM scopes = SCM_EOL;
130 if (ly_c_module_p (header_))
131 scopes = scm_cons (header_, scopes);
133 if (ly_c_module_p (header_0_))
134 scopes = scm_cons (header_0_, scopes);
136 String format = output_backend_global;
137 String mod_nm = "scm framework-" + format;
139 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
140 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
143 func = scm_variable_ref (func);
144 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
150 progress_indication ("\n");
154 /* TODO: resurrect more complex user-tweaks for titling? */
156 Paper_book::book_title ()
158 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
161 SCM scopes = SCM_EOL;
162 if (ly_c_module_p (header_))
163 scopes = scm_cons (header_, scopes);
167 if (ly_c_procedure_p (title_func))
168 tit = scm_call_2 (title_func,
172 if (unsmob_stencil (tit))
173 title = *unsmob_stencil (tit);
175 if (!title.is_empty ())
176 title.align_to (Y_AXIS, UP);
182 Paper_book::score_title (SCM header)
184 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
188 SCM scopes = SCM_EOL;
189 if (ly_c_module_p (header_))
190 scopes = scm_cons (header_, scopes);
192 if (ly_c_module_p (header))
193 scopes = scm_cons (header, scopes);
196 if (ly_c_procedure_p (title_func))
197 tit = scm_call_2 (title_func,
201 if (unsmob_stencil (tit))
202 title = *unsmob_stencil (tit);
204 if (!title.is_empty ())
205 title.align_to (Y_AXIS, UP);
211 set_system_penalty (Paper_system * ps, SCM header)
213 if (ly_c_module_p (header))
215 SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
216 if (SCM_VARIABLEP(force)
217 && scm_is_bool (SCM_VARIABLE_REF(force)))
219 ps->break_before_penalty_ = to_boolean (SCM_VARIABLE_REF(force))
227 Paper_book::systems ()
229 if (systems_ != SCM_BOOL_F)
233 Stencil title = book_title ();
235 if (!title.is_empty ())
237 Paper_system *ps = new Paper_system (title, true);
238 set_system_penalty (ps, header_);
240 systems_ = scm_cons (ps->self_scm (), systems_);
241 scm_gc_unprotect_object (ps->self_scm ());
245 = scm_call_1 (ly_lily_module_constant ("layout-extract-page-properties"),
246 paper_->self_scm ());
248 SCM header = SCM_EOL;
249 for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
251 if (ly_c_module_p (scm_car (s)))
253 header = scm_car (s);
254 if (header_0_ == SCM_EOL)
257 else if (scm_is_vector (scm_car (s)))
259 Stencil title = score_title (header);
260 if (title.is_empty ())
261 title = score_title (header_);
262 if (!title.is_empty ())
264 Paper_system *ps = new Paper_system (title, true);
265 systems_ = scm_cons (ps->self_scm (), systems_);
266 scm_gc_unprotect_object (ps->self_scm ());
267 set_system_penalty (ps, header);
271 SCM system_list = scm_vector_to_list (scm_car (s));
272 system_list = scm_reverse (system_list);
273 systems_ = scm_append (scm_list_2 (system_list, systems_));
275 else if (Text_interface::markup_p (scm_car (s)))
277 SCM t = Text_interface::interpret_markup (paper_->self_scm (),
280 // FIXME: title=true?
281 Paper_system *ps = new Paper_system (*unsmob_stencil (t), true);
282 systems_ = scm_cons (ps->self_scm (), systems_);
283 scm_gc_unprotect_object (ps->self_scm ());
284 // FIXME: figure out penalty.
285 //set_system_penalty (ps, scores_[i].header_);
291 systems_ = scm_reverse (systems_);
294 Paper_system *last = 0;
295 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
297 Paper_system *ps = unsmob_paper_system (scm_car (s));
302 && !ps->break_before_penalty_)
303 ps->break_before_penalty_ = 10000;
313 if (SCM_BOOL_F != pages_)
317 SCM proc = paper_->c_variable ("page-breaking");
318 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));