2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2009 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
);
58 struct Page_spacing_node
62 demerits_
= infinity_f
;
64 penalty_
= infinity_f
;
66 system_count_status_
= SYSTEM_COUNT_OK
;
73 int system_count_status_
;
76 Page_breaking
const *breaker_
;
77 vsize first_page_num_
;
78 vector
<Line_details
> lines_
;
79 Matrix
<Page_spacing_node
> state_
;
80 vsize max_page_count_
;
85 void resize (vsize page_count
);
86 bool calc_subproblem (vsize page
, vsize lines
);
95 Real inverse_spring_k_
;
97 Line_details last_line_
;
98 Line_details first_line_
;
99 Page_breaking
const *breaker_
;
101 Page_spacing (Real page_height
, Page_breaking
const *breaker
)
103 page_height_
= page_height
;
109 void resize (Real new_height
);
110 void append_system (const Line_details
&line
);
111 void prepend_system (const Line_details
&line
);
115 #endif /* PAGE_SPACING_HH */