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 "ly-module.hh"
11 #include "output-def.hh"
12 #include "paper-book.hh"
13 #include "paper-outputter.hh"
14 #include "paper-score.hh"
15 #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 ()),
101 LY_DEFINE (ly_output_formats, "ly:output-formats",
103 "Formats passed to --format as a list of strings, "
104 "used for the output.")
106 Array<String> output_formats = split_string (output_format_global, ',');
109 int output_formats_count = output_formats.size ();
110 for (int i = 0; i < output_formats_count; i ++)
111 lst = scm_cons (scm_makfrom0str (output_formats[i].to_str0 ()), lst);
117 Paper_book::post_processing (SCM module,
123 char const *func_name_;
125 {make_tex, "convert-to-tex"},
126 {make_dvi, "convert-to-dvi"},
127 {make_ps, "convert-to-ps"},
128 {make_pdf, "convert-to-pdf"},
129 {make_png, "convert-to-png"},
133 for (int i= 0; settings[i].func_name_; i++)
135 if (settings[i].do_it_)
137 SCM func = scm_c_module_lookup (module, settings[i].func_name_);
138 if (scm_variable_p (func) == SCM_BOOL_T)
140 func = scm_variable_ref (func);
141 if (ly_c_procedure_p (func))
142 scm_call_2 (func, self_scm(), file_name);
149 Paper_book::output (String outname)
151 if (!score_systems_.size ())
154 /* Generate all stencils to trigger font loads. */
157 SCM formats = ly_output_formats ();
158 for (SCM s = formats; scm_is_pair (s); s = scm_cdr (s))
160 String format = ly_scm2string (scm_car (s));
161 String file_name = outname;
163 if (file_name != "-")
164 file_name += "." + format;
166 Paper_outputter *out = get_paper_outputter (file_name, format);
168 SCM scopes = SCM_EOL;
169 if (ly_c_module_p (header_))
170 scopes = scm_cons (header_, scopes);
172 String mod_nm = "scm framework-" + format;
174 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
177 SCM func = scm_c_module_lookup (mod, "output-framework");
179 func = scm_variable_ref (func);
180 scm_apply_0 (func, scm_list_n (out->self_scm (),
184 scm_makfrom0str (outname.to_str0 ()),
187 scm_gc_unprotect_object (out->self_scm ());
188 post_processing (mod, scm_makfrom0str (file_name.to_str0 ()));
193 String file_name = outname + ".preview." + format;
194 Paper_outputter *out = get_paper_outputter (file_name, format);
196 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
197 func = scm_variable_ref (func);
198 scm_apply_0 (func, scm_list_n (out->self_scm (),
202 scm_makfrom0str (outname.to_str0 ()),
206 scm_gc_unprotect_object (out->self_scm ());
208 post_processing (mod, scm_makfrom0str (file_name.to_str0 ()));
211 progress_indication ("\n");
216 Paper_book::classic_output (String outname)
218 /* Generate all stencils to trigger font loads. */
222 SCM scopes = SCM_EOL;
223 if (ly_c_module_p (header_))
224 scopes = scm_cons (header_, scopes);
226 if (ly_c_module_p (score_systems_[0].header_))
227 scopes = scm_cons (score_systems_[0].header_, scopes);
230 Array<String> output_formats = split_string (output_format_global, ',');
232 for (int i = 0; i < output_formats.size (); i++)
234 String format = output_formats[i];
235 String mod_nm = "scm framework-" + format;
237 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
238 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
240 func = scm_variable_ref (func);
242 Paper_outputter *out = get_paper_outputter (outname + "." + format,
245 scm_apply_0 (func, scm_list_n (out->self_scm (), self_scm (), scopes,
247 scm_makfrom0str (outname.to_str0 ()),
250 scm_gc_unprotect_object (out->self_scm ());
251 progress_indication ("\n");
255 LY_DEFINE (ly_paper_book_pages, "ly:paper-book-pages",
257 "Return pages in book PB.")
259 return unsmob_paper_book(pb)->pages ();
262 LY_DEFINE (ly_paper_book_scopes, "ly:paper-book-scopes",
264 "Return pages in layout book @var{book}.")
266 Paper_book *pb = unsmob_paper_book(book);
267 SCM_ASSERT_TYPE(pb, book, SCM_ARG1, __FUNCTION__, "Paper_book");
269 SCM scopes = SCM_EOL;
270 if (ly_c_module_p (pb->header_))
271 scopes = scm_cons (pb->header_, scopes);
276 LY_DEFINE (ly_paper_book_systems, "ly:paper-book-systems",
278 "Return systems in book PB.")
280 return unsmob_paper_book (pb)->systems ();
283 LY_DEFINE (ly_paper_book_paper, "ly:paper-book-paper",
285 "Return pages in book PB.")
287 return unsmob_paper_book (pb)->paper_->self_scm ();
290 /* TODO: resurrect more complex user-tweaks for titling? */
292 Paper_book::book_title ()
294 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
297 SCM scopes = SCM_EOL;
298 if (ly_c_module_p (header_))
299 scopes = scm_cons (header_, scopes);
303 if (ly_c_procedure_p (title_func))
304 tit = scm_call_2 (title_func,
308 if (unsmob_stencil (tit))
309 title = *unsmob_stencil (tit);
311 if (!title.is_empty ())
312 title.align_to (Y_AXIS, UP);
318 Paper_book::score_title (int i)
320 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
325 SCM scopes = SCM_EOL;
326 if (ly_c_module_p (header_))
327 scopes = scm_cons (header_, scopes);
329 if (ly_c_module_p (score_systems_[i].header_))
330 scopes = scm_cons (score_systems_[i].header_, scopes);
334 if (ly_c_procedure_p (title_func))
335 tit = scm_call_2 (title_func,
339 if (unsmob_stencil (tit))
340 title = *unsmob_stencil (tit);
342 if (!title.is_empty ())
343 title.align_to (Y_AXIS, UP);
349 Paper_book::systems ()
351 if (systems_ != SCM_BOOL_F)
355 Stencil title = book_title ();
357 if (!title.is_empty ())
359 Paper_system *ps = new Paper_system (title, true);
360 systems_ = scm_cons (ps->self_scm (), systems_);
361 scm_gc_unprotect_object (ps->self_scm ());
364 int score_count = score_systems_.size ();
365 for (int i = 0; i < score_count; i++)
367 Stencil title = score_title (i);
368 if (!title.is_empty ())
370 Paper_system *ps = new Paper_system (title, true);
371 systems_ = scm_cons (ps->self_scm (), systems_);
372 scm_gc_unprotect_object (ps->self_scm ());
375 if (scm_vector_p (score_systems_[i].systems_) == SCM_BOOL_T)
378 SCM system_list = scm_vector_to_list (score_systems_[i].systems_);
380 system_list = scm_reverse (system_list);
381 systems_ = scm_append (scm_list_2 (system_list, systems_));
385 systems_ = scm_reverse (systems_);
388 Paper_system *last = 0;
389 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
391 Paper_system *ps = unsmob_paper_system (scm_car (s));
394 if (last && last->is_title ())
396 ps->penalty_ = 10000;
406 if (SCM_BOOL_F != pages_)
410 SCM proc = paper_->c_variable ("page-breaking");
411 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
416 /****************************************************************/
418 Score_systems::Score_systems ()
425 Score_systems::gc_mark ()
427 scm_gc_mark (systems_);
428 scm_gc_mark (header_);