Page_breaking::Page_breaking (Paper_book *pb, Break_predicate is_break)
{
book_ = pb;
- ragged_ = to_boolean (pb->paper_->c_variable ("ragged"));
- ragged_last_ = to_boolean (pb->paper_->c_variable ("ragged-last"));
+ ragged_ = to_boolean (pb->paper_->c_variable ("ragged-bottom"));
+ ragged_last_ = to_boolean (pb->paper_->c_variable ("ragged-last-bottom"));
create_system_list ();
find_chunks_and_breaks (is_break);
}
page_stencil = scm_variable_ref (page_stencil);
SCM book = book_->self_scm ();
- bool ragged_all = to_boolean (book_->paper_->c_variable ("ragged-bottom"));
- bool ragged_last = to_boolean (book_->paper_->c_variable ("ragged-last-bottom"));
int first_page_number = robust_scm2int (book_->paper_->c_variable ("first-page-number"), 1);
SCM ret = SCM_EOL;
{
SCM page_num = scm_from_int (i + first_page_number);
SCM last = scm_from_bool (i == lines_per_page.size () - 1);
- SCM ragged = scm_from_bool (ragged_all || (to_boolean (last) && ragged_last));
+ SCM rag = scm_from_bool (ragged () || (to_boolean (last) && ragged_last ()));
SCM line_count = scm_from_int (lines_per_page[i]);
SCM lines = scm_list_head (systems, line_count);
SCM page = scm_apply_0 (make_page,
- scm_list_n (book, lines, page_num, ragged, last, SCM_UNDEFINED));
+ scm_list_n (book, lines, page_num, rag, last, SCM_UNDEFINED));
scm_apply_1 (page_stencil, page, SCM_EOL);
ret = scm_cons (page, ret);
lower_bound,
upper_bound,
&work_in_progress);
+
+ /* we only consider a constant number of configurations. Otherwise,
+ this becomes slow when there are many small scores. The constant
+ 5 is somewhat arbitrary. */
+ if (current_configurations_.size () > 5)
+ {
+ vector<pair<Real,vsize> > dems_and_indices;
+
+ for (vsize i = 0; i < current_configurations_.size (); i++)
+ {
+ cache_line_details (i);
+ Real dem = 0;
+ for (vsize j = 0; j < cached_line_details_.size (); j++)
+ dem += cached_line_details_[j].force_ * cached_line_details_[j].force_
+ + cached_line_details_[j].break_penalty_;
+
+ dems_and_indices.push_back (pair<Real,vsize> (dem, i));
+ }
+ vector_sort (dems_and_indices, less<pair<Real,vsize> > ());
+
+ vector<Line_division> best_5_configurations;
+ for (vsize i = 0; i < 5; i++)
+ best_5_configurations.push_back (current_configurations_[dems_and_indices[i].second]);
+
+ clear_line_details_cache ();
+ current_configurations_ = best_5_configurations;
+ }
+}
+
+void
+Page_breaking::set_to_ideal_line_configuration (vsize start, vsize end)
+{
+ current_chunks_ = chunk_list (start, end);
+ current_start_breakpoint_ = start;
+ current_end_breakpoint_ = end;
+ clear_line_details_cache ();
+
+ Line_division div;
+ for (vsize i = 0; i+1 < current_chunks_.size (); i++)
+ {
+ vsize sys = next_system (current_chunks_[i]);
+ if (all_[sys].pscore_)
+ {
+ line_breaker_args (sys, current_chunks_[i], current_chunks_[i+1], &start, &end);
+ div.push_back (line_breaking_[sys].best_solution (start, end).size ());
+ }
+ else
+ div.push_back (1);
+ }
+ current_configurations_.clear ();
+ current_configurations_.push_back (div);
}
vsize
Spacing_result
Page_breaking::space_systems_on_n_or_one_more_pages (vsize configuration, vsize n, vsize first_page_num)
{
- Spacing_result n_res = space_systems_on_n_pages (configuration, n, first_page_num);
- Spacing_result m_res = space_systems_on_n_pages (configuration, n+1, first_page_num);
+ Spacing_result n_res;
+ Spacing_result m_res;
+
+ if (n <= 2)
+ {
+ n_res = space_systems_on_n_pages (configuration, n, first_page_num);
+ m_res = space_systems_on_n_pages (configuration, n+1, first_page_num);
+ }
+ else
+ {
+ cache_line_details (configuration);
+
+ vsize min_p_count = min_page_count (configuration, first_page_num);
+ Page_spacer ps (cached_line_details_, first_page_num, this);
+ if (n >= min_p_count)
+ n_res = ps.solve (n);
+ if (n < cached_line_details_.size ())
+ m_res = ps.solve (n+1);
+ }
+
Real penalty = blank_page_penalty ();
n_res.demerits_ += penalty;
n_res.force_.back () += penalty;
Real best_demerits = infinity_f;
for (vsize i = 0; i < page1_force.size (); i++)
{
- Real dem = page1_force[i] * page1_force[i]
- + page2_force[i] * page2_force[i]
+ Real f = page1_force[i] * page1_force[i] + page2_force[i] * page2_force[i];
+ Real uneven = 2 * (page1_force[i] - page2_force[i]);
+ Real dem = uneven * uneven + f
+ cached_line_details_[i+1].page_penalty_
+ cached_line_details_.back ().page_penalty_ + cached_line_details_.back ().turn_penalty_;
if (dem < best_demerits)