- (define index 0)
- (define music-system-heights
- (map-in-order (lambda (sys)
- (* -1 (car (paper-system-extent sys Y))))
- (remove (lambda (sys)
- (ly:prob-property? sys 'is-title))
- (page-lines page))))
- (define (handle-system sys)
- (let* ((props `((line-break . #t)
- (spacing-parameters
- . ((system-Y-extent . ,(paper-system-extent sys Y))
- (system-refpoint-Y-extent . ,(paper-system-staff-extents sys))
- (system-index . ,index)
- (music-system-heights . ,music-system-heights)
- (page-system-count . ,(length (page-lines page)))
- (page-printable-height . ,(page-printable-height page))
- (page-space-left . ,(page-property page 'space-left)))))))
- (if (equal? (car (page-lines page)) sys)
- (set! props (cons '(page-break . #t)
- props)))
- (if (not (ly:prob-property? sys 'is-title))
- (record-tweaks (ly:spanner-bound (ly:prob-property sys 'system-grob) LEFT)
- props
- tweaks))
- (set! index (1+ index))))
- (for-each handle-system (page-lines page)))
+ "Computes vertical stretch for each music line of `page' (starting by
+ the smallest lines), then record the tweak parameters of each line to
+ the `tweaks' hash-table."
+ (let* ((lines (page-property page 'lines))
+ (line-count (length lines))
+ (compute-max-stretch (ly:output-def-lookup
+ (ly:paper-book-paper (page-property page
+ 'paper-book))
+ 'system-maximum-stretch-procedure))
+ (page-number (page-property page 'page-number)))
+ (let set-line-stretch! ((sorted-lines (sort lines
+ (lambda (l1 l2)
+ (< (line-height l1)
+ (line-height l2)))))
+ (rest-height ;; sum of stretchable line heights
+ (reduce + 0.0
+ (map line-height
+ (filter stretchable-line? lines))))
+ (space-left (page-maximum-space-left page)))
+ (if (not (null? sorted-lines))
+ (let* ((line (first sorted-lines))
+ (height (line-height line))
+ (stretch (min (compute-max-stretch line)
+ (if (and (stretchable-line? line)
+ (positive? rest-height))
+ (/ (* height space-left) rest-height)
+ 0.0))))
+ (set! (ly:prob-property line 'stretch) stretch)
+ (set-line-stretch! (cdr sorted-lines)
+ (if (stretchable-line? line)
+ (- rest-height height)
+ rest-height)
+ (- space-left stretch)))))
+ (let record-line-tweak ((lines lines)
+ (is-first-line #t)
+ (index 0))
+ (if (not (null? lines))
+ (let ((line (first lines)))
+ (if (not (ly:prob-property? line 'is-title))
+ (record-tweaks
+ (ly:spanner-bound (ly:prob-property line 'system-grob) LEFT)
+ `((line-break . #t)
+ (page-break . ,is-first-line)
+ (spacing-parameters
+ . ((page-number . ,page-number)
+ (system-index . ,index)
+ (system-stretch . ,(ly:prob-property line 'stretch))
+ (system-Y-extent . ,(paper-system-extent line Y))
+ (system-refpoint-Y-extent . ,(paper-system-staff-extents line))
+ (page-system-count . ,line-count)
+ (page-printable-height . ,(page-printable-height page))
+ (page-space-left . ,(page-property page 'space-left)))))
+ tweaks))
+ (record-line-tweak (cdr lines) #f (1+ index)))))))
+ ;; Compute tweaks for each page, then dump them to the page-layout file