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