From 04c60c47270930d2cca034bfbd0104bda3abbf6a Mon Sep 17 00:00:00 2001 From: Nicolas Sceaux Date: Tue, 11 Nov 2008 16:36:16 +0100 Subject: [PATCH] Nested book parts: take account of Joe's code review from 2008/11/03 Use is-last-bookpart and is-bookpart-last-page properties everywhere, instead of confusing different names. --- input/new/book-parts.ly | 1 - lily/page-breaking.cc | 17 ++++++++--------- lily/paper-book.cc | 2 +- ly/titling-init.ly | 33 +++++++++++++++++++------------- scm/layout-page-layout.scm | 39 +++++++++++++++++++------------------- scm/page.scm | 10 +++++----- scm/titling.scm | 11 +++++------ 7 files changed, 58 insertions(+), 55 deletions(-) diff --git a/input/new/book-parts.ly b/input/new/book-parts.ly index 2e87120fd1..1b4754dc6c 100644 --- a/input/new/book-parts.ly +++ b/input/new/book-parts.ly @@ -17,7 +17,6 @@ difference with the book last page. %% book paper, which is inherited by all children bookparts \paper { - id = "\nbook level paper\n" ragged-last-bottom = ##t %% Page footer: add a different part-tagline at part last page oddFooterMarkup = \markup { diff --git a/lily/page-breaking.cc b/lily/page-breaking.cc index 56746a6a2f..a111d933e5 100644 --- a/lily/page-breaking.cc +++ b/lily/page-breaking.cc @@ -212,7 +212,7 @@ Page_breaking::systems () Real Page_breaking::page_height (int page_num, bool last) const { - bool last_part = ly_scm2bool (book_->paper_->c_variable ("part-is-last")); + bool last_part = ly_scm2bool (book_->paper_->c_variable ("is-last-bookpart")); SCM mod = scm_c_resolve_module ("scm page"); SCM calc_height = scm_c_module_lookup (mod, "calc-printable-height"); SCM make_page = scm_c_module_lookup (mod, "make-page"); @@ -223,8 +223,8 @@ Page_breaking::page_height (int page_num, bool last) const SCM page = scm_apply_0 (make_page, scm_list_n ( book_->self_scm (), ly_symbol2scm ("page-number"), scm_from_int (page_num), - ly_symbol2scm ("is-last"), scm_from_bool (last_part && last), - ly_symbol2scm ("is-part-last"), scm_from_bool (last), + ly_symbol2scm ("is-last-bookpart"), scm_from_bool (last_part), + ly_symbol2scm ("is-bookpart-last-page"), scm_from_bool (last), SCM_UNDEFINED)); SCM height = scm_apply_1 (calc_height, page, SCM_EOL); return scm_to_double (height) - page_top_space_; @@ -256,7 +256,7 @@ Page_breaking::make_pages (vector lines_per_page, SCM systems) SCM book = book_->self_scm (); int first_page_number = robust_scm2int (book_->paper_->c_variable ("first-page-number"), 1); - bool last_part = ly_scm2bool (book_->paper_->c_variable ("part-is-last")); + bool last_bookpart = ly_scm2bool (book_->paper_->c_variable ("is-last-bookpart")); SCM ret = SCM_EOL; SCM label_page_table = book_->top_paper ()->c_variable ("label-page-table"); if (label_page_table == SCM_UNDEFINED) @@ -265,15 +265,14 @@ Page_breaking::make_pages (vector lines_per_page, SCM systems) for (vsize i = 0; i < lines_per_page.size (); i++) { SCM page_num = scm_from_int (i + first_page_number); - bool last_from_part = (i == lines_per_page.size () - 1); - bool last_from_book = (last_part && last_from_part); - SCM rag = scm_from_bool (ragged () || (last_from_part && ragged_last ())); + bool partbook_last_page = (i == lines_per_page.size () - 1); + SCM rag = scm_from_bool (ragged () || ( partbook_last_page && ragged_last ())); SCM line_count = scm_from_int (lines_per_page[i]); SCM lines = scm_list_head (systems, line_count); SCM page = scm_apply_0 (make_page, scm_list_n (book, lines, page_num, rag, - scm_from_bool (last_from_book), - scm_from_bool (last_from_part), + scm_from_bool (last_bookpart), + scm_from_bool (partbook_last_page), SCM_UNDEFINED)); /* collect labels */ for (SCM l = lines ; scm_is_pair (l) ; l = scm_cdr (l)) diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 0887f9312e..069fca16fd 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -143,7 +143,7 @@ Paper_book::output_aux (SCM output_channel, return; paper_->set_variable (ly_symbol2scm ("first-page-number"), scm_long2num (*first_page_number)); - paper_->set_variable (ly_symbol2scm ("part-is-last"), + paper_->set_variable (ly_symbol2scm ("is-last-bookpart"), ly_bool2scm (is_last)); /* Generate all stencils to trigger font loads. */ *first_page_number += scm_ilength (pages ()); diff --git a/ly/titling-init.ly b/ly/titling-init.ly index ebec85b53e..08b23d469d 100644 --- a/ly/titling-init.ly +++ b/ly/titling-init.ly @@ -83,11 +83,24 @@ scoreTitleMarkup = \markup { \column { empty-stencil)) #(define (last-page layout props arg) - (if (chain-assoc-get 'page:last? props #f) - (interpret-markup layout props arg) - empty-stencil)) + (if (and (chain-assoc-get 'page:is-bookpart-last-page props #f) + (chain-assoc-get 'page:is-last-bookpart props #f)) + (interpret-markup layout props arg) + empty-stencil)) + +#(define (not-first-page layout props arg) + (define (ancestor layout) + "Return the topmost layout ancestor" + (let ((parent (ly:output-def-parent layout))) + (if (not (ly:output-def? parent)) + layout + (ancestor parent)))) + (if (not (= (chain-assoc-get 'page:page-number props -1) + (ly:output-def-lookup (ancestor layout) 'first-page-number))) + (interpret-markup layout props arg) + empty-stencil)) -%% Part first page and last page predicates +%% Bookpart first page and last page predicates #(define (part-first-page layout props arg) (if (= (chain-assoc-get 'page:page-number props -1) (ly:output-def-lookup layout 'first-page-number)) @@ -95,15 +108,9 @@ scoreTitleMarkup = \markup { \column { empty-stencil)) #(define (part-last-page layout props arg) - (if (chain-assoc-get 'page:part-last? props #f) - (interpret-markup layout props arg) - empty-stencil)) - -#(define (not-first-page layout props arg) - (if (not (= (chain-assoc-get 'page:page-number props -1) - (ly:output-def-lookup layout 'first-page-number))) - (interpret-markup layout props arg) - empty-stencil)) + (if (chain-assoc-get 'page:is-bookpart-last-page props #f) + (interpret-markup layout props arg) + empty-stencil)) %% unused #(define (not-single-page layout props arg) diff --git a/scm/layout-page-layout.scm b/scm/layout-page-layout.scm index c5b8b65227..00add35806 100644 --- a/scm/layout-page-layout.scm +++ b/scm/layout-page-layout.scm @@ -31,7 +31,8 @@ (= (interval-start system-extent) (interval-end system-extent)))))) -(define (stretch-and-draw-page paper-book systems page-number ragged book-last part-last) +(define (stretch-and-draw-page paper-book systems page-number ragged + is-last-bookpart is-bookpart-last-page) (define (max-stretch sys) (if (ly:grob? sys) (ly:grob-property sys 'max-stretch) @@ -78,8 +79,8 @@ (let* ((page (make-page paper-book 'page-number page-number - 'is-last book-last - 'is-part-last part-last)) + 'is-last-bookpart is-last-bookpart + 'is-bookpart-last-page is-bookpart-last-page)) (paper (ly:paper-book-paper paper-book)) (height (page-printable-height page)) ; there is a certain amount of impreciseness going on here: @@ -352,8 +353,8 @@ is what have collected so far, and has ascending page numbers." inter-system-space)) user))) -(define (walk-paths done-lines best-paths current-lines is-last-part - is-last-page current-best paper-book page-alist) +(define (walk-paths done-lines best-paths current-lines is-last-bookpart + is-bookpart-last-page current-best paper-book page-alist) "Return the best optimal-page-break-node that contains CURRENT-LINES. DONE-LINES.reversed ++ CURRENT-LINES is a consecutive ascending range of lines, and BEST-PATHS contains the optimal breaks @@ -363,19 +364,19 @@ CURRENT-BEST is the best result sofar, or #f." (let* ((paper (ly:paper-book-paper paper-book)) (this-page (make-page paper-book - 'is-last (and is-last-part is-last-page) - 'is-part-last is-last-page + 'is-last-bookpart is-last-bookpart + 'is-bookpart-last-page is-bookpart-last-page 'page-number (if (null? best-paths) (ly:output-def-lookup paper 'first-page-number) (1+ (page-page-number (first best-paths)))))) (ragged-all (eq? #t (ly:output-def-lookup paper 'ragged-bottom))) (ragged-last (eq? #t (ly:output-def-lookup paper 'ragged-last-bottom))) - (ragged (or ragged-all (and ragged-last is-last-page))) + (ragged (or ragged-all (and ragged-last is-bookpart-last-page))) (space-to-fill (page-maximum-space-to-fill this-page current-lines paper)) (vertical-spacing (space-systems space-to-fill current-lines ragged paper #f)) (satisfied-constraints (car vertical-spacing)) (force (if satisfied-constraints - (if (and is-last-page ragged-last) + (if (and is-bookpart-last-page ragged-last) 0.0 satisfied-constraints) 10000)) @@ -413,7 +414,7 @@ CURRENT-BEST is the best result sofar, or #f." (list "\nuser pen " user-penalty "\nsatisfied-constraints" satisfied-constraints - "\nlast? " is-last-page "ragged?" ragged + "\nlast? " is-bookpart-last-page "ragged?" ragged "\nis-better " is-better " total-penalty " total-penalty "\n" "\nconfig " positions "\nforce " force @@ -429,11 +430,11 @@ CURRENT-BEST is the best result sofar, or #f." satisfied-constraints) (walk-paths (cdr done-lines) (cdr best-paths) (cons (car done-lines) current-lines) - is-last-part is-last-page new-best + is-last-bookpart is-bookpart-last-page new-best paper-book page-alist) new-best))) -(define (walk-lines done best-paths todo paper-book page-alist is-last-part) +(define (walk-lines done best-paths todo paper-book page-alist is-last-bookpart) "Return the best page breaking as a single page node for optimally breaking TODO ++ DONE.reversed. BEST-PATHS is a list of break nodes corresponding to @@ -441,15 +442,15 @@ DONE." (if (null? todo) (car best-paths) (let* ((this-line (car todo)) - (is-last-page (null? (cdr todo))) - (next (walk-paths done best-paths (list this-line) is-last-part - is-last-page #f paper-book page-alist))) + (is-bookpart-last-page (null? (cdr todo))) + (next (walk-paths done best-paths (list this-line) is-last-bookpart + is-bookpart-last-page #f paper-book page-alist))) (walk-lines (cons this-line done) (cons next best-paths) (cdr todo) paper-book page-alist - is-last-part)))) + is-last-bookpart)))) (define-public (optimal-page-breaks paper-book) "Return pages as a list starting with 1st page. Each page is a 'page Prob." @@ -458,12 +459,10 @@ DONE." (page-alist (layout->page-init paper)) (force-equalization-factor (ly:output-def-lookup paper 'verticalequalizationfactor 0.3)) - (part-is-last (ly:output-def-lookup paper 'part-is-last))) + (is-last-bookpart (ly:output-def-lookup paper 'is-last-bookpart))) (ly:message (_ "Calculating page breaks...")) - (let* ((best-break-node (walk-lines '() '() lines paper-book page-alist part-is-last)) + (let* ((best-break-node (walk-lines '() '() lines paper-book page-alist is-last-bookpart)) (break-nodes (get-path best-break-node '()))) - ;(page-set-property! (car (last-pair break-nodes)) 'is-last part-is-last) - ;(page-set-property! (car (last-pair break-nodes)) 'is-part-last #t) (if #f; (ly:get-option 'verbose) (begin (display (list diff --git a/scm/page.scm b/scm/page.scm index 068572694b..5e2764100a 100644 --- a/scm/page.scm +++ b/scm/page.scm @@ -137,7 +137,7 @@ (define (page-headfoot layout scopes number sym separation-symbol dir - is-book-last-page is-part-last-page) + is-last-bookpart is-bookpart-last-page) "Create a stencil including separating space." @@ -146,7 +146,7 @@ (stencil (ly:make-stencil "" '(0 . 0) '(0 . 0))) (head-stencil (if (procedure? header-proc) - (header-proc layout scopes number is-book-last-page is-part-last-page) + (header-proc layout scopes number is-last-bookpart is-bookpart-last-page) #f))) (if (and (number? sep) @@ -197,8 +197,8 @@ (layout (ly:paper-book-paper paper-book)) (scopes (ly:paper-book-scopes paper-book)) (number (page-page-number page)) - (is-book-last-page (page-property page 'is-last)) - (is-part-last-page (page-property page 'is-part-last))) + (is-last-bookpart (page-property page 'is-last-bookpart)) + (is-bookpart-last-page (page-property page 'is-bookpart-last-page))) (page-headfoot layout scopes number (if (= dir UP) @@ -207,7 +207,7 @@ (if (= dir UP) 'head-separation 'foot-separation) - dir is-book-last-page is-part-last-page))) + dir is-last-bookpart is-bookpart-last-page))) (define (page-header page) (page-header-or-footer page UP)) diff --git a/scm/titling.scm b/scm/titling.scm index 28e0e9c8c8..1ab08d73b7 100644 --- a/scm/titling.scm +++ b/scm/titling.scm @@ -13,12 +13,12 @@ ;;;;;;;;;;;;;;;;;; (define-public ((marked-up-headfoot what-odd what-even) - layout scopes page-number is-book-last-page is-part-last-page) + layout scopes page-number is-last-bookpart is-bookpart-last-page) "Read variables WHAT-ODD, WHAT-EVEN from LAYOUT, and interpret them as markup. The PROPS argument will include variables set in SCOPES and -page:last?, page:page-number-string and page:page-number -" +page:is-bookpart-last-page, page:is-last-bookpart, page:page-number-string +and page:page-number" (define (get sym) (ly:output-def-lookup layout sym)) @@ -42,8 +42,8 @@ page:last?, page:page-number-string and page:page-number (cons 'header:tagline (ly:modules-lookup scopes 'tagline (ly:output-def-lookup layout 'tagline))) - (cons 'page:last? is-book-last-page) - (cons 'page:part-last? is-part-last-page) + (cons 'page:is-last-bookpart is-last-bookpart) + (cons 'page:is-bookpart-last-page is-bookpart-last-page) (cons 'page:page-number-string (number->string page-number)) (cons 'page:page-number page-number))) @@ -51,7 +51,6 @@ page:last?, page:page-number-string and page:page-number (list pgnum-alist) prefixed-alists (layout-extract-page-properties layout)))) - (interpret-markup layout props potential-markup)) empty-stencil)) -- 2.39.2