+Page_spacing_result
+Page_breaking::space_systems_with_fixed_number_per_page (vsize configuration,
+ vsize first_page_num)
+{
+ Page_spacing_result res;
+ Page_spacing space (page_height (first_page_num, false), page_top_space_);
+ vsize line = 0;
+ vsize page = 0;
+ vsize page_first_line = 0;
+
+ cache_line_details (configuration);
+ while (line < cached_line_details_.size ())
+ {
+ page++;
+ space.clear ();
+ space.resize (page_height (first_page_num + page, false));
+
+ int system_count_on_this_page = 0;
+ while (system_count_on_this_page < systems_per_page_
+ && line < cached_line_details_.size ())
+ {
+ Line_details const &cur_line = cached_line_details_[line];
+ space.append_system (cur_line);
+ system_count_on_this_page += cur_line.compressed_nontitle_lines_count_;
+ line++;
+
+ if (cur_line.page_permission_ == ly_symbol2scm ("force"))
+ break;
+ }
+
+ res.systems_per_page_.push_back (line - page_first_line);
+
+ // Don't say that the force is infinite even if it is: if we were told to
+ // put a certain number of systems on a page then we will, even if it's bad.
+ res.force_.push_back (min (space.force_, BAD_SPACING_PENALTY));
+ res.penalty_ += cached_line_details_[line-1].page_penalty_;
+ page_first_line = line;
+ }
+
+ /* Recalculate forces for the last page because we know now that is
+ really the last page. */
+ space.resize (page_height (first_page_num + page, true));
+ res.force_.back () = min(space.force_, BAD_SPACING_PENALTY);
+ return finalize_spacing_result (configuration, res);
+}
+