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 ()),
123 Paper_book::classic_output (String outname)
125 /* 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);
132 if (ly_c_module_p (header_0_))
133 scopes = scm_cons (header_0_, scopes);
135 String format = output_backend_global;
136 String mod_nm = "scm framework-" + format;
138 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
139 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
141 func = scm_variable_ref (func);
142 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
148 progress_indication ("\n");
151 /* TODO: resurrect more complex user-tweaks for titling? */
153 Paper_book::book_title ()
155 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
158 SCM scopes = SCM_EOL;
159 if (ly_c_module_p (header_))
160 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 (SCM header)
180 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 (header))
189 scopes = scm_cons (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::add_score_title (SCM header)
225 Stencil title = score_title (header);
226 if (title.is_empty ())
227 title = score_title (header_);
228 if (!title.is_empty ())
230 Paper_system *ps = new Paper_system (title, true);
231 systems_ = scm_cons (ps->self_scm (), systems_);
232 scm_gc_unprotect_object (ps->self_scm ());
233 set_system_penalty (ps, header);
238 Paper_book::systems ()
240 if (systems_ != SCM_BOOL_F)
244 Stencil title = book_title ();
246 if (!title.is_empty ())
248 Paper_system *ps = new Paper_system (title, true);
249 set_system_penalty (ps, header_);
251 systems_ = scm_cons (ps->self_scm (), systems_);
252 scm_gc_unprotect_object (ps->self_scm ());
256 = scm_call_1 (ly_lily_module_constant ("layout-extract-page-properties"),
257 paper_->self_scm ());
259 SCM header = SCM_EOL;
260 for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
262 if (ly_c_module_p (scm_car (s)))
264 header = scm_car (s);
265 if (header_0_ == SCM_EOL)
268 else if (Music_output *mop = unsmob_music_output (scm_car (s)))
271 if (Paper_score *pscore = dynamic_cast<Paper_score *> (mop))
273 add_score_title (header);
277 SCM system_list = scm_vector_to_list (pscore->get_paper_systems ());
278 system_list = scm_reverse (system_list);
279 systems_ = scm_append (scm_list_2 (system_list, systems_));
288 else if (scm_is_vector (scm_car (s)))
293 add_score_title (header);
296 SCM system_list = scm_vector_to_list (scm_car (s));
297 system_list = scm_reverse (system_list);
298 systems_ = scm_append (scm_list_2 (system_list, systems_));
300 else if (Text_interface::markup_p (scm_car (s)))
302 SCM t = Text_interface::interpret_markup (paper_->self_scm (),
305 // FIXME: title=true?
306 Paper_system *ps = new Paper_system (*unsmob_stencil (t), true);
307 systems_ = scm_cons (ps->self_scm (), systems_);
308 scm_gc_unprotect_object (ps->self_scm ());
309 // FIXME: figure out penalty.
310 //set_system_penalty (ps, scores_[i].header_);
316 systems_ = scm_reverse (systems_);
319 Paper_system *last = 0;
320 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
322 Paper_system *ps = unsmob_paper_system (scm_car (s));
327 && !ps->break_before_penalty_)
328 ps->break_before_penalty_ = 10000;
338 if (SCM_BOOL_F != pages_)
342 SCM proc = paper_->c_variable ("page-breaking");
343 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));