source file of the GNU LilyPond music typesetter
- (c) 2006--2007 Joe Neeman <joeneeman@gmail.com>
+ (c) 2006--2009 Joe Neeman <joeneeman@gmail.com>
*/
#include "page-breaking.hh"
compressed.extent_[UP] = old.extent_[UP] + orig[i].extent_.length () + old.padding_;
compressed.space_ += old.space_;
compressed.inverse_hooke_ += old.inverse_hooke_;
- compressed.title_ = old.title_;
- /* we don't need the force_ field for the vertical spacing,
- so we use force_ = n to signal that the line was compressed,
- reducing the number of lines by n (and force_ = 0 otherwise).
- This makes uncompression much easier. */
- compressed.force_ = old.force_ + 1;
+ compressed.compressed_lines_count_ = old.compressed_lines_count_ + 1;
+ compressed.compressed_nontitle_lines_count_ =
+ old.compressed_nontitle_lines_count_ + (compressed.title_ ? 0 : 1);
+
+ compressed.title_ = compressed.title_ && old.title_;
ret.back () = compressed;
}
else
{
int compressed_count = 0;
for (vsize j = start_sys; j < start_sys + systems_per_page[i]; j++)
- compressed_count += (int)compressed[j].force_;
+ compressed_count += compressed[j].compressed_lines_count_ - 1;
ret.push_back (systems_per_page[i] + compressed_count);
start_sys += systems_per_page[i];
ragged_ = to_boolean (pb->paper_->c_variable ("ragged-bottom"));
ragged_last_ = to_boolean (pb->paper_->c_variable ("ragged-last-bottom"));
page_top_space_ = robust_scm2double (pb->paper_->c_variable ("page-top-space"), 0);
+ systems_per_page_ = robust_scm2int (pb->paper_->c_variable ("systems-per-page"), 0);
+ max_systems_per_page_ = robust_scm2int (pb->paper_->c_variable ("max-systems-per-page"), 0);
+
create_system_list ();
find_chunks_and_breaks (is_break);
}
return ragged_last_;
}
+int
+Page_breaking::systems_per_page () const
+{
+ return systems_per_page_;
+}
+
+int
+Page_breaking::max_systems_per_page () const
+{
+ return max_systems_per_page_;
+}
+
Real
Page_breaking::page_top_space () const
{
return ret;
}
+// If systems_per_page_ is positive, we don't really try to space on N pages;
+// we just put the requested number of systems on each page and penalize
+// if the result doesn't have N pages.
Page_spacing_result
Page_breaking::space_systems_on_n_pages (vsize configuration, vsize n, vsize first_page_num)
{
Page_spacing_result ret;
+ if (systems_per_page_ > 0)
+ {
+ Page_spacing_result ret = space_systems_with_fixed_number_per_page (configuration, first_page_num);
+ ret.demerits_ += (ret.force_.size () == n) ? 0 : BAD_SPACING_PENALTY;
+ return ret;
+ }
+
cache_line_details (configuration);
bool valid_n = (n >= min_page_count (configuration, first_page_num)
&& n <= cached_line_details_.size ());
return robust_scm2double (book_->paper_->lookup_variable (penalty_sym), 0.0);
}
+// If systems_per_page_ is positive, we don't really try to space on N
+// or N+1 pages; see the comment to space_systems_on_n_pages.
Page_spacing_result
Page_breaking::space_systems_on_n_or_one_more_pages (vsize configuration, vsize n, vsize first_page_num)
{
Page_spacing_result n_res;
Page_spacing_result m_res;
+ if (systems_per_page_ > 0)
+ {
+ Page_spacing_result ret = space_systems_with_fixed_number_per_page (configuration, first_page_num);
+ ret.demerits_ += (ret.force_.size () == n || ret.force_.size () == (n-1)) ? 0 : BAD_SPACING_PENALTY;
+ return ret;
+ }
+
cache_line_details (configuration);
vsize min_p_count = min_page_count (configuration, first_page_num);
bool valid_n = n >= min_p_count || n <= cached_line_details_.size ();
return finalize_spacing_result (configuration, best);
}
+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);
+}
+
Page_spacing_result
Page_breaking::pack_systems_on_least_pages (vsize configuration, vsize first_page_num)
{
{
Real f = res.force_[i];
if (isinf (f) && res.systems_per_page_[i] == 1)
- f = 20000;
+ f = BAD_SPACING_PENALTY;
page_force += f * f;
}