]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/page-breaking.hh
548100ca8b14ca7ef40e08a9ce4da3e2e166bad9
[lilypond.git] / lily / include / page-breaking.hh
1 /*
2   page-breaking.hh -- declare a superclass and utility
3   functions for several different page-breaking algorithms
4
5   source file of the GNU LilyPond music typesetter
6
7   (c) 2006 Joe Neeman <joeneeman@gmail.com>
8 */
9
10 #ifndef PAGE_BREAKING_HH
11 #define PAGE_BREAKING_HH
12
13 #include "constrained-breaking.hh"
14 #include "lily-guile.hh"
15
16 /* Either a paper-score, markup or header.
17  */
18 struct System_spec
19 {
20   System_spec (Paper_score *ps)
21   {
22     pscore_ = ps;
23     prob_ = NULL;
24   }
25
26   System_spec (Prob *pb)
27   {
28     prob_ = pb;
29     pscore_ = NULL;
30   }
31
32   System_spec ()
33   {
34     pscore_ = NULL;
35     prob_ = NULL;
36   }
37
38   Paper_score *pscore_;
39   Prob *prob_;
40 };
41
42 struct Break_position
43 {
44   vsize sys_; /* our index in the all_ list */
45   vsize score_break_; /* if sys_ is a score, then we start at the score_brk_'th
46                          possible page-break in the score */
47   Grob *col_;  /* if sys_ is a score, this points to the broken column */
48   bool score_ender_;
49
50   Break_position (vsize s=VPOS, vsize brk=VPOS, Grob *g=NULL, bool end=false)
51   {
52     sys_ = s;
53     score_break_ = brk;
54     col_ = g;
55     score_ender_ = end;
56   }
57
58   bool operator< (const Break_position &other)
59   {
60     return (sys_ == VPOS && other.sys_ != VPOS)
61       || (sys_ < other.sys_)
62       || (sys_ == other.sys_ && score_break_ < other.score_break_);
63   }
64
65   bool operator<= (const Break_position &other)
66   {
67     return (sys_ == VPOS)
68       || (sys_ < other.sys_ && other.sys_ != VPOS)
69       || (sys_ == other.sys_ && score_break_ <= other.score_break_);
70   }
71 };
72
73 class Page_breaking
74 {
75 public:
76   typedef bool (*Break_predicate) (Grob *);
77   typedef vector<vsize> Line_division;
78   virtual SCM solve () = 0;
79
80   Page_breaking (Paper_book *pb, Break_predicate);
81   virtual ~Page_breaking ();
82
83 protected:
84   Paper_book *book_;
85
86   Real page_height (int page_number, bool last);
87   vsize next_system (Break_position const &break_pos) const;
88
89   SCM make_pages (vector<vsize> lines_per_page, SCM lines);
90
91   vsize min_system_count (vsize start, vsize end);
92   vsize max_system_count (vsize start, vsize end);
93   vector<Line_details> line_details (vsize start, vsize end, Line_division const &div);
94
95   void break_into_pieces (vsize start, vsize end, Line_division const &div);
96   SCM systems ();
97
98
99   vector<Line_division> line_divisions (vsize start,
100                                         vsize end,
101                                         vsize system_count,
102                                         Line_division lower_bound = Line_division (),
103                                         Line_division upper_bound = Line_division ());
104
105   SCM breakpoint_property (vsize breakpoint, char const *str);
106   vector<Break_position> breaks_;
107
108 private:
109   vector<Break_position> chunks_;
110   vector<System_spec> all_;
111   vector<Constrained_breaking> line_breaking_;
112
113   vector<Break_position> chunk_list (vsize start, vsize end);
114   Line_division system_count_bounds (vector<Break_position> const &chunks, bool min);
115   void line_breaker_args (vsize i,
116                           Break_position const &start,
117                           Break_position const &end,
118                           vsize *line_breaker_start,
119                           vsize *line_breaker_end);
120
121   void line_divisions_rec (vsize system_count,
122                            Line_division const &min,
123                            Line_division const &max,
124                            vector<Line_division> *result,
125                            Line_division *cur);
126
127   void create_system_list ();
128   void find_chunks_and_breaks (Break_predicate);
129 };
130 #endif /* PAGE_BREAKING_HH */