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);
70 for (int i = dump_header_fieldnames_global.size (); i--; )
72 = scm_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
78 Paper_book::output (String outname)
80 if (!score_systems_.size ())
83 /* Generate all stencils to trigger font loads. */
87 if (ly_c_module_p (header_))
88 scopes = scm_cons (header_, scopes);
90 String mod_nm = "scm framework-" + output_backend_global;
92 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
95 SCM func = scm_c_module_lookup (mod, "output-framework");
97 func = scm_variable_ref (func);
98 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
107 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
108 func = scm_variable_ref (func);
109 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
115 progress_indication ("\n");
119 Paper_book::classic_output (String outname)
121 /* Generate all stencils to trigger font loads. */
125 SCM scopes = SCM_EOL;
126 if (ly_c_module_p (header_))
127 scopes = scm_cons (header_, scopes);
129 if (ly_c_module_p (score_systems_[0].header_))
130 scopes = scm_cons (score_systems_[0].header_, scopes);
133 String format = output_backend_global;
134 String mod_nm = "scm framework-" + format;
136 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
137 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
139 func = scm_variable_ref (func);
141 scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
147 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);
164 if (ly_c_procedure_p (title_func))
165 tit = scm_call_2 (title_func,
169 if (unsmob_stencil (tit))
170 title = *unsmob_stencil (tit);
172 if (!title.is_empty ())
173 title.align_to (Y_AXIS, UP);
179 Paper_book::score_title (int i)
181 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
186 SCM scopes = SCM_EOL;
187 if (ly_c_module_p (header_))
188 scopes = scm_cons (header_, scopes);
190 if (ly_c_module_p (score_systems_[i].header_))
191 scopes = scm_cons (score_systems_[i].header_, scopes);
195 if (ly_c_procedure_p (title_func))
196 tit = scm_call_2 (title_func,
200 if (unsmob_stencil (tit))
201 title = *unsmob_stencil (tit);
203 if (!title.is_empty ())
204 title.align_to (Y_AXIS, UP);
210 set_system_penalty (Paper_system * ps, SCM header)
212 if (ly_c_module_p (header))
214 SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
215 if (SCM_VARIABLEP(force)
216 && scm_is_bool (SCM_VARIABLE_REF(force)))
218 ps->break_before_penalty_ = to_boolean (SCM_VARIABLE_REF(force))
226 Paper_book::systems ()
228 if (systems_ != SCM_BOOL_F)
232 Stencil title = book_title ();
234 if (!title.is_empty ())
236 Paper_system *ps = new Paper_system (title, true);
237 set_system_penalty (ps, header_);
239 systems_ = scm_cons (ps->self_scm (), systems_);
240 scm_gc_unprotect_object (ps->self_scm ());
243 int score_count = score_systems_.size ();
244 for (int i = 0; i < score_count; i++)
246 Stencil title = score_title (i);
247 if (!title.is_empty ())
249 Paper_system *ps = new Paper_system (title, true);
250 systems_ = scm_cons (ps->self_scm (), systems_);
251 scm_gc_unprotect_object (ps->self_scm ());
253 set_system_penalty (ps, score_systems_[i].header_);
257 if (scm_vector_p (score_systems_[i].systems_) == SCM_BOOL_T)
260 SCM system_list = scm_vector_to_list (score_systems_[i].systems_);
262 system_list = scm_reverse (system_list);
263 systems_ = scm_append (scm_list_2 (system_list, systems_));
267 systems_ = scm_reverse (systems_);
270 Paper_system *last = 0;
271 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
273 Paper_system *ps = unsmob_paper_system (scm_car (s));
278 && !ps->break_before_penalty_)
279 ps->break_before_penalty_ = 10000;
289 if (SCM_BOOL_F != pages_)
293 SCM proc = paper_->c_variable ("page-breaking");
294 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
299 /****************************************************************/
301 Score_systems::Score_systems ()
308 Score_systems::gc_mark ()
310 scm_gc_mark (systems_);
311 scm_gc_mark (header_);