#include "page-breaking.hh"
#include "warn.hh"
-/* In order to prevent possible division by zero, we require every line
- to have a spring of non-zero length. */
-Real
-line_space (const Line_details &line)
-{
- return max (0.1, line.space_);
-}
-
void
Page_spacing::calc_force ()
{
- if (rod_height_ + last_line_.bottom_padding_ >= page_height_ || !inverse_spring_k_)
+ /* If the first system is a title, we add back in the page-top-space. */
+ Real height = first_line_.title_ ? page_height_ + page_top_space_ : page_height_;
+
+ if (rod_height_ + last_line_.bottom_padding_ >= height)
force_ = infinity_f;
else
- force_ = (page_height_ - rod_height_ - last_line_.bottom_padding_ - spring_len_) / inverse_spring_k_;
+ force_ = (height - rod_height_ - last_line_.bottom_padding_ - spring_len_)
+ / max (0.1, inverse_spring_k_);
+}
+
+void
+Page_spacing::resize (Real new_height)
+{
+ page_height_ = new_height;
+ calc_force ();
}
void
Page_spacing::append_system (const Line_details &line)
{
+ if (!rod_height_)
+ first_line_ = line;
+
rod_height_ += last_line_.padding_;
rod_height_ += line.extent_.length ();
- spring_len_ += line_space (line);
- inverse_spring_k_ += max (0.1, line.inverse_hooke_);
+ spring_len_ += line.space_;
+ inverse_spring_k_ += line.inverse_hooke_;
last_line_ = line;
last_line_ = line;
rod_height_ += line.extent_.length ();
- spring_len_ += line_space (line);
- inverse_spring_k_ += max (0.1, line.inverse_hooke_);
+ spring_len_ += line.space_;
+ inverse_spring_k_ += line.inverse_hooke_;
+
+ first_line_ = line;
calc_force ();
}
breaker_ = breaker;
max_page_count_ = 0;
ragged_ = breaker->ragged ();
- ragged_last_ = breaker->last () && breaker->ragged_last ();
+ ragged_last_ = breaker->is_last () && breaker->ragged_last ();
}
-Spacing_result
+Page_spacing_result
Page_spacer::solve (vsize page_count)
{
if (page_count > max_page_count_)
resize (page_count);
- Spacing_result ret;
+ Page_spacing_result ret;
ret.force_.resize (page_count);
ret.systems_per_page_.resize (page_count);
system = i;
}
else
- return Spacing_result (); /* couldn't salvage it -- probably going to crash */
+ return Page_spacing_result (); /* couldn't salvage it -- probably going to crash */
}
ret.penalty_ = state_.at (system, page_count-1).penalty_
Page_spacer::calc_subproblem (vsize page, vsize line)
{
bool last = line == lines_.size () - 1;
- Page_spacing space (breaker_->page_height (page + first_page_num_, last));
+ Page_spacing space (breaker_->page_height (page + first_page_num_, last),
+ breaker_->page_top_space ());
Page_spacing_node &cur = state_.at (line, page);
bool ragged = ragged_ || (ragged_last_ && last);