#include "system.hh"
#include "warn.hh"
+static bool
+is_break (Grob *g)
+{
+ return scm_is_symbol (g->get_property ("page-turn-permission"));
+}
+
Page_turn_page_breaking::Page_turn_page_breaking (Paper_book *pb)
- : Page_breaking (pb, true)
+ : Page_breaking (pb, is_break)
{
}
Page_turn_page_breaking::put_systems_on_pages (vsize start,
vsize end,
vector<Line_details> const &lines,
- vector<vsize> const &div,
+ Line_division const &div,
int page_number)
{
bool last = end == breaks_.size () - 1;
+ bool ragged_all = to_boolean (book_->paper_->c_variable ("ragged-bottom"));
+ bool ragged_last = last && to_boolean (book_->paper_->c_variable ("ragged-last-bottom"));
Real page_h = page_height (1, false); // FIXME
SCM force_sym = last ? ly_symbol2scm ("blank-last-page-force") : ly_symbol2scm ("blank-page-force");
Real blank_force = robust_scm2double (book_->paper_->lookup_variable (force_sym), 0);
- Spacing_result result = space_systems_on_min_pages (lines, page_h, blank_force);
+ Spacing_result result = space_systems_on_min_pages (lines, page_h, blank_force, ragged_all, ragged_last);
Break_node ret;
ret.prev_ = start - 1;
for (vsize start = end; start--;)
{
+ if (start < end-1
+ && breakpoint_property (start+1, "page-turn-permission") == ly_symbol2scm ("force"))
+ break;
+
if (start > 0 && best.demerits_ < state_[start-1].demerits_)
continue;
p_num = f_p_num + p_count + ((f_p_num > 1) ? p_count % 2 : 0);
}
- vector<vsize> min_systems;
- vector<vsize> max_systems;
- vsize min_system_count = 0;
- vsize max_system_count = 0;
- this_start_best.demerits_ = infinity_f;
- calc_system_count_bounds (start, end, &min_systems, &max_systems);
+ Line_division min_division;
+ Line_division max_division;
- /* heuristic: we've prepended some music, only the first system is allowed
- to get more lines */
- if (this_start_best.page_count_ == 2 && this_start_best.div_.size ())
- {
- vsize ds = max_systems.size () - this_start_best.div_.size ();
- for (vsize i = ds + 1; i < max_systems.size (); i++)
- {
- assert (this_start_best.div_[i - ds] <= max_systems[i]);
- max_systems[i] = this_start_best.div_[i - ds];
- }
- }
-
- for (vsize i = 0; i < min_systems.size (); i++)
- {
- min_system_count += min_systems[i];
- max_system_count += max_systems[i];
- }
+ vsize min_sys_count = min_system_count (start, end);
+ vsize max_sys_count = max_system_count (start, end);
+ this_start_best.demerits_ = infinity_f;
bool ok_page = true;
/* heuristic: we've just added a breakpoint, we'll need at least as
many systems as before */
- min_system_count = max (min_system_count, prev_best_system_count);
- for (vsize sys_count = min_system_count; sys_count <= max_system_count && ok_page; sys_count++)
+ min_sys_count = max (min_sys_count, prev_best_system_count);
+ for (vsize sys_count = min_sys_count; sys_count <= max_sys_count && ok_page; sys_count++)
{
- vector<vector<vsize> > div;
- vector<vsize> blank;
+ vector<Line_division> div = line_divisions (start, end, sys_count, min_division, max_division);
bool found = false;
- divide_systems (sys_count, min_systems, max_systems, &div, &blank);
for (vsize d = 0; d < div.size (); d++)
{
- vector<Line_details> line = get_line_details (start, end, div[d]);
+ vector<Line_details> line = line_details (start, end, div[d]);
cur = put_systems_on_pages (start, end, line, div[d], p_num);
if (cur.page_count_ > 2 &&
(start < end - 1 || (!isinf (this_start_best.demerits_)
&& cur.page_count_ + cur.page_count_ % 2
- > this_start_best.page_count_ + this_start_best.page_count_ % 2)))
+ > this_start_best.page_count_ + this_start_best.page_count_ % 2)))
{
ok_page = false;
break;
found = true;
this_start_best = cur;
prev_best_system_count = sys_count;
+
+ /* heuristic: if we increase the number of systems, we can bound the
+ division from below by our current best division */
+ min_division = div[d];
}
}
if (!found && this_start_best.too_many_lines_)
assert (!isinf (best.demerits_) && start < end - 1);
break;
}
+
if (this_start_best.demerits_ < best.demerits_)
- best = this_start_best;
+ best = this_start_best;
}
state_.push_back (best);
}
vsize start = n > 0 ? soln[n-1].break_pos_ : 0;
vsize end = soln[n].break_pos_;
- /* break each score into pieces */
- for (vsize i = next_system (start); i <= breaks_[end].sys_; i++)
- {
- vsize d = i - next_system (start);
- if (all_[i].pscore_)
- {
- vector<Column_x_positions> line_brk;
-
- line_brk = get_line_breaks (i, soln[n].div_[d], start, end);
- all_[i].pscore_->root_system ()->break_into_pieces (line_brk);
- assert (line_brk.size () == soln[n].div_[d]);
- }
- }
+ break_into_pieces (start, end, soln[n].div_);
}
- SCM ret = SCM_EOL;
- SCM *tail = &ret;
- for (vsize i = 0; i < all_.size (); i++)
- {
- if (all_[i].pscore_)
- for (SCM s = scm_vector_to_list (all_[i].pscore_->root_system ()->get_paper_systems ());
- scm_is_pair (s); s = scm_cdr (s))
- {
- *tail = scm_cons (scm_car (s), SCM_EOL);
- tail = SCM_CDRLOC (*tail);
- }
- else
- {
- *tail = scm_cons (all_[i].prob_->self_scm (), SCM_EOL);
- all_[i].prob_->unprotect ();
- tail = SCM_CDRLOC (*tail);
- }
- }
- return ret;
+
+ return systems ();
}
SCM