X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Fpage-layout-problem.cc;h=4e5a86d320bfe49cc4d78e42a36c38c30f7f0f56;hb=375c0be42300202d2f4b631f5302d817b8a91c60;hp=61a7ebb90168cf26a747bdee0f31b269b50b7cb8;hpb=8daea73d1db6182485bd4f9a0654b63d2fcedfb7;p=lilypond.git diff --git a/lily/page-layout-problem.cc b/lily/page-layout-problem.cc index 61a7ebb901..4e5a86d320 100644 --- a/lily/page-layout-problem.cc +++ b/lily/page-layout-problem.cc @@ -10,6 +10,7 @@ #include "page-layout-problem.hh" #include "align-interface.hh" +#include "axis-group-interface.hh" #include "hara-kiri-group-spanner.hh" #include "international.hh" #include "item.hh" @@ -26,6 +27,8 @@ Page_layout_problem::Page_layout_problem (Paper_book *pb, SCM page_scm, SCM syst Prob *page = unsmob_prob (page_scm); header_height_ = 0; footer_height_ = 0; + header_padding_ = 0; + footer_padding_ = 0; page_height_ = 100; if (page) @@ -61,16 +64,19 @@ Page_layout_problem::Page_layout_problem (Paper_book *pb, SCM page_scm, SCM syst after_title_spacing = paper->c_variable ("after-title-spacing"); before_title_spacing = paper->c_variable ("before-title-spacing"); between_title_spacing = paper->c_variable ("between-title-spacing"); - last_system_spacing = paper->c_variable ("last-system-spacing"); - first_system_spacing = paper->c_variable ("first-system-spacing"); + last_system_spacing = paper->c_variable ("bottom-system-spacing"); + first_system_spacing = paper->c_variable ("top-system-spacing"); if (scm_is_pair (systems) && unsmob_prob (scm_car (systems))) - first_system_spacing = paper->c_variable ("first-system-title-spacing"); + first_system_spacing = paper->c_variable ("top-title-spacing"); // Note: the page height here does _not_ reserve space for headers and - // footers. This is because we want to anchor the first-system-spacing + // footers. This is because we want to anchor the top-system-spacing // spring at the _top_ of the header. page_height_ -= robust_scm2double (paper->c_variable ("top-margin"), 0) + robust_scm2double (paper->c_variable ("bottom-margin"), 0); + + read_spacing_spec (first_system_spacing, &header_padding_, ly_symbol2scm ("padding")); + read_spacing_spec (last_system_spacing, &footer_padding_, ly_symbol2scm ("padding")); } bool last_system_was_title = false; @@ -120,6 +126,26 @@ Page_layout_problem::Page_layout_problem (Paper_book *pb, SCM page_scm, SCM syst read_spacing_spec (last_system_spacing, &last_padding, ly_symbol2scm ("padding")); last_spring.ensure_min_distance (last_padding - bottom_skyline_.max_height () + footer_height_); springs_.push_back (last_spring); + + if (elements_.size ()) + { + Real bottom_padding = 0; + + // TODO: junk bottom-space now that we have bottom-system-spacing? + // bottom-space has the flexibility that one can do it per-system. + // NOTE: bottom-space is misnamed since it is not stretchable space. + if (Prob *p = elements_.back ().prob) + bottom_padding = robust_scm2double (p->get_property ("bottom-space"), 0); + else if (elements_.back ().staves.size ()) + { + SCM details = get_details (elements_.back ()); + bottom_padding = robust_scm2double (ly_assoc_get (ly_symbol2scm ("bottom-space"), + details, + SCM_BOOL_F), + 0.0); + } + page_height_ -= bottom_padding; + } } void @@ -134,26 +160,12 @@ Page_layout_problem::set_footer_height (Real height) footer_height_ = height; } -Grob* -Page_layout_problem::find_vertical_alignment (System *sys) -{ - extract_grob_set (sys, "elements", elts); - for (vsize i = 0; i < elts.size (); ++i) - if (Align_interface::has_interface (elts[i])) - return elts[i]; - - return 0; -} - void Page_layout_problem::append_system (System *sys, Spring const& spring, Real padding) { - Grob *align = find_vertical_alignment (sys); + Grob *align = sys->get_vertical_alignment (); if (!align) - { - sys->programming_error ("no VerticalAlignment in system: can't do vertical spacing"); - return; - } + return; align->set_property ("positioning-done", SCM_BOOL_T); @@ -191,9 +203,6 @@ Page_layout_problem::append_system (System *sys, Spring const& spring, Real padd // we are only adding springs _between_ staves here. if (!found_spaceable_staff) { - if (i > 0) - add_loose_lines_as_spaceable_lines (elts, minimum_offsets, 0, i-1); - found_spaceable_staff = true; last_spaceable_staff = i; continue; @@ -204,7 +213,7 @@ Page_layout_problem::append_system (System *sys, Spring const& spring, Real padd alter_spring_from_spacing_spec (spec, &spring); springs_.push_back (spring); - Real min_distance = minimum_offsets[last_spaceable_staff] - minimum_offsets[i]; + Real min_distance = (found_spaceable_staff ? minimum_offsets[last_spaceable_staff] : 0) - minimum_offsets[i]; springs_.back ().ensure_min_distance (min_distance); if (scm_is_pair (manual_dists)) @@ -222,54 +231,14 @@ Page_layout_problem::append_system (System *sys, Spring const& spring, Real padd last_spaceable_staff = i; } } - // Any loose lines hanging off the end are treated as spaceable - // lines. This might give slightly weird results if the hanging - // systems have staff-affinity != UP. It's not quite clear what - // should happen in that case, though. - if (last_spaceable_staff + 1 < elts.size ()) - add_loose_lines_as_spaceable_lines (elts, minimum_offsets, - found_spaceable_staff ? last_spaceable_staff + 1 : 0, - elts.size () - 1); + // Corner case: there was only one staff, and it wasn't spaceable. // Mark it spaceable, because we do not allow non-spaceable staves // to be at the top or bottom of a system. - else if (!found_spaceable_staff && elts.size ()) + if (!found_spaceable_staff && elts.size ()) mark_as_spaceable (elts[0]); } -// first and last are inclusive -void -Page_layout_problem::add_loose_lines_as_spaceable_lines (vector const& elts, - vector const& minimum_offsets, - vsize first, vsize last) -{ - vsize start = first; - vsize end = last; - if (start > 0) - --start; - if (end + 1 < elts.size ()) - ++end; - - for (vsize i = start; i < end; ++i) - { - SCM spec = get_spacing_spec (elts[i], elts[i+1]); - Spring spring (1.0, 0.0); - alter_spring_from_spacing_spec (spec, &spring); - if (spec == SCM_BOOL_F) - { - spring.set_inverse_compress_strength (10000); - spring.set_inverse_stretch_strength (10000); - } - - Real min_distance = minimum_offsets[i] - minimum_offsets[i+1]; - spring.ensure_min_distance (min_distance); - springs_.push_back (spring); - } - - for (vsize i = first; i <= last; ++i) - mark_as_spaceable (elts[i]); -} - void Page_layout_problem::append_prob (Prob *prob, Spring const& spring, Real padding) { @@ -304,30 +273,7 @@ Page_layout_problem::solve_rod_spring_problem (bool ragged) for (vsize i = 0; i < springs_.size (); ++i) spacer.add_spring (springs_[i]); - Real bottom_padding = 0; - Interval first_staff_iv (0, 0); - Interval last_staff_iv (0, 0); - if (elements_.size ()) - { - first_staff_iv = first_staff_extent (elements_[0]); - last_staff_iv = last_staff_extent (elements_.back ()); - - // TODO: junk bottom-space now that we have last-spring-spacing? - // bottom-space has the flexibility that one can do it per-system. - // NOTE: bottom-space is misnamed since it is not stretchable space. - if (Prob *p = elements_.back ().prob) - bottom_padding = robust_scm2double (p->get_property ("bottom-space"), 0); - else if (elements_.back ().staves.size ()) - { - SCM details = get_details (elements_.back ()); - bottom_padding = robust_scm2double (ly_assoc_get (ly_symbol2scm ("bottom-space"), - details, - SCM_BOOL_F), - 0.0); - } - } - - spacer.solve (page_height_ - bottom_padding, ragged); + spacer.solve (page_height_, ragged); solution_ = spacer.spring_positions (); } @@ -344,12 +290,36 @@ Page_layout_problem::find_system_offsets () // spring_idx 0 is the top of the page. Interesting values start from 1. vsize spring_idx = 1; + vector loose_lines; + vector loose_line_min_distances; + Grob *last_spaceable_line = 0; + Real last_spaceable_line_translation = 0; for (vsize i = 0; i < elements_.size (); ++i) { if (elements_[i].prob) { *tail = scm_cons (scm_from_double (solution_[spring_idx]), SCM_EOL); tail = SCM_CDRLOC (*tail); + + // Lay out any non-spaceable lines between this line and + // the last one. + if (loose_lines.size ()) + { + Interval loose_extent = loose_lines.back ()->extent (loose_lines.back (), Y_AXIS); + Interval prob_extent = unsmob_stencil (elements_[i].prob->get_property ("stencil"))->extent (Y_AXIS); + Real min_distance = -loose_extent[DOWN] + prob_extent[UP]; // TODO: include padding/minimum-distance + + loose_line_min_distances.push_back (min_distance); + loose_lines.push_back (0); + + distribute_loose_lines (loose_lines, loose_line_min_distances, + last_spaceable_line_translation, -solution_[spring_idx]); + loose_lines.clear (); + loose_line_min_distances.clear (); + } + + last_spaceable_line = 0; + last_spaceable_line_translation = -solution_[spring_idx]; spring_idx++; } else @@ -370,14 +340,12 @@ Page_layout_problem::find_system_offsets () // Position the staves within this system. Real translation = 0; - vector loose_lines; vector const& min_offsets = elements_[i].min_offsets; - vector loose_line_min_distances; - Grob *last_spaceable_line = 0; - Real last_spaceable_line_translation = 0; + bool found_spaceable_staff = false; for (vsize staff_idx = 0; staff_idx < elements_[i].staves.size (); ++staff_idx) { Grob *staff = elements_[i].staves[staff_idx]; + staff->set_property ("system-Y-offset", scm_from_double (-system_position)); if (is_spaceable (staff)) { @@ -391,15 +359,18 @@ Page_layout_problem::find_system_offsets () { loose_line_min_distances.push_back (min_offsets[staff_idx-1] - min_offsets[staff_idx]); loose_lines.push_back (staff); + distribute_loose_lines (loose_lines, loose_line_min_distances, - last_spaceable_line_translation, translation); + last_spaceable_line_translation, translation - system_position); loose_lines.clear (); loose_line_min_distances.clear (); } last_spaceable_line = staff; - last_spaceable_line_translation = translation; + // Negative is down but the translation is relative to the whole page. + last_spaceable_line_translation = -system_position + translation; staff->translate_axis (translation, Y_AXIS); + found_spaceable_staff = true; } else { @@ -407,14 +378,27 @@ Page_layout_problem::find_system_offsets () loose_lines.push_back (last_spaceable_line); loose_lines.push_back (staff); - loose_line_min_distances.push_back (min_offsets[staff_idx-1] - min_offsets[staff_idx]); + if (staff_idx) + loose_line_min_distances.push_back (min_offsets[staff_idx-1] - min_offsets[staff_idx]); + else + { + Real min_dist = 0; + if (last_spaceable_line) + min_dist = Axis_group_interface::minimum_distance (last_spaceable_line, + staff, + Y_AXIS); + else // distance to the top margin + min_dist = header_padding_ + header_height_ + staff->extent (staff, Y_AXIS)[UP]; + + loose_line_min_distances.push_back (min_dist); + } } } // Corner case: even if a system has no live staves, it still takes up // one spring (a system with one live staff also takes up one spring), // which we need to increment past. - if (elements_[i].staves.empty ()) + if (!found_spaceable_staff) spring_idx++; *tail = scm_cons (scm_from_double (system_position), SCM_EOL); @@ -422,6 +406,18 @@ Page_layout_problem::find_system_offsets () } } + if (loose_lines.size ()) + { + Grob *last = loose_lines.back (); + Interval last_ext = last->extent (last, Y_AXIS); + loose_line_min_distances.push_back (-last_ext[DOWN] + footer_height_ + footer_padding_); + loose_lines.push_back (0); + + distribute_loose_lines (loose_lines, loose_line_min_distances, + last_spaceable_line_translation, -page_height_); + + } + assert (spring_idx == solution_.size () - 1); return system_offsets; } @@ -442,9 +438,14 @@ Page_layout_problem::distribute_loose_lines (vector const &loose_lines, alter_spring_from_spacing_spec (spec, &spring); spring.ensure_min_distance (min_distances[i]); - if (spec == SCM_BOOL_F) + if ((spec == SCM_BOOL_F && loose_lines[0] && loose_lines.back ()) + || !loose_lines[i] + || !loose_lines[i+1]) { // Insert a very flexible spring, so it doesn't have much effect. + // TODO: set a default distance and a compress strength so that a + // lyrics line, for example, will stay closer to the top staff + // even in a compressed configuration. spring.set_inverse_stretch_strength (100000); spring.set_inverse_compress_strength (100000); } @@ -457,7 +458,10 @@ Page_layout_problem::distribute_loose_lines (vector const &loose_lines, vector solution = spacer.spring_positions (); for (vsize i = 1; i + 1 < solution.size (); ++i) - loose_lines[i]->translate_axis (first_translation - solution[i], Y_AXIS); + { + Real system_offset = scm_to_double (loose_lines[i]->get_property ("system-Y-offset")); + loose_lines[i]->translate_axis (first_translation - solution[i] - system_offset, Y_AXIS); + } } SCM @@ -487,7 +491,9 @@ Page_layout_problem::build_system_skyline (vector const& staves, assert (staves.size () == minimum_translations.size ()); Real first_translation = minimum_translations[0]; - Real last_dy = 0; + Real last_spaceable_dy = 0; + Real first_spaceable_dy = 0; + bool found_spaceable_staff = false; for (vsize i = 0; i < staves.size (); ++i) { @@ -503,14 +509,25 @@ Page_layout_problem::build_system_skyline (vector const& staves, down->raise (-dy); down->merge ((*sky)[DOWN]); down->raise (dy); - - last_dy = dy; + } + if (is_spaceable (staves[i])) + { + if (!found_spaceable_staff) + { + found_spaceable_staff = true; + first_spaceable_dy = dy; + } + last_spaceable_dy = dy; } } + // Leave the up skyline at a position relative + // to the top spaceable staff. + up->raise (-first_spaceable_dy); + // Leave the down skyline at a position - // relative to the bottom staff. - down->raise (-last_dy); + // relative to the bottom spaceable staff. + down->raise (-last_spaceable_dy); } Interval @@ -588,6 +605,9 @@ Page_layout_problem::read_spacing_spec (SCM spec, Real* dest, SCM sym) SCM Page_layout_problem::get_spacing_spec (Grob *before, Grob *after) { + if (!before || !after) + return SCM_BOOL_F; + if (is_spaceable (before)) { if (is_spaceable (after))