]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-score.cc
Web-ja: update introduction
[lilypond.git] / lily / paper-score.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "paper-score.hh"
21
22 #include "all-font-metrics.hh"
23 #include "book.hh"
24 #include "international.hh"
25 #include "main.hh"
26 #include "misc.hh"
27 #include "output-def.hh"
28 #include "paper-book.hh"
29 #include "paper-column.hh"
30 #include "scm-hash.hh"
31 #include "score.hh"
32 #include "stencil.hh"
33 #include "system.hh"
34 #include "warn.hh"
35 #include "constrained-breaking.hh"
36
37 Paper_score::Paper_score (Output_def *layout)
38 {
39   layout_ = layout;
40   system_ = 0;
41   systems_ = SCM_EOL;
42   paper_systems_ = SCM_BOOL_F;
43 }
44
45 void
46 Paper_score::derived_mark () const
47 {
48   if (layout_)
49     scm_gc_mark (layout_->self_scm ());
50   scm_gc_mark (systems_);
51   scm_gc_mark (paper_systems_);
52 }
53
54 void
55 Paper_score::typeset_system (System *system)
56 {
57   if (!system_)
58     system_ = system;
59
60   systems_ = scm_cons (system->self_scm (), systems_);
61   system->pscore_ = this;
62   system->layout_ = layout_;
63   system->unprotect ();
64 }
65
66 void
67 Paper_score::find_break_indices () const
68 {
69   cols_ = root_system ()->used_columns ();
70   break_indices_.clear ();
71   break_ranks_.clear ();
72
73   for (vsize i = 0; i < cols_.size (); i++)
74     {
75       Item *it = dynamic_cast<Item *> (cols_[i]);
76       if (Paper_column::is_breakable (cols_[i])
77           && (i == 0 || it->find_prebroken_piece (LEFT))
78           && (i == cols_.size () - 1 || it->find_prebroken_piece (RIGHT)))
79         {
80           break_indices_.push_back (i);
81           break_ranks_.push_back (it->get_column ()->get_rank ());
82         }
83     }
84 }
85
86 vector<vsize>
87 Paper_score::get_break_indices () const
88 {
89   if (break_indices_.empty ())
90     find_break_indices ();
91   return break_indices_;
92 }
93
94 vector<Grob *>
95 Paper_score::get_columns () const
96 {
97   if (cols_.empty ())
98     find_break_indices ();
99   return cols_;
100 }
101
102 vector<vsize>
103 Paper_score::get_break_ranks () const
104 {
105   if (break_ranks_.empty ())
106     find_break_indices ();
107   return break_ranks_;
108 }
109
110 vector<Column_x_positions>
111 Paper_score::calc_breaking ()
112 {
113   Constrained_breaking algorithm (this);
114   vector<Column_x_positions> sol;
115
116   message (_ ("Calculating line breaks...") + " ");
117
118   int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0);
119   if (system_count)
120     return algorithm.solve (0, VPOS, system_count);
121
122   return algorithm.best_solution (0, VPOS);
123 }
124
125 void
126 Paper_score::process ()
127 {
128   debug_output (_f ("Element count %d (spanners %d) ",
129                     system_->element_count (),
130                     system_->spanner_count ()));
131
132   message (_ ("Preprocessing graphical objects..."));
133
134   system_->pre_processing ();
135 }
136
137 System *
138 Paper_score::root_system () const
139 {
140   return system_;
141 }
142
143 Output_def *
144 Paper_score::layout () const
145 {
146   return layout_;
147 }
148
149 SCM
150 Paper_score::get_paper_systems ()
151 {
152   if (scm_is_false (paper_systems_))
153     {
154       vector<Column_x_positions> breaking = calc_breaking ();
155       system_->break_into_pieces (breaking);
156       message (_ ("Drawing systems...") + " ");
157       system_->do_break_substitution_and_fixup_refpoints ();
158       paper_systems_ = system_->get_paper_systems ();
159     }
160   return paper_systems_;
161 }