2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2010 Joe Neeman <joeneeman@gmail.com>
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 #ifndef PAGE_SPACING_HH
21 #define PAGE_SPACING_HH
23 #include "constrained-breaking.hh"
24 #include "page-spacing-result.hh"
26 /* This is a penalty that we add whenever a page breaking solution
27 is not bad enough to completely discard, but bad enough that
28 it is worse than any "proper" solution. For example, if we didn't
29 manage to fit systems on the desired number of pages or if there was
32 This constant is large enough that it dominates any reasonable penalty,
33 but small enough that nothing will overflow to infinity (so that we
34 can still distinguish bad spacings by the number of BAD_SPACING_PENALTYs
37 BAD_SPACING_PENALTY is for occasions where the spacing is bad.
38 TERRIBLE_SPACING_PENALTY is for when we are disregarding a user override
39 (for example, we are failing to satisfy min-systems-per-page). These user
40 overrides are more important than getting good spacing, so they get a
43 const Real BAD_SPACING_PENALTY = 1e6;
44 const Real TERRIBLE_SPACING_PENALTY = 1e8;
47 /* for page_count > 2, we use a dynamic algorithm similar to
48 constrained-breaking -- we have a class that stores the intermediate
49 calculations so they can be reused for querying different page counts.
54 Page_spacer (vector<Line_details> const &lines, vsize first_page_num, Page_breaking const*);
55 Page_spacing_result solve (vsize page_count);
56 Page_spacing_result solve ();
59 struct Page_spacing_node
63 demerits_ = infinity_f;
65 penalty_ = infinity_f;
67 system_count_status_ = SYSTEM_COUNT_OK;
76 int system_count_status_;
79 Page_breaking const *breaker_;
80 vsize first_page_num_;
81 vector<Line_details> lines_;
83 // If a page-count is requested, we use state_, which
84 // is indexed by page*system, for our dynamic programming
85 // intermediate storage. Otherwise, we use simple_state_,
86 // which is indexed only by system.
87 Matrix<Page_spacing_node> state_;
88 vector<Page_spacing_node> simple_state_;
89 vsize max_page_count_;
94 void resize (vsize page_count);
95 bool calc_subproblem (vsize page, vsize lines);
104 Real inverse_spring_k_;
106 Line_details last_line_;
107 Line_details first_line_;
108 Page_breaking const *breaker_;
110 Page_spacing (Real page_height, Page_breaking const *breaker)
112 page_height_ = page_height;
118 void resize (Real new_height);
119 void append_system (const Line_details &line);
120 void prepend_system (const Line_details &line);
124 #endif /* PAGE_SPACING_HH */