Consider accidentals in optical spacing correction.
[lilypond.git] / lily / paper-score.cc
blob7ae0854e984c3283799b59754c3b2a2687ffdafb
1 /*
2 paper-score.cc -- implement Paper_score
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "paper-score.hh"
11 #include "all-font-metrics.hh"
12 #include "book.hh"
13 #include "international.hh"
14 #include "main.hh"
15 #include "misc.hh"
16 #include "output-def.hh"
17 #include "paper-book.hh"
18 #include "paper-column.hh"
19 #include "scm-hash.hh"
20 #include "score.hh"
21 #include "stencil.hh"
22 #include "system.hh"
23 #include "warn.hh"
24 #include "constrained-breaking.hh"
26 Paper_score::Paper_score (Output_def *layout)
28 layout_ = layout;
29 system_ = 0;
30 systems_ = SCM_EOL;
31 paper_systems_ = SCM_BOOL_F;
34 Paper_score::Paper_score (Paper_score const &s)
35 : Music_output (s)
37 assert (false);
40 void
41 Paper_score::derived_mark () const
43 if (layout_)
44 scm_gc_mark (layout_->self_scm ());
45 scm_gc_mark (systems_);
46 scm_gc_mark (paper_systems_);
49 void
50 Paper_score::typeset_system (System *system)
52 if (!system_)
53 system_ = system;
55 systems_ = scm_cons (system->self_scm (), systems_);
56 system->pscore_ = this;
57 system->layout_ = layout_;
58 system->unprotect ();
62 vector<vsize>
63 Paper_score::find_break_indices () const
65 vector<Grob*> all = root_system ()->used_columns ();
66 vector<vsize> retval;
68 for (vsize i = 0; i < all.size (); i++)
70 Item *it = dynamic_cast<Item*> (all[i]);
71 if (Paper_column::is_breakable (all[i])
72 && (i == 0 || it->find_prebroken_piece (LEFT))
73 && (i == all.size () - 1 || it->find_prebroken_piece (RIGHT)))
74 retval.push_back (i);
77 cols_ = all;
78 break_indices_ = retval;
80 return retval;
83 vector<vsize>
84 Paper_score::get_break_indices () const
86 if (break_indices_.empty ())
87 find_break_indices ();
88 return break_indices_;
91 vector<Grob*>
92 Paper_score::get_columns () const
94 if (cols_.empty ())
95 find_break_indices ();
96 return cols_;
99 vector<Column_x_positions>
100 Paper_score::calc_breaking ()
102 Constrained_breaking algorithm (this);
103 vector<Column_x_positions> sol;
105 message (_ ("Calculating line breaks...") + " ");
107 int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0);
108 if (system_count)
109 return algorithm.solve (0, VPOS, system_count);
111 return algorithm.best_solution (0, VPOS);
114 void
115 Paper_score::process ()
117 if (be_verbose_global)
118 message (_f ("Element count %d (spanners %d) ",
119 system_->element_count (),
120 system_->spanner_count ()));
122 message (_ ("Preprocessing graphical objects..."));
124 system_->pre_processing ();
127 System *
128 Paper_score::root_system () const
130 return system_;
133 Output_def *
134 Paper_score::layout () const
136 return layout_;
140 Paper_score::get_paper_systems ()
142 if (paper_systems_ == SCM_BOOL_F)
144 vector<Column_x_positions> breaking = calc_breaking ();
145 system_->break_into_pieces (breaking);
146 message (_ ("Drawing systems...") + " ");
147 system_->do_break_substitution_and_fixup_refpoints ();
148 paper_systems_ = system_->get_paper_systems ();
150 return paper_systems_;
154 Paper_score *
155 unsmob_paper_score (SCM x)
157 return dynamic_cast<Paper_score*> (unsmob_music_output (x));