]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/page-spacing.hh
fe7056c597c1fa1bcdf30a19c7b979756ef3ba16
[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 #include "page-spacing-result.hh"
15
16
17 /* for page_count > 2, we use a dynamic algorithm similar to
18    constrained-breaking -- we have a class that stores the intermediate
19    calculations so they can be reused for querying different page counts.
20 */
21 class Page_spacer
22 {
23 public:
24   Page_spacer (vector<Line_details> const &lines, vsize first_page_num, Page_breaking const*);
25   Page_spacing_result solve (vsize page_count);
26
27 private:
28   struct Page_spacing_node
29   {
30     Page_spacing_node ()
31     {
32       demerits_ = infinity_f;
33       force_ = infinity_f;
34       penalty_ = infinity_f;
35       prev_ = VPOS;
36     }
37
38     Real demerits_;
39     Real force_;
40     Real penalty_;
41     vsize prev_;
42   };
43
44   Page_breaking const *breaker_;
45   vsize first_page_num_;
46   vector<Line_details> lines_;
47   Matrix<Page_spacing_node> state_;
48   vsize max_page_count_;
49
50   bool ragged_;
51   bool ragged_last_;
52
53   void resize (vsize page_count);
54   bool calc_subproblem (vsize page, vsize lines);
55 };
56
57 struct Page_spacing
58 {
59   Real force_;
60   Real page_height_;
61   Real rod_height_;
62   Real spring_len_;
63   Real inverse_spring_k_;
64   Real page_top_space_;
65
66   Line_details last_line_;
67   Line_details first_line_;
68
69   Page_spacing (Real page_height, Real page_top_space)
70   {
71     page_height_ = page_height;
72     page_top_space_ = page_top_space;
73     clear ();
74   }
75
76   void calc_force ();
77   void resize (Real new_height);
78   void append_system (const Line_details &line);
79   void prepend_system (const Line_details &line);
80   void clear ();
81 };
82
83 #endif /* PAGE_SPACING_HH */