]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-score.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / paper-score.cc
1 /*
2   paper-score.cc -- implement Paper_score
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "paper-score.hh"
10
11 #include "all-font-metrics.hh"
12 #include "book.hh"
13 #include "gourlay-breaking.hh"
14 #include "international.hh"
15 #include "main.hh"
16 #include "misc.hh"
17 #include "output-def.hh"
18 #include "paper-book.hh"
19 #include "paper-column.hh"
20 #include "scm-hash.hh"
21 #include "score.hh"
22 #include "stencil.hh"
23 #include "system.hh"
24 #include "warn.hh"
25 #include "constrained-breaking.hh"
26
27 Paper_score::Paper_score (Output_def *layout)
28 {
29   layout_ = layout;
30   system_ = 0;
31   systems_ = SCM_EOL;
32   paper_systems_ = SCM_BOOL_F;
33 }
34
35 Paper_score::Paper_score (Paper_score const &s)
36   : Music_output (s)
37 {
38   assert (false);
39 }
40
41 void
42 Paper_score::derived_mark () const
43 {
44   if (layout_)
45     scm_gc_mark (layout_->self_scm ());
46   scm_gc_mark (systems_);
47   scm_gc_mark (paper_systems_);
48 }
49
50 void
51 Paper_score::typeset_system (System *system)
52 {
53   if (!system_)
54     system_ = system;
55
56   systems_ = scm_cons (system->self_scm (), systems_);
57   system->pscore_ = this;
58   system->layout_ = layout_;
59   system->unprotect ();
60 }
61
62
63 vector<vsize>
64 Paper_score::find_break_indices () const
65 {
66   vector<Grob*> all = root_system ()->columns ();
67   vector<vsize> retval;
68
69   for (vsize i = 0; i < all.size (); i++)
70     {
71       Item *it = dynamic_cast<Item*> (all[i]);
72       if (Paper_column::is_breakable (all[i])
73           && (i == 0 || it->find_prebroken_piece (LEFT))
74           && (i == all.size () - 1 || it->find_prebroken_piece (RIGHT)))
75         retval.push_back (i);
76     }
77
78   return retval;
79 }
80
81
82 vector<Column_x_positions>
83 Paper_score::calc_breaking ()
84 {
85   Break_algorithm *algorithm = 0;
86   vector<Column_x_positions> sol;
87
88   message (_ ("Calculating line breaks...") + " ");
89
90   int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0);
91   if (system_count)
92     {
93       Constrained_breaking *b = new Constrained_breaking;
94       b->resize (system_count);
95       algorithm = b;
96     }
97   else
98     algorithm = new Gourlay_breaking;
99   
100   algorithm->set_pscore (this);
101   sol = algorithm->solve ();
102   delete algorithm;
103
104   return sol;
105 }
106
107 void
108 Paper_score::process ()
109 {
110   if (be_verbose_global)
111     message (_f ("Element count %d (spanners %d) ",
112                  system_->element_count (),
113                  system_->spanner_count ()));
114
115   message (_ ("Preprocessing graphical objects...") + " ");
116
117   /* FIXME: Check out why we need this - removing gives assertion failures
118      down the road.
119
120      doubly, also done in Score_engraver */
121   vector<Grob*> pc (system_->columns ());
122   pc[0]->set_property ("line-break-permission", ly_symbol2scm ("allow"));
123   pc.back ()->set_property ("line-break-permission", ly_symbol2scm ("allow"));
124
125   system_->pre_processing ();
126 }
127
128 System *
129 Paper_score::root_system () const
130 {
131   return system_;
132 }
133
134 Output_def *
135 Paper_score::layout () const
136 {
137   return layout_;
138 }
139
140 SCM
141 Paper_score::get_paper_systems ()
142 {
143   if (paper_systems_ == SCM_BOOL_F)
144     {
145       vector<Column_x_positions> breaking = calc_breaking ();
146       system_->break_into_pieces (breaking);
147       message (_ ("Drawing systems...") + " ");
148       paper_systems_ = system_->get_paper_systems ();
149     }
150   return paper_systems_;
151 }
152