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--2009 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 /* if non-zero, this is the (fixed, uncompressed) number of lines between
58 this Break_position and the previous. */
59 int forced_line_count_;
61 Break_position (vsize s=VPOS, vsize brk=VPOS, Grob *g=NULL, bool end=false)
63 system_spec_index_ = s;
67 forced_line_count_ = 0;
71 lexicographic in (system_spec_index_, score_break_)
73 bool operator< (const Break_position &other)
75 return (system_spec_index_ == VPOS && other.system_spec_index_ != VPOS)
76 || (system_spec_index_ < other.system_spec_index_)
77 || (system_spec_index_ == other.system_spec_index_ && score_break_ < other.score_break_);
80 bool operator<= (const Break_position &other)
82 return (system_spec_index_ == VPOS)
83 || (system_spec_index_ < other.system_spec_index_ && other.system_spec_index_ != VPOS)
84 || (system_spec_index_ == other.system_spec_index_ && score_break_ <= other.score_break_);
91 typedef bool (*Break_predicate) (Grob *);
92 typedef vector<vsize> Line_division;
97 determine the page breaking, and break scores into lines
100 virtual SCM solve () = 0;
102 Page_breaking (Paper_book *pb, Break_predicate);
103 virtual ~Page_breaking ();
105 bool ragged () const;
106 bool ragged_last () const;
107 bool is_last () const;
108 bool ends_score () const;
109 int systems_per_page () const;
110 int max_systems_per_page () const;
111 int min_systems_per_page () const;
112 Real page_height (int page_number, bool last) const;
113 vsize system_count () const;
114 Real line_count_penalty (int line_count) const;
115 int line_count_status (int line_count) const;
116 bool too_many_lines (int line_count) const;
117 bool too_few_lines (int line_count) const;
118 Real min_whitespace_at_top_of_page (Line_details const&) const;
119 Real min_whitespace_at_bottom_of_page (Line_details const&) const;
124 vsize next_system (Break_position const &break_pos) const;
126 SCM make_pages (vector<vsize> lines_per_page, SCM lines);
128 vsize min_system_count (vsize start, vsize end);
129 vsize max_system_count (vsize start, vsize end);
132 void break_into_pieces (vsize start, vsize end, Line_division const &div);
135 void set_current_breakpoints (vsize start,
138 Line_division lower_bound = Line_division (),
139 Line_division upper_bound = Line_division ());
140 void set_to_ideal_line_configuration (vsize start, vsize end);
142 vsize current_configuration_count () const;
143 Line_division current_configuration (vsize configuration_index) const;
144 Page_spacing_result space_systems_on_n_pages (vsize configuration_index,
145 vsize n, vsize first_page_num);
146 Page_spacing_result space_systems_on_n_or_one_more_pages (vsize configuration_index, vsize n,
147 vsize first_page_num);
148 Page_spacing_result space_systems_on_best_pages (vsize configuration_index,
149 vsize first_page_num);
150 Page_spacing_result space_systems_with_fixed_number_per_page (vsize configuration_index,
151 vsize first_page_num);
152 Page_spacing_result pack_systems_on_least_pages (vsize configuration_index,
153 vsize first_page_num);
154 vsize min_page_count (vsize configuration_index, vsize first_page_num);
155 bool all_lines_stretched (vsize configuration_index);
156 Real blank_page_penalty () const;
158 SCM breakpoint_property (vsize breakpoint, char const *str);
160 vsize last_break_position () const;
162 vector<Break_position> breaks_;
163 vector<Break_position> chunks_;
164 vector<System_spec> system_specs_;
165 vector<Constrained_breaking> line_breaking_;
168 int systems_per_page_;
169 int max_systems_per_page_;
170 int min_systems_per_page_;
173 vector<Line_division> current_configurations_;
174 vector<Break_position> current_chunks_;
175 vsize current_start_breakpoint_;
176 vsize current_end_breakpoint_;
178 void cache_line_details (vsize configuration_index);
179 void clear_line_details_cache ();
180 vsize cached_configuration_index_;
181 vector<Line_details> cached_line_details_;
182 vector<Line_details> uncompressed_line_details_;
184 vector<Break_position> chunk_list (vsize start, vsize end);
185 Line_division system_count_bounds (vector<Break_position> const &chunks, bool min);
186 void line_breaker_args (vsize i,
187 Break_position const &start,
188 Break_position const &end,
189 vsize *line_breaker_start,
190 vsize *line_breaker_end);
192 void line_divisions_rec (vsize system_count,
193 Line_division const &min,
194 Line_division const &max,
197 vector<Line_details> line_details (vsize start, vsize end, Line_division const &div);
198 Page_spacing_result space_systems_on_1_page (vector<Line_details> const &lines, Real page_height, bool ragged);
199 Page_spacing_result space_systems_on_2_pages (vsize configuration_index, vsize first_page_num);
200 Page_spacing_result finalize_spacing_result (vsize configuration_index, Page_spacing_result);
201 void create_system_list ();
202 void find_chunks_and_breaks (Break_predicate);
203 SCM make_page (int page_num, bool last) const;
204 SCM get_page_configuration (SCM systems, int page_num, bool ragged, bool last);
205 SCM draw_page (SCM systems, SCM config, int page_num, bool last);
207 #endif /* PAGE_BREAKING_HH */