2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2010 Joe Neeman <joeneeman@gmail.com>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef PAGE_BREAKING_HH
21 #define PAGE_BREAKING_HH
23 #include "constrained-breaking.hh"
24 #include "page-spacing.hh"
26 /* Either a paper-score, markup or header.
30 System_spec (Paper_score *ps)
36 System_spec (Prob *pb)
55 index in system_spec_index_, if VPOS start of book.
57 vsize system_spec_index_;
59 /* if system_spec_index_ is a score, then we start at the score_brk_'th possible
60 page-break in the score */
63 /* if system_spec_index_ is a score, this points to the broken column */
67 /* if non-zero, this is the (fixed, uncompressed) number of lines between
68 this Break_position and the previous. */
69 int forced_line_count_;
71 Break_position (vsize s=VPOS, vsize brk=VPOS, Grob *g=NULL, bool end=false)
73 system_spec_index_ = s;
77 forced_line_count_ = 0;
81 lexicographic in (system_spec_index_, score_break_)
83 bool operator< (const Break_position &other)
85 return (system_spec_index_ == VPOS && other.system_spec_index_ != VPOS)
86 || (system_spec_index_ < other.system_spec_index_)
87 || (system_spec_index_ == other.system_spec_index_ && score_break_ < other.score_break_);
90 bool operator<= (const Break_position &other)
92 return (system_spec_index_ == VPOS)
93 || (system_spec_index_ < other.system_spec_index_ && other.system_spec_index_ != VPOS)
94 || (system_spec_index_ == other.system_spec_index_ && score_break_ <= other.score_break_);
101 typedef bool (*Break_predicate) (Grob *);
102 typedef bool (*Prob_break_predicate) (Prob *);
103 typedef vector<vsize> Line_division;
108 determine the page breaking, and break scores into lines
111 virtual SCM solve () = 0;
113 Page_breaking (Paper_book *pb, Break_predicate, Prob_break_predicate);
114 virtual ~Page_breaking ();
116 bool ragged () const;
117 bool ragged_last () const;
118 bool is_last () const;
119 bool ends_score () const;
120 int systems_per_page () const;
121 int max_systems_per_page () const;
122 int min_systems_per_page () const;
123 Real page_height (int page_number, bool last) const;
124 Real paper_height () const;
125 vsize system_count () const;
126 Real line_count_penalty (int line_count) const;
127 int line_count_status (int line_count) const;
128 bool too_many_lines (int line_count) const;
129 bool too_few_lines (int line_count) const;
130 Real min_whitespace_at_top_of_page (Line_details const&) const;
131 Real min_whitespace_at_bottom_of_page (Line_details const&) const;
132 int orphan_penalty () const;
137 vsize next_system (Break_position const &break_pos) const;
139 SCM make_pages (vector<vsize> lines_per_page, SCM lines);
141 vsize min_system_count (vsize start, vsize end);
142 vsize max_system_count (vsize start, vsize end);
145 void break_into_pieces (vsize start, vsize end, Line_division const &div);
148 void set_current_breakpoints (vsize start,
151 Line_division lower_bound = Line_division (),
152 Line_division upper_bound = Line_division ());
153 void set_to_ideal_line_configuration (vsize start, vsize end);
155 vsize current_configuration_count () const;
156 Line_division current_configuration (vsize configuration_index) const;
157 Page_spacing_result space_systems_on_n_pages (vsize configuration_index,
158 vsize n, vsize first_page_num);
159 Page_spacing_result space_systems_on_n_or_one_more_pages (vsize configuration_index, vsize n,
160 vsize first_page_num,
161 Real penalty_for_fewer_pages);
162 Page_spacing_result space_systems_on_best_pages (vsize configuration_index,
163 vsize first_page_num);
164 Page_spacing_result space_systems_with_fixed_number_per_page (vsize configuration_index,
165 vsize first_page_num);
166 Page_spacing_result pack_systems_on_least_pages (vsize configuration_index,
167 vsize first_page_num);
168 vsize min_page_count (vsize configuration_index, vsize first_page_num);
169 bool all_lines_stretched (vsize configuration_index);
170 Real blank_page_penalty () const;
172 SCM breakpoint_property (vsize breakpoint, char const *str);
174 vsize last_break_position () const;
176 vector<Break_position> breaks_;
177 vector<Break_position> chunks_;
178 vector<System_spec> system_specs_;
179 vector<Constrained_breaking> line_breaking_;
182 int systems_per_page_;
183 int max_systems_per_page_;
184 int min_systems_per_page_;
188 vector<Line_division> current_configurations_;
189 vector<Break_position> current_chunks_;
190 vsize current_start_breakpoint_;
191 vsize current_end_breakpoint_;
193 void cache_line_details (vsize configuration_index);
194 void compute_line_heights ();
195 void clear_line_details_cache ();
196 vsize cached_configuration_index_;
197 vector<Line_details> cached_line_details_;
198 vector<Line_details> uncompressed_line_details_;
201 mutable vector<Real> page_height_cache_;
202 mutable vector<Real> last_page_height_cache_;
204 vector<Break_position> chunk_list (vsize start, vsize end);
205 Line_division system_count_bounds (vector<Break_position> const &chunks, bool min);
206 void line_breaker_args (vsize i,
207 Break_position const &start,
208 Break_position const &end,
209 vsize *line_breaker_start,
210 vsize *line_breaker_end);
212 void line_divisions_rec (vsize system_count,
213 Line_division const &min,
214 Line_division const &max,
217 vector<Line_details> line_details (vsize start, vsize end, Line_division const &div);
218 Page_spacing_result space_systems_on_1_page (vector<Line_details> const &lines, Real page_height, bool ragged);
219 Page_spacing_result space_systems_on_2_pages (vsize configuration_index, vsize first_page_num);
220 Page_spacing_result finalize_spacing_result (vsize configuration_index, Page_spacing_result);
221 void create_system_list ();
222 void find_chunks_and_breaks (Break_predicate, Prob_break_predicate);
223 SCM make_page (int page_num, bool last) const;
224 SCM get_page_configuration (SCM systems, int page_num, bool ragged, bool last);
225 SCM draw_page (SCM systems, SCM config, int page_num, bool last);
227 #endif /* PAGE_BREAKING_HH */