]> git.donarmstrong.com Git - lilypond.git/blob - lily/book.cc
(ly_bookpaper_fonts): move from Paperdef
[lilypond.git] / lily / book.cc
1 /*
2   book.cc -- implement Book
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <stdio.h>
10
11 #include "book-paper-def.hh"
12 #include "ly-smobs.icc"
13 #include "stencil.hh"
14 #include "book.hh"
15 #include "global-context.hh"
16 #include "ly-module.hh"
17 #include "main.hh"
18 #include "music-iterator.hh"
19 #include "music-output-def.hh"
20 #include "music-output.hh"
21 #include "music.hh"
22 #include "page.hh"
23 #include "paper-book.hh"
24 #include "paper-def.hh"
25 #include "score.hh"
26 #include "warn.hh"
27
28 Book::Book ()
29   : Input ()
30 {
31   bookpaper_ = 0;
32   header_ = SCM_EOL;
33   assert (!scores_.size ());
34   smobify_self ();
35 }
36
37 Book::~Book ()
38 {
39 }
40
41 IMPLEMENT_SMOBS (Book);
42 IMPLEMENT_DEFAULT_EQUAL_P (Book);
43
44 SCM
45 Book::mark_smob (SCM s)
46 {
47   Book *book = (Book*) SCM_CELL_WORD_1 (s);
48   int score_count = book->scores_.size ();
49   for (int i = 0; i < score_count; i++)
50     scm_gc_mark (book->scores_[i]->self_scm ());
51
52   if (book->bookpaper_)
53     scm_gc_mark (book->bookpaper_->self_scm ());
54   return book->header_;
55 }
56
57 int
58 Book::print_smob (SCM, SCM p, scm_print_state*)
59 {
60   scm_puts ("#<Book>", p);
61   return 1;
62 }
63
64 void
65 Book::process (String outname, Music_output_def *default_def, SCM header)
66 {
67   Paper_book *paper_book = new Paper_book ();
68   int score_count = scores_.size ();
69   for (int i = 0; i < score_count; i++)
70     {
71       Paper_def *paper = 0;
72       SCM systems = scores_[i]->book_rendering (outname,
73                                                 bookpaper_,
74                                                 default_def, &paper);
75       if (systems != SCM_UNDEFINED)
76         {
77           Score_lines sc;
78           sc.paper_ = paper;
79           sc.lines_ = systems;
80           sc.header_ = header;
81
82           paper_book->score_lines_.push (sc);
83         }
84     }
85   paper_book->output (outname);
86   scm_gc_unprotect_object (paper_book->self_scm ());
87 }
88
89 /* FIXME: WIP, this is a hack.  Return first page as stencil.  */
90 SCM
91 Book::to_stencil (Music_output_def *default_def, SCM header)
92 {
93   Paper_book *paper_book = new Paper_book ();
94   int score_count = scores_.size ();
95   for (int i = 0; i < score_count; i++)
96     {
97       Paper_def *paper = 0;
98       SCM systems = scores_[i]->book_rendering ("<markup>",
99                                                 bookpaper_,
100                                                 default_def,
101                                                 &paper);
102       if (systems != SCM_UNDEFINED)
103         {
104           Score_lines sc;
105           sc.paper_ = paper;
106           sc.lines_ = systems;
107           sc.header_ =header;
108
109           paper_book->score_lines_.push (sc);
110
111           // wtf: code dup.
112         }
113     }
114
115   SCM pages = paper_book->pages ();
116   paper_book = 0;
117   if (pages != SCM_EOL)
118     {
119       progress_indication (_f ("paper output to `%s'...", "<markup>"));
120       return (unsmob_page (ly_car (pages)))->to_stencil ().smobbed_copy ();
121     }
122   return SCM_EOL;
123 }