title_ = to_boolean (pb->get_property ("is-title"));
compressed_lines_count_ = 1;
compressed_nontitle_lines_count_ = title_ ? 0 : 1;
+ SCM last_scm = pb->get_property ("last-markup-line");
+ last_markup_line_ = to_boolean (last_scm);
+ SCM first_scm = pb->get_property ("first-markup-line");
+ first_markup_line_ = to_boolean (first_scm);
}
class. */
int compressed_lines_count_;
int compressed_nontitle_lines_count_;
+ bool last_markup_line_;
+ bool first_markup_line_;
Line_details ()
{
title_ = false;
compressed_lines_count_ = 1;
compressed_nontitle_lines_count_ = 1;
+ last_markup_line_ = false;
+ first_markup_line_ = false;
}
Line_details (Prob *pb, Output_def *paper);
bool too_few_lines (int line_count) const;
Real min_whitespace_at_top_of_page (Line_details const&) const;
Real min_whitespace_at_bottom_of_page (Line_details const&) const;
+ int orphan_penalty () const;
protected:
Paper_book *book_;
int max_systems_per_page_;
int min_systems_per_page_;
vsize system_count_;
+ int orphan_penalty_;
vector<Line_division> current_configurations_;
vector<Break_position> current_chunks_;
systems_per_page_ = max (0, robust_scm2int (pb->paper_->c_variable ("systems-per-page"), 0));
max_systems_per_page_ = max (0, robust_scm2int (pb->paper_->c_variable ("max-systems-per-page"), 0));
min_systems_per_page_ = max (0, robust_scm2int (pb->paper_->c_variable ("min-systems-per-page"), 0));
+ orphan_penalty_ = robust_scm2int (pb->paper_->c_variable ("orphan-penalty"), 100000);
if (systems_per_page_ && (max_systems_per_page_ || min_systems_per_page_))
{
// FIXME: take into account the height of the footer
return max (0.0, max (padding, min_distance + line.extent_[DOWN]));
}
+
+int
+Page_breaking::orphan_penalty () const
+{
+ return orphan_penalty_;
+}
penalty += lines_[page_start-1].page_penalty_
+ (page % 2 == 0) ? lines_[page_start-1].turn_penalty_ : 0;
+ /* Deal with widow/orphan lines */
+ /* Last line of paragraph is first line on the new page */
+ if ((page_start > 0) &&
+ (page_start < lines_.size ()) &&
+ (lines_[page_start].last_markup_line_))
+ penalty += breaker_->orphan_penalty ();
+ /* First line of paragraph is last line on the previous page */
+ if ((page_start > 0) &&
+ (page_start < lines_.size ()) &&
+ (lines_[page_start-1].first_markup_line_))
+ penalty += breaker_->orphan_penalty ();
+
demerits += penalty;
if (demerits < cur.demerits_ || page_start == line)
{
paper_->self_scm (),
page_properties,
scm_car (s));
- for (SCM list = texts ; scm_is_pair (list) ; list = scm_cdr (list))
+ Prob *ps;
+ SCM list;
+ for (list = texts ; scm_is_pair (list) ; list = scm_cdr (list))
{
SCM t = scm_car (list);
// TODO: init props
- Prob *ps = make_paper_system (SCM_EOL);
+ ps = make_paper_system (SCM_EOL);
ps->set_property ("page-break-permission",
ly_symbol2scm ("allow"));
ps->set_property ("page-turn-permission",
ly_symbol2scm ("allow"));
+ ps->set_property ("last-markup-line", SCM_BOOL_F);
+ ps->set_property ("first-markup-line",
+ list == texts? SCM_BOOL_T : SCM_BOOL_F);
paper_system_set_stencil (ps, *unsmob_stencil (t));
ps->set_property ("is-title", SCM_BOOL_T);
// FIXME: figure out penalty.
//set_system_penalty (ps, scores_[i].header_);
}
+ // We may want to place a check here, for whether the line is too short
+ if (list == texts)
+ {
+ // if there is only one line in the paragraph,
+ // do not try to avoid orphans
+ ps->set_property ("last-markup-line", SCM_BOOL_F);
+ ps->set_property ("first-markup-line", SCM_BOOL_F);
+ }
+ else
+ {
+ ps->set_property ("last-markup-line", SCM_BOOL_T);
+ }
}
else
assert (0);