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-interface.hh"
18 #include "ly-smobs.icc"
20 Paper_book::Paper_book ()
26 performances_ = SCM_EOL;
27 systems_ = SCM_BOOL_F;
33 Paper_book::~Paper_book ()
37 IMPLEMENT_DEFAULT_EQUAL_P (Paper_book);
38 IMPLEMENT_SMOBS (Paper_book);
39 IMPLEMENT_TYPE_P (Paper_book, "ly:paper-book?");
42 Paper_book::mark_smob (SCM smob)
44 Paper_book *b = (Paper_book *) SCM_CELL_WORD_1 (smob);
46 scm_gc_mark (b->paper_->self_scm ());
47 scm_gc_mark (b->header_);
48 scm_gc_mark (b->header_0_);
49 scm_gc_mark (b->pages_);
50 scm_gc_mark (b->performances_);
51 scm_gc_mark (b->scores_);
56 Paper_book::print_smob (SCM smob, SCM port, scm_print_state*)
58 Paper_book *b = (Paper_book *) SCM_CELL_WORD_1 (smob);
60 scm_puts ("#<", port);
61 scm_puts (classname (b), port);
71 for (int i = dump_header_fieldnames_global.size (); i--;)
73 = scm_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
79 Paper_book::add_score (SCM s)
81 scores_ = scm_cons (s, scores_);
85 Paper_book::add_performance (SCM s)
87 performances_ = scm_cons (s, performances_);
91 Paper_book::output (SCM output_channel)
93 if (scores_ == SCM_EOL)
96 /* Generate all stencils to trigger font loads. */
100 if (ly_is_module (header_))
101 scopes = scm_cons (header_, scopes);
103 String mod_nm = "scm framework-" + output_backend_global;
105 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
108 SCM func = scm_c_module_lookup (mod, "output-framework");
110 func = scm_variable_ref (func);
111 scm_apply_0 (func, scm_list_n (output_channel,
120 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
121 func = scm_variable_ref (func);
122 scm_apply_0 (func, scm_list_n (output_channel,
131 Paper_book::classic_output (SCM output)
133 /* Generate all stencils to trigger font loads. */
136 SCM scopes = SCM_EOL;
137 if (ly_is_module (header_))
138 scopes = scm_cons (header_, scopes);
140 if (ly_is_module (header_0_))
141 scopes = scm_cons (header_0_, scopes);
143 String format = output_backend_global;
144 String mod_nm = "scm framework-" + format;
146 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
147 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
149 func = scm_variable_ref (func);
150 scm_apply_0 (func, scm_list_n (output,
156 progress_indication ("\n");
159 /* TODO: resurrect more complex user-tweaks for titling? */
161 Paper_book::book_title ()
163 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
166 SCM scopes = SCM_EOL;
167 if (ly_is_module (header_))
168 scopes = scm_cons (header_, scopes);
171 if (ly_is_procedure (title_func))
172 tit = scm_call_2 (title_func,
176 if (unsmob_stencil (tit))
177 title = *unsmob_stencil (tit);
179 if (!title.is_empty ())
180 title.align_to (Y_AXIS, UP);
186 Paper_book::score_title (SCM header)
188 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
192 SCM scopes = SCM_EOL;
193 if (ly_is_module (header_))
194 scopes = scm_cons (header_, scopes);
196 if (ly_is_module (header))
197 scopes = scm_cons (header, scopes);
200 if (ly_is_procedure (title_func))
201 tit = scm_call_2 (title_func,
205 if (unsmob_stencil (tit))
206 title = *unsmob_stencil (tit);
208 if (!title.is_empty ())
209 title.align_to (Y_AXIS, UP);
215 set_system_penalty (Paper_system *ps, SCM header)
217 if (ly_is_module (header))
219 SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
220 if (SCM_VARIABLEP (force)
221 && scm_is_bool (SCM_VARIABLE_REF (force)))
223 ps->break_before_penalty_ = to_boolean (SCM_VARIABLE_REF (force))
231 Paper_book::add_score_title (SCM header)
233 Stencil title = score_title (header);
234 if (title.is_empty ())
235 title = score_title (header_);
236 if (!title.is_empty ())
238 Paper_system *ps = new Paper_system (title, true);
239 systems_ = scm_cons (ps->self_scm (), systems_);
241 set_system_penalty (ps, header);
246 Paper_book::systems ()
248 if (systems_ != SCM_BOOL_F)
252 Stencil title = book_title ();
254 if (!title.is_empty ())
256 Paper_system *ps = new Paper_system (title, true);
257 set_system_penalty (ps, header_);
259 systems_ = scm_cons (ps->self_scm (), systems_);
264 = scm_call_1 (ly_lily_module_constant ("layout-extract-page-properties"),
265 paper_->self_scm ());
267 SCM header = SCM_EOL;
268 for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
270 if (ly_is_module (scm_car (s)))
272 header = scm_car (s);
273 if (header_0_ == SCM_EOL)
276 else if (Music_output *mop = unsmob_music_output (scm_car (s)))
279 if (Paper_score *pscore = dynamic_cast<Paper_score *> (mop))
281 add_score_title (header);
285 SCM system_list = scm_vector_to_list (pscore->get_paper_systems ());
286 system_list = scm_reverse (system_list);
287 systems_ = scm_append (scm_list_2 (system_list, systems_));
296 else if (scm_is_vector (scm_car (s)))
301 add_score_title (header);
304 SCM system_list = scm_vector_to_list (scm_car (s));
305 system_list = scm_reverse (system_list);
306 systems_ = scm_append (scm_list_2 (system_list, systems_));
308 else if (Text_interface::is_markup (scm_car (s)))
310 SCM t = Text_interface::interpret_markup (paper_->self_scm (),
313 // FIXME: title=true?
314 Paper_system *ps = new Paper_system (*unsmob_stencil (t), true);
315 systems_ = scm_cons (ps->self_scm (), systems_);
317 // FIXME: figure out penalty.
318 //set_system_penalty (ps, scores_[i].header_);
324 systems_ = scm_reverse (systems_);
327 Paper_system *last = 0;
328 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
330 Paper_system *ps = unsmob_paper_system (scm_car (s));
335 && !ps->break_before_penalty_)
336 ps->break_before_penalty_ = 10000;
346 if (SCM_BOOL_F != pages_)
350 SCM proc = paper_->c_variable ("page-breaking");
351 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
356 Paper_book::performances () const
358 return scm_reverse (performances_);