]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/page-spacing.hh
Merge branch 'master' of git://git.sv.gnu.org/lilypond
[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
65   Line_details last_line_;
66
67   Page_spacing (Real page_height)
68   {
69     page_height_ = page_height;
70     clear ();
71   }
72
73   void calc_force ();
74   void resize (Real new_height);
75   void append_system (const Line_details &line);
76   void prepend_system (const Line_details &line);
77   void clear ();
78 };
79
80 #endif /* PAGE_SPACING_HH */