2 page-breaking.hh -- declare a superclass and utility
3 functions for several different page-breaking algorithms
5 source file of the GNU LilyPond music typesetter
7 (c) 2006--2007 Joe Neeman <joeneeman@gmail.com>
10 #ifndef PAGE_BREAKING_HH
11 #define PAGE_BREAKING_HH
13 #include "constrained-breaking.hh"
14 #include "page-spacing.hh"
16 /* Either a paper-score, markup or header.
20 System_spec (Paper_score *ps)
26 System_spec (Prob *pb)
45 index in system_spec_index_, if VPOS start of book.
47 vsize system_spec_index_;
49 /* if system_spec_index_ is a score, then we start at the score_brk_'th possible
50 page-break in the score */
53 /* if system_spec_index_ is a score, this points to the broken column */
57 Break_position (vsize s=VPOS, vsize brk=VPOS, Grob *g=NULL, bool end=false)
59 system_spec_index_ = s;
66 lexicographic in (system_spec_index_, score_break_)
68 bool operator< (const Break_position &other)
70 return (system_spec_index_ == VPOS && other.system_spec_index_ != VPOS)
71 || (system_spec_index_ < other.system_spec_index_)
72 || (system_spec_index_ == other.system_spec_index_ && score_break_ < other.score_break_);
75 bool operator<= (const Break_position &other)
77 return (system_spec_index_ == VPOS)
78 || (system_spec_index_ < other.system_spec_index_ && other.system_spec_index_ != VPOS)
79 || (system_spec_index_ == other.system_spec_index_ && score_break_ <= other.score_break_);
86 typedef bool (*Break_predicate) (Grob *);
87 typedef vector<vsize> Line_division;
92 determine the page breaking, and break scores into lines
95 virtual SCM solve () = 0;
97 Page_breaking (Paper_book *pb, Break_predicate);
98 virtual ~Page_breaking ();
100 bool ragged () const;
101 bool ragged_last () const;
102 bool is_last () const;
103 bool ends_score () const;
104 int systems_per_page () const;
105 int max_systems_per_page () const;
106 int min_systems_per_page () const;
107 Real page_height (int page_number, bool last) const;
108 Real page_top_space () const;
109 vsize system_count () const;
110 Real line_count_penalty (int line_count) const;
111 bool too_many_lines (int line_count) const;
112 bool too_few_lines (int line_count) const;
117 vsize next_system (Break_position const &break_pos) const;
119 SCM make_pages (vector<vsize> lines_per_page, SCM lines);
121 vsize min_system_count (vsize start, vsize end);
122 vsize max_system_count (vsize start, vsize end);
125 void break_into_pieces (vsize start, vsize end, Line_division const &div);
128 void set_current_breakpoints (vsize start,
131 Line_division lower_bound = Line_division (),
132 Line_division upper_bound = Line_division ());
133 void set_to_ideal_line_configuration (vsize start, vsize end);
135 vsize current_configuration_count () const;
136 Line_division current_configuration (vsize configuration_index) const;
137 Page_spacing_result space_systems_on_n_pages (vsize configuration_index,
138 vsize n, vsize first_page_num);
139 Page_spacing_result space_systems_on_n_or_one_more_pages (vsize configuration_index, vsize n,
140 vsize first_page_num);
141 Page_spacing_result space_systems_on_best_pages (vsize configuration_index,
142 vsize first_page_num);
143 Page_spacing_result space_systems_with_fixed_number_per_page (vsize configuration_index,
144 vsize first_page_num);
145 Page_spacing_result pack_systems_on_least_pages (vsize configuration_index,
146 vsize first_page_num);
147 vsize min_page_count (vsize configuration_index, vsize first_page_num);
148 bool all_lines_stretched (vsize configuration_index);
149 Real blank_page_penalty () const;
151 SCM breakpoint_property (vsize breakpoint, char const *str);
153 vsize last_break_position () const;
155 vector<Break_position> breaks_;
156 vector<Break_position> chunks_;
157 vector<System_spec> system_specs_;
158 vector<Constrained_breaking> line_breaking_;
161 int systems_per_page_;
162 int max_systems_per_page_;
163 int min_systems_per_page_;
164 Real page_top_space_;
167 vector<Line_division> current_configurations_;
168 vector<Break_position> current_chunks_;
169 vsize current_start_breakpoint_;
170 vsize current_end_breakpoint_;
172 void cache_line_details (vsize configuration_index);
173 void clear_line_details_cache ();
174 vsize cached_configuration_index_;
175 vector<Line_details> cached_line_details_;
176 vector<Line_details> uncompressed_line_details_;
178 vector<Break_position> chunk_list (vsize start, vsize end);
179 Line_division system_count_bounds (vector<Break_position> const &chunks, bool min);
180 void line_breaker_args (vsize i,
181 Break_position const &start,
182 Break_position const &end,
183 vsize *line_breaker_start,
184 vsize *line_breaker_end);
186 void line_divisions_rec (vsize system_count,
187 Line_division const &min,
188 Line_division const &max,
191 vector<Line_details> line_details (vsize start, vsize end, Line_division const &div);
192 Page_spacing_result space_systems_on_1_page (vector<Line_details> const &lines, Real page_height, bool ragged);
193 Page_spacing_result space_systems_on_2_pages (vsize configuration_index, vsize first_page_num);
194 Page_spacing_result finalize_spacing_result (vsize configuration_index, Page_spacing_result);
195 void create_system_list ();
196 void find_chunks_and_breaks (Break_predicate);
198 #endif /* PAGE_BREAKING_HH */