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 ()
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_lines_.size (); i++)
44 b->score_lines_[i].gc_mark ();
47 scm_gc_mark (b->bookpaper_->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*) ly_cdr (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::output (String outname)
119 if (!score_lines_.size ())
122 /* Generate all stencils to trigger font loads. */
125 SCM formats = ly_output_formats();
126 for (SCM s = formats; ly_c_pair_p (s); s = ly_cdr (s))
128 String format = ly_scm2string (ly_car (s));
129 Paper_outputter *out = get_paper_outputter (outname + "." + format,
132 SCM scopes = SCM_EOL;
133 if (ly_c_module_p (header_))
134 scopes = scm_cons (header_, scopes);
136 String func_nm = format;
137 func_nm = "output-framework-" + func_nm;
138 String mod_nm = "scm framework-" + format;
140 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
141 SCM func = scm_c_module_lookup (mod, func_nm.to_str0 ());
143 func = scm_variable_ref (func);
144 scm_apply_0 (func, scm_list_n (out->self_scm (),
148 scm_makfrom0str (outname.to_str0 ()),
151 scm_gc_unprotect_object (out->self_scm ());
152 progress_indication ("\n");
157 Paper_book::classic_output (String outname)
159 /* Generate all stencils to trigger font loads. */
163 SCM scopes = SCM_EOL;
164 if (ly_c_module_p (header_))
165 scopes = scm_cons (header_, scopes);
167 if (ly_c_module_p (score_lines_[0].header_))
168 scopes = scm_cons (score_lines_[0].header_, scopes);
171 Array<String> output_formats = split_string (output_format_global, ',');
173 for (int i = 0; i < output_formats.size (); i++)
175 String format = output_formats[i];
176 String func_nm = format;
177 func_nm = "output-classic-framework-" + func_nm;
179 SCM func = ly_scheme_function (func_nm.to_str0 ());
180 Paper_outputter *out = get_paper_outputter (outname + "." + format,
183 scm_apply_0 (func, scm_list_5 (out->self_scm (), self_scm (), scopes,
185 scm_makfrom0str (outname.to_str0 ())));
187 scm_gc_unprotect_object (out->self_scm ());
188 progress_indication ("\n");
192 LY_DEFINE (ly_paper_book_pages, "ly:paper-book-pages",
194 "Return pages in book PB.")
196 return unsmob_paper_book(pb)->pages ();
199 LY_DEFINE (ly_paper_book_scopes, "ly:paper-book-scopes",
201 "Return pages in paper book @var{book}.")
203 Paper_book *pb = unsmob_paper_book(book);
204 SCM_ASSERT_TYPE(pb, book, SCM_ARG1, __FUNCTION__, "Paper_book");
206 SCM scopes = SCM_EOL;
207 if (ly_c_module_p (pb->header_))
208 scopes = scm_cons (pb->header_, scopes);
213 LY_DEFINE (ly_paper_book_lines, "ly:paper-book-lines",
215 "Return lines in book PB.")
217 return unsmob_paper_book (pb)->lines ();
220 LY_DEFINE (ly_paper_book_book_paper, "ly:paper-book-book-paper",
222 "Return pages in book PB.")
224 return unsmob_paper_book (pb)->bookpaper_->self_scm ();
227 /* TODO: resurrect more complex user-tweaks for titling? */
229 Paper_book::book_title ()
231 SCM title_func = bookpaper_->lookup_variable (ly_symbol2scm ("book-title"));
234 SCM scopes = SCM_EOL;
235 if (ly_c_module_p (header_))
236 scopes = scm_cons (header_, scopes);
240 if (ly_c_procedure_p (title_func))
241 tit = scm_call_2 (title_func,
242 bookpaper_->self_scm (),
245 if (unsmob_stencil (tit))
246 title = *unsmob_stencil (tit);
248 if (!title.is_empty ())
249 title.align_to (Y_AXIS, UP);
255 Paper_book::score_title (int i)
257 SCM title_func = bookpaper_->lookup_variable (ly_symbol2scm ("score-title"));
262 SCM scopes = SCM_EOL;
263 if (ly_c_module_p (header_))
264 scopes = scm_cons (header_, scopes);
266 if (ly_c_module_p (score_lines_[i].header_))
267 scopes = scm_cons (score_lines_[i].header_, scopes);
271 if (ly_c_procedure_p (title_func))
272 tit = scm_call_2 (title_func,
273 bookpaper_->self_scm (),
276 if (unsmob_stencil (tit))
277 title = *unsmob_stencil (tit);
279 if (!title.is_empty ())
280 title.align_to (Y_AXIS, UP);
288 if (lines_ != SCM_BOOL_F)
292 Stencil title = book_title ();
294 if (!title.is_empty ())
296 Paper_system *pl = new Paper_system (title, true);
297 lines_ = scm_cons (pl->self_scm (), lines_);
298 scm_gc_unprotect_object (pl->self_scm ());
301 int score_count = score_lines_.size ();
302 for (int i = 0; i < score_count; i++)
304 Stencil title = score_title (i);
305 if (!title.is_empty ())
307 Paper_system *pl = new Paper_system (title, true);
308 lines_ = scm_cons (pl->self_scm (), lines_);
309 scm_gc_unprotect_object (pl->self_scm ());
312 if (scm_vector_p (score_lines_[i].lines_) == SCM_BOOL_T)
315 SCM line_list = scm_vector_to_list (score_lines_[i].lines_);
317 line_list = scm_reverse (line_list);
318 lines_ = scm_append (scm_list_2 (line_list, lines_));
322 lines_ = scm_reverse (lines_);
325 Paper_system *last = 0;
326 for (SCM s = lines_; s != SCM_EOL; s = ly_cdr (s))
328 Paper_system * p = unsmob_paper_line (ly_car (s));
331 if (last && last->is_title ())
343 if (SCM_BOOL_F != pages_)
347 Output_def *paper = bookpaper_;
348 SCM proc = paper->c_variable ("page-breaking");
349 pages_ = scm_apply_0 (proc, scm_list_2 (lines (), self_scm ()));
354 /****************************************************************/
356 Score_lines::Score_lines ()
363 Score_lines::gc_mark ()
365 scm_gc_mark (lines_);
366 scm_gc_mark (header_);