X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Finclude%2Fpage-spacing.hh;h=958a1b21ff08b2bffd51b5746db2f29abaf91daf;hb=38d7d319eabc906e82fb42002678c6d42a23b6f7;hp=e1fa582d922fa8013e7d9535945db9f33e0feba7;hpb=474c8729dc274a30558102a015a01fa5882673db;p=lilypond.git diff --git a/lily/include/page-spacing.hh b/lily/include/page-spacing.hh index e1fa582d92..958a1b21ff 100644 --- a/lily/include/page-spacing.hh +++ b/lily/include/page-spacing.hh @@ -4,37 +4,45 @@ source file of the GNU LilyPond music typesetter - (c) 2006--2007 Joe Neeman + (c) 2006--2009 Joe Neeman */ #ifndef PAGE_SPACING_HH #define PAGE_SPACING_HH #include "constrained-breaking.hh" +#include "page-spacing-result.hh" + +/* This is a penalty that we add whenever a page breaking solution + is not bad enough to completely discard, but bad enough that + it is worse than any "proper" solution. For example, if we didn't + manage to fit systems on the desired number of pages or if there was + too big for a page. + + This constant is large enough that it dominates any reasonable penalty, + but small enough that nothing will overflow to infinity (so that we + can still distinguish bad spacings by the number of BAD_SPACING_PENALTYs + that they incur. + + BAD_SPACING_PENALTY is for occasions where the spacing is bad. + TERRIBLE_SPACING_PENALTY is for when we are disregarding a user override + (for example, we are failing to satisfy min-systems-per-page). These user + overrides are more important than getting good spacing, so they get a + larger penalty. +*/ +const Real BAD_SPACING_PENALTY = 1e6; +const Real TERRIBLE_SPACING_PENALTY = 1e8; -struct Spacing_result { - vector systems_per_page_; - vector force_; - Real penalty_; - Real demerits_; - - Spacing_result () - { - penalty_ = 0; - demerits_ = infinity_f; - } -}; /* for page_count > 2, we use a dynamic algorithm similar to constrained-breaking -- we have a class that stores the intermediate calculations so they can be reused for querying different page counts. */ - class Page_spacer { public: - Page_spacer (vector const &lines, Real page_height, bool ragged, bool ragged_last); - Spacing_result solve (vsize page_count); + Page_spacer (vector const &lines, vsize first_page_num, Page_breaking const*); + Page_spacing_result solve (vsize page_count); private: struct Page_spacing_node @@ -45,15 +53,18 @@ private: force_ = infinity_f; penalty_ = infinity_f; prev_ = VPOS; + system_count_status_ = SYSTEM_COUNT_OK; } Real demerits_; Real force_; Real penalty_; vsize prev_; + int system_count_status_; }; - Real page_height_; + Page_breaking const *breaker_; + vsize first_page_num_; vector lines_; Matrix state_; vsize max_page_count_; @@ -65,29 +76,30 @@ private: bool calc_subproblem (vsize page, vsize lines); }; -vsize -min_page_count (vector const &lines, - Real page_height, bool ragged, bool ragged_last); - -Spacing_result -space_systems_on_n_pages (vector const&, - vsize n, - Real page_height, - bool ragged, - bool ragged_last); - -Spacing_result -space_systems_on_n_or_one_more_pages (vector const&, - vsize n, - Real page_height, - Real odd_pages_penalty, - bool ragged, - bool ragged_last); -Spacing_result -space_systems_on_best_pages (vector const&, - Real page_height, - Real odd_pages_penalty, - bool ragged, - bool ragged_last); +struct Page_spacing +{ + Real force_; + Real page_height_; + Real rod_height_; + Real spring_len_; + Real inverse_spring_k_; + Real page_top_space_; + + Line_details last_line_; + Line_details first_line_; + + Page_spacing (Real page_height, Real page_top_space) + { + page_height_ = page_height; + page_top_space_ = page_top_space; + clear (); + } + + void calc_force (); + void resize (Real new_height); + void append_system (const Line_details &line); + void prepend_system (const Line_details &line); + void clear (); +}; #endif /* PAGE_SPACING_HH */