X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpage-breaking.cc;h=fb476848983f6a6ff0ce60ea10c014fd9e294fa0;hb=97a0169312a260933246ab224e4f8b0969871dd5;hp=9a6f8f40f25c0edbe47f45ecde1780c2babc89b6;hpb=01df8ad908c92687d0c352e5ad5f067e52809423;p=lilypond.git diff --git a/lily/page-breaking.cc b/lily/page-breaking.cc index 9a6f8f40f2..fb47684898 100644 --- a/lily/page-breaking.cc +++ b/lily/page-breaking.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 2006--2012 Joe Neeman + Copyright (C) 2006--2015 Joe Neeman LilyPond is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -195,7 +195,6 @@ compress_lines (const vector &orig) else { ret.push_back (orig[i]); - ret.back ().force_ = 0; } } return ret; @@ -555,7 +554,7 @@ Page_breaking::draw_page (SCM systems, SCM configuration, int page_num, bool las for (SCM s = systems; scm_is_pair (s); s = scm_cdr (s)) { SCM paper_system = scm_car (s); - if (Grob *g = unsmob_grob (scm_car (s))) + if (Grob *g = unsmob (scm_car (s))) { System *sys = dynamic_cast (g); paper_system = sys->get_paper_system (); @@ -568,11 +567,11 @@ Page_breaking::draw_page (SCM systems, SCM configuration, int page_num, bool las // Create the page and draw it. SCM page = make_page (page_num, last); - Prob *p = unsmob_prob (page); + Prob *p = unsmob (page); p->set_property ("lines", paper_systems); p->set_property ("configuration", configuration); - Stencil *foot_p = unsmob_stencil (p->get_property ("foot-stencil")); + Stencil *foot_p = unsmob (p->get_property ("foot-stencil")); Stencil foot = foot_p ? *foot_p : Stencil (); SCM footnotes = Page_layout_problem::get_footnotes_from_lines (systems); @@ -595,7 +594,7 @@ Page_breaking::make_pages (vector lines_per_page, SCM systems) SCM ret = SCM_EOL; bool reset_footnotes_on_new_page = to_boolean (book_->top_paper ()->c_variable ("reset-footnotes-on-new-page")); SCM label_page_table = book_->top_paper ()->c_variable ("label-page-table"); - if (label_page_table == SCM_UNDEFINED) + if (SCM_UNBNDP (label_page_table)) label_page_table = SCM_EOL; // Build a list of (systems configuration . footnote-count) triples. @@ -632,7 +631,11 @@ Page_breaking::make_pages (vector lines_per_page, SCM systems) else config = layout.solution (rag); - last_page_force = layout.force (); + if ((ragged () && layout.force () < 0.0) + || isinf (layout.force ())) + warning (_f ("page %d has been compressed", page_num)); + else + last_page_force = layout.force (); systems_configs_fncounts = scm_cons (scm_cons (lines, config), systems_configs_fncounts); footnote_count += fn_lines; @@ -648,19 +651,19 @@ Page_breaking::make_pages (vector lines_per_page, SCM systems) SCM lines = scm_caar (s); SCM config = scm_cdar (s); - bool bookpart_last_page = (s == systems_configs_fncounts); + bool bookpart_last_page = scm_is_eq (s, systems_configs_fncounts); SCM page = draw_page (lines, config, page_num, bookpart_last_page); /* collect labels */ SCM page_num_scm = scm_from_int (page_num); for (SCM l = lines; scm_is_pair (l); l = scm_cdr (l)) { SCM labels = SCM_EOL; - if (Grob *line = unsmob_grob (scm_car (l))) + if (Grob *line = unsmob (scm_car (l))) { System *system = dynamic_cast (line); labels = system->get_property ("labels"); } - else if (Prob *prob = unsmob_prob (scm_car (l))) + else if (Prob *prob = unsmob (scm_car (l))) labels = prob->get_property ("labels"); for (SCM lbls = labels; scm_is_pair (lbls); lbls = scm_cdr (lbls)) @@ -686,13 +689,13 @@ Page_breaking::create_system_list () SCM specs = book_->get_system_specs (); for (SCM s = specs; scm_is_pair (s); s = scm_cdr (s)) { - if (Paper_score *ps = dynamic_cast (unsmob_music_output (scm_car (s)))) + if (Paper_score *ps = unsmob (scm_car (s))) { system_specs_.push_back (System_spec (ps)); } else { - Prob *pb = unsmob_prob (scm_car (s)); + Prob *pb = unsmob (scm_car (s)); assert (pb); pb->protect (); @@ -744,7 +747,7 @@ Page_breaking::find_chunks_and_breaks (Break_predicate is_break, Prob_break_pred vector line_breaker_columns; line_breaker_columns.push_back (0); - for (vsize j = 1; j < cols.size (); j++) + for (vsize j = 0; j < cols.size (); j++) { if (forced_line_break_cols.size ()) { @@ -757,7 +760,7 @@ Page_breaking::find_chunks_and_breaks (Break_predicate is_break, Prob_break_pred bool last = (j == cols.size () - 1); bool break_point = is_break && is_break (cols[j]); - bool chunk_end = cols[j]->get_property ("page-break-permission") == force_sym; + bool chunk_end = scm_is_eq (cols[j]->get_property ("page-break-permission"), force_sym); Break_position cur_pos = Break_position (i, line_breaker_columns.size (), cols[j], @@ -1130,7 +1133,7 @@ Page_breaking::min_page_count (vsize configuration, vsize first_page_num) if ((!too_few_lines (line_count) && (next_height > cur_page_height && cur_rod_height > 0)) || too_many_lines (next_line_count) - || (prev && prev->page_permission_ == ly_symbol2scm ("force"))) + || (prev && scm_is_eq (prev->page_permission_, ly_symbol2scm ("force")))) { line_count = cur.compressed_nontitle_lines_count_; cur_rod_height = cur.full_height (); @@ -1169,9 +1172,8 @@ Page_breaking::min_page_count (vsize configuration, vsize first_page_num) cur_page_height -= min_whitespace_at_top_of_page (cached_line_details_[page_starter]); cur_page_height -= min_whitespace_at_bottom_of_page (cached_line_details_.back ()); - Real cur_height = cur_rod_height + ((ragged_last () || ragged ()) ? cur_spring_height : 0); if (!too_few_lines (line_count - cached_line_details_.back ().compressed_nontitle_lines_count_) - && cur_height > cur_page_height + && cur_rod_height > cur_page_height /* don't increase the page count if the last page had only one system */ && cur_rod_height > cached_line_details_.back ().full_height ()) ret++; @@ -1330,7 +1332,7 @@ Page_breaking::space_systems_with_fixed_number_per_page (vsize configuration, system_count_on_this_page += cur_line.compressed_nontitle_lines_count_; line++; - if (cur_line.page_permission_ == ly_symbol2scm ("force")) + if (scm_is_eq (cur_line.page_permission_, ly_symbol2scm ("force"))) break; } @@ -1372,7 +1374,8 @@ Page_breaking::pack_systems_on_least_pages (vsize configuration, vsize first_pag if ((line > page_first_line) && (isinf (space.force_) || ((line > 0) - && (cached_line_details_[line - 1].page_permission_ == ly_symbol2scm ("force"))))) + && scm_is_eq (cached_line_details_[line - 1].page_permission_, + ly_symbol2scm ("force"))))) { res.systems_per_page_.push_back (line - page_first_line); res.force_.push_back (prev_force); @@ -1437,7 +1440,9 @@ Page_breaking::finalize_spacing_result (vsize configuration, Page_spacing_result line_penalty += uncompressed_line_details_[i].break_penalty_; } - for (vsize i = 0; i < res.force_.size (); i++) + for (vsize i = ragged () ? res.force_.size () - 1 : 0; + i < res.force_.size () - (is_last () && ragged_last ()); + i++) { Real f = res.force_[i]; @@ -1494,7 +1499,8 @@ Page_breaking::space_systems_on_2_pages (vsize configuration, vsize first_page_n /* if there is a forced break, this reduces to 2 1-page problems */ cache_line_details (configuration); for (vsize i = 0; i + 1 < cached_line_details_.size (); i++) - if (cached_line_details_[i].page_permission_ == ly_symbol2scm ("force")) + if (scm_is_eq (cached_line_details_[i].page_permission_, + ly_symbol2scm ("force"))) { vector lines1 (cached_line_details_.begin (), cached_line_details_.begin () + i + 1); vector lines2 (cached_line_details_.begin () + i + 1, cached_line_details_.end ()); @@ -1545,9 +1551,11 @@ Page_breaking::space_systems_on_2_pages (vsize configuration, vsize first_page_n page1_penalty[i] = line_count_penalty (page1_line_count); page1_status[i] = line_count_status (page1_line_count); - if (ragged2) + if (ragged1) page2_force[page2_force.size () - 1 - i] = (page2.force_ < 0 && i + 1 < page1_force.size ()) ? infinity_f : 0; + else if (ragged2 && page2.force_ > 0) + page2_force[page2_force.size () - 1 - i] = 0.0; else page2_force[page2_force.size () - 1 - i] = page2.force_; page2_penalty[page2_penalty.size () - 1 - i] = line_count_penalty (page2_line_count);