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"
17 #include "ly-smobs.icc"
19 Paper_book::Paper_book ()
22 systems_ = SCM_BOOL_F;
29 Paper_book::~Paper_book ()
33 IMPLEMENT_DEFAULT_EQUAL_P (Paper_book);
34 IMPLEMENT_SMOBS (Paper_book)
35 IMPLEMENT_TYPE_P (Paper_book, "ly:paper-book?")
38 Paper_book::mark_smob (SCM smob)
40 Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob);
41 for (int i = 0; i < b->score_systems_.size (); i++)
42 b->score_systems_[i].gc_mark ();
45 scm_gc_mark (b->paper_->self_scm ());
46 scm_gc_mark (b->header_);
47 scm_gc_mark (b->pages_);
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::output (String outname)
77 if (!score_systems_.size ())
80 /* Generate all stencils to trigger font loads. */
84 if (ly_c_module_p (header_))
85 scopes = scm_cons (header_, scopes);
87 String mod_nm = "scm framework-" + output_backend_global;
89 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
92 SCM func = scm_c_module_lookup (mod, "output-framework");
94 func = scm_variable_ref (func);
95 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
104 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
105 func = scm_variable_ref (func);
106 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
112 progress_indication ("\n");
116 Paper_book::classic_output (String outname)
118 /* Generate all stencils to trigger font loads. */
122 SCM scopes = SCM_EOL;
123 if (ly_c_module_p (header_))
124 scopes = scm_cons (header_, scopes);
126 if (ly_c_module_p (score_systems_[0].header_))
127 scopes = scm_cons (score_systems_[0].header_, scopes);
130 String format = output_backend_global;
131 String mod_nm = "scm framework-" + format;
133 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
134 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
137 func = scm_variable_ref (func);
138 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
144 progress_indication ("\n");
148 /* TODO: resurrect more complex user-tweaks for titling? */
150 Paper_book::book_title ()
152 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
155 SCM scopes = SCM_EOL;
156 if (ly_c_module_p (header_))
157 scopes = scm_cons (header_, scopes);
161 if (ly_c_procedure_p (title_func))
162 tit = scm_call_2 (title_func,
166 if (unsmob_stencil (tit))
167 title = *unsmob_stencil (tit);
169 if (!title.is_empty ())
170 title.align_to (Y_AXIS, UP);
176 Paper_book::score_title (int i)
178 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
183 SCM scopes = SCM_EOL;
184 if (ly_c_module_p (header_))
185 scopes = scm_cons (header_, scopes);
187 if (ly_c_module_p (score_systems_[i].header_))
188 scopes = scm_cons (score_systems_[i].header_, scopes);
192 if (ly_c_procedure_p (title_func))
193 tit = scm_call_2 (title_func,
197 if (unsmob_stencil (tit))
198 title = *unsmob_stencil (tit);
200 if (!title.is_empty ())
201 title.align_to (Y_AXIS, UP);
207 set_system_penalty (Paper_system * ps, SCM header)
209 if (ly_c_module_p (header))
211 SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
212 if (SCM_VARIABLEP(force)
213 && scm_is_bool (SCM_VARIABLE_REF(force)))
215 ps->break_before_penalty_ = to_boolean (SCM_VARIABLE_REF(force))
223 Paper_book::systems ()
225 if (systems_ != SCM_BOOL_F)
229 Stencil title = book_title ();
231 if (!title.is_empty ())
233 Paper_system *ps = new Paper_system (title, true);
234 set_system_penalty (ps, header_);
236 systems_ = scm_cons (ps->self_scm (), systems_);
237 scm_gc_unprotect_object (ps->self_scm ());
240 int score_count = score_systems_.size ();
241 for (int i = 0; i < score_count; i++)
243 Stencil title = score_title (i);
244 if (!title.is_empty ())
246 Paper_system *ps = new Paper_system (title, true);
247 systems_ = scm_cons (ps->self_scm (), systems_);
248 scm_gc_unprotect_object (ps->self_scm ());
250 set_system_penalty (ps, score_systems_[i].header_);
254 if (scm_vector_p (score_systems_[i].systems_) == SCM_BOOL_T)
257 SCM system_list = scm_vector_to_list (score_systems_[i].systems_);
259 system_list = scm_reverse (system_list);
260 systems_ = scm_append (scm_list_2 (system_list, systems_));
264 systems_ = scm_reverse (systems_);
267 Paper_system *last = 0;
268 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
270 Paper_system *ps = unsmob_paper_system (scm_car (s));
275 && !ps->break_before_penalty_)
276 ps->break_before_penalty_ = 10000;
286 if (SCM_BOOL_F != pages_)
290 SCM proc = paper_->c_variable ("page-breaking");
291 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
296 /****************************************************************/
298 Score_systems::Score_systems ()
305 Score_systems::gc_mark ()
307 scm_gc_mark (systems_);
308 scm_gc_mark (header_);