]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/page-spacing.hh
Refactor page breaking to give a higher-level interface to the individual
[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--2007 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_breaking;
34
35 class Page_spacer
36 {
37 public:
38   Page_spacer (vector<Line_details> const &lines, vsize first_page_num, Page_breaking const*);
39   Spacing_result solve (vsize page_count);
40
41 private:
42   struct Page_spacing_node
43   {
44     Page_spacing_node ()
45     {
46       demerits_ = infinity_f;
47       force_ = infinity_f;
48       penalty_ = infinity_f;
49       prev_ = VPOS;
50     }
51
52     Real demerits_;
53     Real force_;
54     Real penalty_;
55     vsize prev_;
56   };
57
58   Page_breaking const *breaker_;
59   vsize first_page_num_;
60   vector<Line_details> lines_;
61   Matrix<Page_spacing_node> state_;
62   vsize max_page_count_;
63
64   bool ragged_;
65   bool ragged_last_;
66
67   void resize (vsize page_count);
68   bool calc_subproblem (vsize page, vsize lines);
69 };
70
71 struct Page_spacing
72 {
73   Real force_;
74   Real page_height_;
75   Real rod_height_;
76   Real spring_len_;
77   Real inverse_spring_k_;
78
79   Line_details last_line_;
80
81   Page_spacing (Real page_height)
82   {
83     page_height_ = page_height;
84     clear ();
85   }
86
87   void calc_force ();
88
89   void append_system (const Line_details &line);
90   void prepend_system (const Line_details &line);
91   void clear ();
92 };
93
94 Real line_space (Line_details const &line);
95 #endif /* PAGE_SPACING_HH */