- 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, ragged_all, ragged_last);
+ vsize min_p_count = min_page_count (configuration, page_number);
+ bool auto_first = to_boolean (book_->paper_->c_variable ("auto-first-page-number"));
+
+ /* If [START, END] does not contain an intermediate
+ breakpoint, we may need to consider solutions that result in a bad turn.
+ In this case, we won't abort if the min_page_count is too big */
+ if (start < end - 1 && min_p_count + (auto_first ? 0 : (page_number % 2)) > 2)
+ return Break_node ();
+
+ /* if PAGE-NUMBER is odd, we are starting on a right hand page. That is, we
+ have the options
+ PAGE-NUMBER odd:
+ - even number of pages + a blank page
+ - odd number of pages
+ PAGE-NUMBER even:
+ - odd number of pages + a blank page
+ - even number of pages
+
+ No matter which case PAGE-NUMBER falls into, we take the second choice if
+ min_p_count has that evenness. (For example, if PAGE-NUMBER is even and
+ min_p_count is even, we don't even consider the blank page option). */
+
+ Page_spacing_result result;
+ if (start == 0 && auto_first)
+ {
+ if (min_p_count % 2)
+ result = space_systems_on_n_or_one_more_pages (configuration, min_p_count, page_number, 0);
+ else
+ result = space_systems_on_n_pages (configuration, min_p_count, page_number);
+ }
+ else if (page_number % 2 == min_p_count % 2)
+ result = space_systems_on_n_pages (configuration, min_p_count, page_number);
+ else
+ result = space_systems_on_n_or_one_more_pages (configuration, min_p_count, page_number, blank_page_penalty ());