]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/page-spacing.hh
* input/regression/optimal-page-breaking-hstretch.ly: test for
[lilypond.git] / lily / include / page-spacing.hh
1 /*
2   page-spacing.hh -- routines for spacing systems
3   vertically across pages
4
5   source file of the GNU LilyPond music typesetter
6
7   (c) 2006 Joe Neeman <joeneeman@gmail.com>
8 */
9
10 #ifndef PAGE_SPACING_HH
11 #define PAGE_SPACING_HH
12
13 #include "constrained-breaking.hh"
14
15 struct Spacing_result {
16   vector<vsize> systems_per_page_;
17   vector<Real> force_;
18   Real penalty_;
19   Real demerits_;
20
21   Spacing_result ()
22   {
23     penalty_ = 0;
24     demerits_ = infinity_f;
25   }
26 };
27
28 /* for page_count > 2, we use a dynamic algorithm similar to
29    constrained-breaking -- we have a class that stores the intermediate
30    calculations so they can be reused for querying different page counts.
31 */
32
33 class Page_spacer
34 {
35 public:
36   Page_spacer (vector<Line_details> const &lines, Real page_height, bool ragged, bool ragged_last);
37   Spacing_result solve (vsize page_count);
38
39 private:
40   struct Page_spacing_node
41   {
42     Page_spacing_node ()
43     {
44       demerits_ = infinity_f;
45       force_ = infinity_f;
46       penalty_ = infinity_f;
47       prev_ = VPOS;
48     }
49
50     Real demerits_;
51     Real force_;
52     Real penalty_;
53     vsize prev_;
54   };
55
56   Real page_height_;
57   vector<Line_details> lines_;
58   Matrix<Page_spacing_node> state_;
59   vsize max_page_count_;
60
61   bool ragged_;
62   bool ragged_last_;
63
64   void resize (vsize page_count);
65   bool calc_subproblem (vsize page, vsize lines);
66 };
67
68 Spacing_result
69 space_systems_on_min_pages (vector<Line_details> const&,
70                             Real page_height,
71                             Real odd_pages_penalty,
72                             bool ragged,
73                             bool ragged_last);
74 Spacing_result
75 space_systems_on_best_pages (vector<Line_details> const&,
76                              Real page_height,
77                              Real odd_pages_penalty,
78                              bool ragged,
79                              bool ragged_last);
80
81 #endif /* PAGE_SPACING_HH */