2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1996--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "paper-score.hh"
22 #include "all-font-metrics.hh"
24 #include "international.hh"
27 #include "output-def.hh"
28 #include "paper-book.hh"
29 #include "paper-column.hh"
30 #include "scm-hash.hh"
35 #include "constrained-breaking.hh"
39 Paper_score::Paper_score (Output_def *layout)
44 paper_systems_ = SCM_BOOL_F;
48 Paper_score::derived_mark () const
51 scm_gc_mark (layout_->self_scm ());
52 scm_gc_mark (systems_);
53 scm_gc_mark (paper_systems_);
57 Paper_score::typeset_system (System *system)
62 systems_ = scm_cons (system->self_scm (), systems_);
63 system->pscore_ = this;
64 system->layout_ = layout_;
69 Paper_score::find_break_indices () const
71 cols_ = root_system ()->used_columns ();
72 break_indices_.clear ();
73 break_ranks_.clear ();
75 for (vsize i = 0; i < cols_.size (); i++)
77 Item *it = dynamic_cast<Item *> (cols_[i]);
78 if (Paper_column::is_breakable (cols_[i])
79 && (i == 0 || it->find_prebroken_piece (LEFT))
80 && (i == cols_.size () - 1 || it->find_prebroken_piece (RIGHT)))
82 break_indices_.push_back (i);
83 break_ranks_.push_back (it->get_column ()->get_rank ());
89 Paper_score::get_break_indices () const
91 if (break_indices_.empty ())
92 find_break_indices ();
93 return break_indices_;
97 Paper_score::get_columns () const
100 find_break_indices ();
105 Paper_score::get_break_ranks () const
107 if (break_ranks_.empty ())
108 find_break_indices ();
112 vector<Column_x_positions>
113 Paper_score::calc_breaking ()
115 Constrained_breaking algorithm (this);
116 vector<Column_x_positions> sol;
118 message (_ ("Calculating line breaks...") + " ");
120 int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0);
122 return algorithm.solve (0, VPOS, system_count);
124 return algorithm.best_solution (0, VPOS);
128 Paper_score::process ()
130 debug_output (_f ("Element count %d (spanners %d) ",
131 system_->element_count (),
132 system_->spanner_count ()));
134 message (_ ("Preprocessing graphical objects..."));
136 system_->pre_processing ();
140 Paper_score::root_system () const
146 Paper_score::layout () const
152 Paper_score::get_paper_systems ()
154 if (scm_is_false (paper_systems_))
156 vector<Column_x_positions> breaking = calc_breaking ();
157 system_->break_into_pieces (breaking);
158 message (_ ("Drawing systems...") + " ");
159 system_->do_break_substitution_and_fixup_refpoints ();
160 paper_systems_ = system_->get_paper_systems ();
162 return paper_systems_;