2 paper-book.cc -- implement Paper_book
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "paper-book.hh"
12 #include "output-def.hh"
13 #include "paper-outputter.hh"
14 #include "paper-score.hh"
15 #include "paper-system.hh"
18 #include "ly-smobs.icc"
20 Paper_book::Paper_book ()
23 systems_ = SCM_BOOL_F;
30 Paper_book::~Paper_book ()
34 IMPLEMENT_DEFAULT_EQUAL_P (Paper_book);
35 IMPLEMENT_SMOBS (Paper_book)
36 IMPLEMENT_TYPE_P (Paper_book, "ly:paper-book?")
39 Paper_book::mark_smob (SCM smob)
41 Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob);
42 for (int i = 0; i < b->score_systems_.size (); i++)
43 b->score_systems_[i].gc_mark ();
46 scm_gc_mark (b->paper_->self_scm ());
47 scm_gc_mark (b->header_);
48 scm_gc_mark (b->pages_);
53 Paper_book::print_smob (SCM smob, SCM port, scm_print_state*)
55 Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob);
57 scm_puts ("#<", port);
58 scm_puts (classname (b), port);
60 //scm_puts (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::output (String outname)
79 if (!score_systems_.size ())
82 /* Generate all stencils to trigger font loads. */
86 if (ly_c_module_p (header_))
87 scopes = scm_cons (header_, scopes);
89 String mod_nm = "scm framework-" + output_backend_global;
91 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
94 SCM func = scm_c_module_lookup (mod, "output-framework");
96 func = scm_variable_ref (func);
97 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
106 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
107 func = scm_variable_ref (func);
108 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
114 progress_indication ("\n");
118 Paper_book::classic_output (String outname)
120 /* Generate all stencils to trigger font loads. */
124 SCM scopes = SCM_EOL;
125 if (ly_c_module_p (header_))
126 scopes = scm_cons (header_, scopes);
128 if (ly_c_module_p (score_systems_[0].header_))
129 scopes = scm_cons (score_systems_[0].header_, scopes);
132 String format = output_backend_global;
133 String mod_nm = "scm framework-" + format;
135 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
136 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
138 func = scm_variable_ref (func);
140 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
146 progress_indication ("\n");
150 /* TODO: resurrect more complex user-tweaks for titling? */
152 Paper_book::book_title ()
154 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
157 SCM scopes = SCM_EOL;
158 if (ly_c_module_p (header_))
159 scopes = scm_cons (header_, scopes);
163 if (ly_c_procedure_p (title_func))
164 tit = scm_call_2 (title_func,
168 if (unsmob_stencil (tit))
169 title = *unsmob_stencil (tit);
171 if (!title.is_empty ())
172 title.align_to (Y_AXIS, UP);
178 Paper_book::score_title (int i)
180 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
185 SCM scopes = SCM_EOL;
186 if (ly_c_module_p (header_))
187 scopes = scm_cons (header_, scopes);
189 if (ly_c_module_p (score_systems_[i].header_))
190 scopes = scm_cons (score_systems_[i].header_, scopes);
194 if (ly_c_procedure_p (title_func))
195 tit = scm_call_2 (title_func,
199 if (unsmob_stencil (tit))
200 title = *unsmob_stencil (tit);
202 if (!title.is_empty ())
203 title.align_to (Y_AXIS, UP);
209 set_system_penalty (Paper_system * ps, SCM header)
211 if (ly_c_module_p (header))
213 SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
214 if (SCM_VARIABLEP(force)
215 && scm_is_bool (SCM_VARIABLE_REF(force)))
217 ps->break_before_penalty_ = to_boolean (SCM_VARIABLE_REF(force))
225 Paper_book::systems ()
227 if (systems_ != SCM_BOOL_F)
231 Stencil title = book_title ();
233 if (!title.is_empty ())
235 Paper_system *ps = new Paper_system (title, true);
236 set_system_penalty (ps, header_);
238 systems_ = scm_cons (ps->self_scm (), systems_);
239 scm_gc_unprotect_object (ps->self_scm ());
242 int score_count = score_systems_.size ();
243 for (int i = 0; i < score_count; i++)
245 Stencil title = score_title (i);
246 if (!title.is_empty ())
248 Paper_system *ps = new Paper_system (title, true);
249 systems_ = scm_cons (ps->self_scm (), systems_);
250 scm_gc_unprotect_object (ps->self_scm ());
252 set_system_penalty (ps, score_systems_[i].header_);
256 if (scm_vector_p (score_systems_[i].systems_) == SCM_BOOL_T)
259 SCM system_list = scm_vector_to_list (score_systems_[i].systems_);
261 system_list = scm_reverse (system_list);
262 systems_ = scm_append (scm_list_2 (system_list, systems_));
266 systems_ = scm_reverse (systems_);
269 Paper_system *last = 0;
270 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
272 Paper_system *ps = unsmob_paper_system (scm_car (s));
277 && !ps->break_before_penalty_)
278 ps->break_before_penalty_ = 10000;
288 if (SCM_BOOL_F != pages_)
292 SCM proc = paper_->c_variable ("page-breaking");
293 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
298 /****************************************************************/
300 Score_systems::Score_systems ()
307 Score_systems::gc_mark ()
309 scm_gc_mark (systems_);
310 scm_gc_mark (header_);