]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/layout-page-layout.scm
Merge branch 'master' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / scm / layout-page-layout.scm
index c5721b325a98711b2d89c4ff7195705ea89e50fd..6c1f605b0d7d0bc80c8161c6636e24711602e06f 100644 (file)
@@ -15,6 +15,7 @@
   #:use-module (lily)
   #:export (post-process-pages optimal-page-breaks make-page-from-systems
            page-breaking-wrapper
+           stretchable-line? ; delete me
            ;; utilities for writing custom page breaking functions
             line-height line-next-space line-next-padding
            line-minimum-distance line-ideal-distance
             line-minimum-position-on-page
            page-maximum-space-to-fill page-maximum-space-left space-systems))
 
+; this is for 2-pass spacing. Delete me.
+(define (stretchable-line? line)
+  "Say whether a system can be stretched."
+  (not (or (ly:prob-property? line 'is-title)
+          (let ((system-extent (paper-system-staff-extents line)))
+            (= (interval-start system-extent)
+               (interval-end   system-extent))))))
+
 (define (stretch-and-draw-page paper-book systems page-number ragged last)
+  (define (max-stretch sys)
+    (if (ly:grob? sys)
+       (ly:grob-property sys 'max-stretch)
+       0.0))
+
   (define (stretchable? sys)
     (and (ly:grob? sys)
-        (ly:grob-property sys 'stretchable)))
+        (> (max-stretch sys) 0.0)))
 
   (define (height-estimate sys)
     (interval-length
         (ly:grob-property sys 'pure-Y-extent)
         (paper-system-extent sys Y))))
 
-  (define (max-stretch sys)
-    (if (stretchable? sys)
-       (ly:grob-property sys 'max-stretch)
-       0.0))
-
   (define (print-system sys)
     (if (ly:grob? sys)
        (ly:system-print sys)
                                 rest-height)
                             (- space-left stretch)))))
 
+  (define (total-padding systems)
+    (let ((layout (ly:paper-book-paper paper-book)))
+      (if (or (null? systems)
+             (null? (cdr systems)))
+         0.0
+         (+ (line-next-padding (car systems) (cadr systems) layout)
+            (total-padding (cdr systems))))))
+
   (let* ((page (make-page paper-book
                          'page-number page-number
                          'is-last last))
         ; yet, etc. If we overstretch because of underestimation, the result
         ; is very bad. So we stick in some extra space, just to be sure.
         (buffer (/ height 10.0))
-        (total-system-height (apply + (map height-estimate systems)))
+        (total-system-height (+ (apply + (map height-estimate systems))
+                                (total-padding systems)))
         (height-left (- height total-system-height buffer)))
 
-    (if (not ragged)
+    (if (and
+        (not ragged)
+        (> height-left 0))
        (set-line-stretch! (sort systems
                                 (lambda (s1 s2)
                                   (< (height-estimate s1)
                                      (height-estimate s2))))
                           (apply + (map height-estimate
                                         (filter stretchable? systems)))
-                          (- (page-printable-height page)
-                             total-system-height)))
+                          height-left))
 
     (let* ((lines (map print-system systems))
           (posns (if (null? lines)
 (define (line-next-padding line next-line layout)
   "Return padding to use between `line' and `next-line'.
   `next-line' can be #f, meaning that `line' is the last line."
-  (ly:prob-property
-   line 'next-padding
-   (ly:output-def-lookup layout 'between-system-padding)))
+  (let ((default (ly:output-def-lookup layout 'between-system-padding)))
+    (if (ly:grob? line)
+       (let* ((details (ly:grob-property line 'line-break-system-details))
+              (padding (assq 'next-padding details)))
+         (if padding
+             (cdr padding)
+             default))
+       (ly:prob-property line 'next-padding default))))
 
 
 (define (line-minimum-distance line next-line layout ignore-padding)