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 ()
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);
68 for (int i = dump_header_fieldnames_global.size (); i--; )
70 = scm_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
76 Paper_book::output (String outname)
78 if (!score_systems_.size ())
81 /* Generate all stencils to trigger font loads. */
85 if (ly_c_module_p (header_))
86 scopes = scm_cons (header_, scopes);
88 String mod_nm = "scm framework-" + output_backend_global;
90 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
93 SCM func = scm_c_module_lookup (mod, "output-framework");
95 func = scm_variable_ref (func);
96 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
105 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
106 func = scm_variable_ref (func);
107 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
113 progress_indication ("\n");
117 Paper_book::classic_output (String outname)
119 /* Generate all stencils to trigger font loads. */
123 SCM scopes = SCM_EOL;
124 if (ly_c_module_p (header_))
125 scopes = scm_cons (header_, scopes);
127 if (ly_c_module_p (score_systems_[0].header_))
128 scopes = scm_cons (score_systems_[0].header_, scopes);
131 String format = output_backend_global;
132 String mod_nm = "scm framework-" + format;
134 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
135 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
138 func = scm_variable_ref (func);
139 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
145 progress_indication ("\n");
149 /* TODO: resurrect more complex user-tweaks for titling? */
151 Paper_book::book_title ()
153 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
156 SCM scopes = SCM_EOL;
157 if (ly_c_module_p (header_))
158 scopes = scm_cons (header_, scopes);
162 if (ly_c_procedure_p (title_func))
163 tit = scm_call_2 (title_func,
167 if (unsmob_stencil (tit))
168 title = *unsmob_stencil (tit);
170 if (!title.is_empty ())
171 title.align_to (Y_AXIS, UP);
177 Paper_book::score_title (int i)
179 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
184 SCM scopes = SCM_EOL;
185 if (ly_c_module_p (header_))
186 scopes = scm_cons (header_, scopes);
188 if (ly_c_module_p (score_systems_[i].header_))
189 scopes = scm_cons (score_systems_[i].header_, scopes);
193 if (ly_c_procedure_p (title_func))
194 tit = scm_call_2 (title_func,
198 if (unsmob_stencil (tit))
199 title = *unsmob_stencil (tit);
201 if (!title.is_empty ())
202 title.align_to (Y_AXIS, UP);
208 set_system_penalty (Paper_system * ps, SCM header)
210 if (ly_c_module_p (header))
212 SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
213 if (SCM_VARIABLEP(force)
214 && scm_is_bool (SCM_VARIABLE_REF(force)))
216 ps->break_before_penalty_ = to_boolean (SCM_VARIABLE_REF(force))
224 Paper_book::systems ()
226 if (systems_ != SCM_BOOL_F)
230 Stencil title = book_title ();
232 if (!title.is_empty ())
234 Paper_system *ps = new Paper_system (title, true);
235 set_system_penalty (ps, header_);
237 systems_ = scm_cons (ps->self_scm (), systems_);
238 scm_gc_unprotect_object (ps->self_scm ());
242 = scm_call_1 (ly_lily_module_constant ("layout-extract-page-properties"),
243 paper_->self_scm ());
245 int score_count = score_systems_.size ();
246 for (int i = 0; i < score_count; i++)
248 Stencil title = score_title (i);
249 if (!title.is_empty ())
251 Paper_system *ps = new Paper_system (title, true);
252 systems_ = scm_cons (ps->self_scm (), systems_);
253 scm_gc_unprotect_object (ps->self_scm ());
255 set_system_penalty (ps, score_systems_[i].header_);
259 if (scm_vector_p (score_systems_[i].systems_) == SCM_BOOL_T)
262 SCM system_list = scm_vector_to_list (score_systems_[i].systems_);
264 system_list = scm_reverse (system_list);
265 systems_ = scm_append (scm_list_2 (system_list, systems_));
268 for (SCM s = score_systems_[i].texts_; s != SCM_EOL; s = scm_cdr (s))
270 SCM t = Text_interface::interpret_markup (paper_->self_scm (),
273 // FIXME: title=true?
274 Paper_system *ps = new Paper_system (*unsmob_stencil (t), true);
275 systems_ = scm_cons (ps->self_scm (), systems_);
276 scm_gc_unprotect_object (ps->self_scm ());
277 // FIXME: figure out penalty.
278 //set_system_penalty (ps, score_systems_[i].header_);
282 systems_ = scm_reverse (systems_);
285 Paper_system *last = 0;
286 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
288 Paper_system *ps = unsmob_paper_system (scm_car (s));
293 && !ps->break_before_penalty_)
294 ps->break_before_penalty_ = 10000;
304 if (SCM_BOOL_F != pages_)
308 SCM proc = paper_->c_variable ("page-breaking");
309 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
314 /****************************************************************/
316 Score_systems::Score_systems ()
324 Score_systems::gc_mark ()
326 scm_gc_mark (systems_);
327 scm_gc_mark (header_);
328 scm_gc_mark (texts_);