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"
11 #include "ly-module.hh"
13 #include "output-def.hh"
14 #include "paper-outputter.hh"
15 #include "paper-score.hh"
16 #include "paper-system.hh"
19 #include "ly-smobs.icc"
21 Paper_book::Paper_book ()
24 systems_ = SCM_BOOL_F;
31 Paper_book::~Paper_book ()
35 IMPLEMENT_DEFAULT_EQUAL_P (Paper_book);
36 IMPLEMENT_SMOBS (Paper_book)
37 IMPLEMENT_TYPE_P (Paper_book, "ly:paper-book?")
40 Paper_book::mark_smob (SCM smob)
42 Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob);
43 for (int i = 0; i < b->score_systems_.size (); i++)
44 b->score_systems_[i].gc_mark ();
47 scm_gc_mark (b->paper_->self_scm ());
48 scm_gc_mark (b->header_);
49 scm_gc_mark (b->pages_);
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);
61 //scm_puts (b->, port);
67 split_string (String s, char c)
76 s = s.nomid_string (0, 1);
83 rv.push (s.cut_string (0, i));
84 s = s.nomid_string (0, i);
94 for (int i = dump_header_fieldnames_global.size (); i--; )
96 = scm_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
102 Paper_book::post_processing (SCM module,
108 char const *func_name_;
110 {make_tex, "convert-to-tex"},
111 {make_dvi, "convert-to-dvi"},
112 {make_ps, "convert-to-ps"},
113 {make_pdf, "convert-to-pdf"},
114 {make_png, "convert-to-png"},
118 for (int i = 0; settings[i].func_name_; i++)
120 if (settings[i].do_it_)
122 SCM func = scm_c_module_lookup (module, settings[i].func_name_);
123 if (scm_variable_p (func) == SCM_BOOL_T)
125 func = scm_variable_ref (func);
126 if (ly_c_procedure_p (func))
127 scm_call_2 (func, self_scm (), file_name);
134 Paper_book::output (String outname)
136 if (!score_systems_.size ())
139 /* Generate all stencils to trigger font loads. */
142 String format = output_backend_global;
143 String file_name = outname;
145 if (file_name != "-")
146 file_name += "." + format;
148 Paper_outputter *out = get_paper_outputter (file_name, format);
150 SCM scopes = SCM_EOL;
151 if (ly_c_module_p (header_))
152 scopes = scm_cons (header_, scopes);
154 String mod_nm = "scm framework-" + format;
156 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
159 SCM func = scm_c_module_lookup (mod, "output-framework");
161 func = scm_variable_ref (func);
162 scm_apply_0 (func, scm_list_n (out->self_scm (),
166 scm_makfrom0str (outname.to_str0 ()),
169 scm_gc_unprotect_object (out->self_scm ());
170 post_processing (mod, scm_makfrom0str (file_name.to_str0 ()));
175 String file_name = outname + ".preview." + format;
176 Paper_outputter *out = get_paper_outputter (file_name, format);
178 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
179 func = scm_variable_ref (func);
180 scm_apply_0 (func, scm_list_n (out->self_scm (),
184 scm_makfrom0str (outname.to_str0 ()),
188 scm_gc_unprotect_object (out->self_scm ());
190 post_processing (mod, scm_makfrom0str (file_name.to_str0 ()));
192 progress_indication ("\n");
196 Paper_book::classic_output (String outname)
198 /* Generate all stencils to trigger font loads. */
202 SCM scopes = SCM_EOL;
203 if (ly_c_module_p (header_))
204 scopes = scm_cons (header_, scopes);
206 if (ly_c_module_p (score_systems_[0].header_))
207 scopes = scm_cons (score_systems_[0].header_, scopes);
210 String format = output_backend_global;
211 String mod_nm = "scm framework-" + format;
213 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
214 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
216 func = scm_variable_ref (func);
218 Paper_outputter *out = get_paper_outputter (outname + "." + format,
221 scm_apply_0 (func, scm_list_n (out->self_scm (), self_scm (), scopes,
223 scm_makfrom0str (outname.to_str0 ()),
226 scm_gc_unprotect_object (out->self_scm ());
227 progress_indication ("\n");
230 LY_DEFINE (ly_paper_book_pages, "ly:paper-book-pages",
232 "Return pages in book PB.")
234 return unsmob_paper_book(pb)->pages ();
237 LY_DEFINE (ly_paper_book_scopes, "ly:paper-book-scopes",
239 "Return pages in layout book @var{book}.")
241 Paper_book *pb = unsmob_paper_book(book);
242 SCM_ASSERT_TYPE(pb, book, SCM_ARG1, __FUNCTION__, "Paper_book");
244 SCM scopes = SCM_EOL;
245 if (ly_c_module_p (pb->header_))
246 scopes = scm_cons (pb->header_, scopes);
251 LY_DEFINE (ly_paper_book_systems, "ly:paper-book-systems",
253 "Return systems in book PB.")
255 return unsmob_paper_book (pb)->systems ();
258 LY_DEFINE (ly_paper_book_paper, "ly:paper-book-paper",
260 "Return pages in book PB.")
262 return unsmob_paper_book (pb)->paper_->self_scm ();
265 /* TODO: resurrect more complex user-tweaks for titling? */
267 Paper_book::book_title ()
269 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
272 SCM scopes = SCM_EOL;
273 if (ly_c_module_p (header_))
274 scopes = scm_cons (header_, scopes);
278 if (ly_c_procedure_p (title_func))
279 tit = scm_call_2 (title_func,
283 if (unsmob_stencil (tit))
284 title = *unsmob_stencil (tit);
286 if (!title.is_empty ())
287 title.align_to (Y_AXIS, UP);
293 Paper_book::score_title (int i)
295 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
300 SCM scopes = SCM_EOL;
301 if (ly_c_module_p (header_))
302 scopes = scm_cons (header_, scopes);
304 if (ly_c_module_p (score_systems_[i].header_))
305 scopes = scm_cons (score_systems_[i].header_, scopes);
309 if (ly_c_procedure_p (title_func))
310 tit = scm_call_2 (title_func,
314 if (unsmob_stencil (tit))
315 title = *unsmob_stencil (tit);
317 if (!title.is_empty ())
318 title.align_to (Y_AXIS, UP);
324 set_system_penalty (Paper_system * ps, SCM header)
326 if (ly_c_module_p (header))
328 SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
329 if (SCM_VARIABLEP(force)
330 && scm_is_bool (SCM_VARIABLE_REF(force)))
332 ps->break_before_penalty_ = to_boolean (SCM_VARIABLE_REF(force))
340 Paper_book::systems ()
342 if (systems_ != SCM_BOOL_F)
346 Stencil title = book_title ();
348 if (!title.is_empty ())
350 Paper_system *ps = new Paper_system (title, true);
351 set_system_penalty (ps, header_);
353 systems_ = scm_cons (ps->self_scm (), systems_);
354 scm_gc_unprotect_object (ps->self_scm ());
357 int score_count = score_systems_.size ();
358 for (int i = 0; i < score_count; i++)
360 Stencil title = score_title (i);
361 if (!title.is_empty ())
363 Paper_system *ps = new Paper_system (title, true);
364 systems_ = scm_cons (ps->self_scm (), systems_);
365 scm_gc_unprotect_object (ps->self_scm ());
367 set_system_penalty (ps, score_systems_[i].header_);
371 if (scm_vector_p (score_systems_[i].systems_) == SCM_BOOL_T)
374 SCM system_list = scm_vector_to_list (score_systems_[i].systems_);
376 system_list = scm_reverse (system_list);
377 systems_ = scm_append (scm_list_2 (system_list, systems_));
381 systems_ = scm_reverse (systems_);
384 Paper_system *last = 0;
385 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
387 Paper_system *ps = unsmob_paper_system (scm_car (s));
392 && !ps->break_before_penalty_)
393 ps->break_before_penalty_ = 10000;
403 if (SCM_BOOL_F != pages_)
407 SCM proc = paper_->c_variable ("page-breaking");
408 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
413 /****************************************************************/
415 Score_systems::Score_systems ()
422 Score_systems::gc_mark ()
424 scm_gc_mark (systems_);
425 scm_gc_mark (header_);