-(define-public (default-page-music-height paper scopes number last?)
- "Printable area for music and titles; matches default-page-make-stencil."
- (let*
- ((h (- (ly:output-def-lookup paper 'vsize)
- (ly:output-def-lookup paper 'topmargin)
- (ly:output-def-lookup paper 'bottommargin)))
- (head (page-headfoot paper scopes number 'make-header 'headsep UP last?))
- (foot (page-headfoot paper scopes number 'make-footer 'footsep DOWN last?)))
- (- h (if (ly:stencil? head)
- (interval-length (ly:stencil-extent head Y))
- 0)
- (if (ly:stencil? foot)
- (interval-length (ly:stencil-extent foot Y))
- 0))
- ))
-
-
-(define-public (default-page-make-stencil lines paper scopes number last? )
- "Construct a stencil representing the page from LINES. "
- (let*
- ((topmargin (ly:output-def-lookup paper 'topmargin))
-
- ;; TODO: naming vsize/hsize not analogous to TeX.
-
-
- (vsize (ly:output-def-lookup paper 'vsize))
- (hsize (ly:output-def-lookup paper 'hsize))
-
- (lmargin (ly:output-def-lookup paper 'leftmargin))
- (leftmargin (if lmargin
- lmargin
- (/ (- hsize
- (ly:output-def-lookup paper 'linewidth)) 2)))
-
- (rightmargin (ly:output-def-lookup paper 'rightmargin))
- (bottom-edge (- vsize
- (ly:output-def-lookup paper 'bottommargin)))
-
- (head (page-headfoot paper scopes number 'make-header 'headsep UP last?))
- (foot (page-headfoot paper scopes number 'make-footer 'footsep DOWN last?))
- (line-stencils (map ly:paper-system-stencil lines))
- (height-proc (ly:output-def-lookup paper 'page-music-height))
- (music-height (height-proc paper scopes number last?))
- (ragged (ly:output-def-lookup paper 'raggedbottom))
- (ragged-last (ly:output-def-lookup paper 'raggedlastbottom))
- (ragged-bottom (or (eq? #t ragged)
- (and last? (eq? #t ragged-last))))
-
- (spc-left (- music-height
- (apply + (map (lambda (x)
- (interval-length (ly:stencil-extent x Y)))
- line-stencils))))
- (stretchable-lines (remove ly:paper-system-title? (cdr lines)))
- (stretch (if (or (null? stretchable-lines)
- (> spc-left (/ music-height 2))
- ragged-bottom)
- 0.0
- (/ spc-left (length stretchable-lines))))
-
- (page-stencil (ly:make-stencil '()
- (cons leftmargin hsize)
- (cons (- topmargin) 0)))
- (was-title #t))
+(define-public (default-page-music-height layout scopes number last?)
+ "Printable area for music and titles; matches default-page-make-stencil."
+ (let* ((h (- (ly:output-def-lookup layout 'vsize)
+ (ly:output-def-lookup layout 'topmargin)
+ (ly:output-def-lookup layout 'bottommargin)))
+ (head (page-headfoot layout scopes number 'make-header 'headsep UP last?))
+ (foot (page-headfoot layout scopes number 'make-footer 'footsep DOWN last?))
+ (available
+ (- h (if (ly:stencil? head)
+ (interval-length (ly:stencil-extent head Y))
+ 0)
+ (if (ly:stencil? foot)
+ (interval-length (ly:stencil-extent foot Y))
+ 0))))
+
+ ;; (display (list "\n available" available head foot))
+ available))
+
+(define-public (default-page-make-stencil
+ lines offsets layout scopes number last?)
+ "Construct a stencil representing the page from LINES.
+
+ Offsets is a list of increasing numbers. They must be negated to
+create offsets.
+ "
+
+ (let* ((topmargin (ly:output-def-lookup layout 'topmargin))
+
+ ;; TODO: naming vsize/hsize not analogous to TeX.
+
+ (vsize (ly:output-def-lookup layout 'vsize))
+ (hsize (ly:output-def-lookup layout 'hsize))
+
+ (system-xoffset (ly:output-def-lookup layout 'horizontalshift 0.0))
+ (system-separator-markup (ly:output-def-lookup layout 'systemSeparatorMarkup))
+ (system-separator-stencil (if (markup? system-separator-markup)
+ (interpret-markup layout
+ (layout-extract-page-properties layout)
+ system-separator-markup)
+ #f))
+ (lmargin (ly:output-def-lookup layout 'leftmargin))
+ (leftmargin (if lmargin
+ lmargin
+ (/ (- hsize
+ (ly:output-def-lookup layout 'linewidth)) 2)))
+
+ (rightmargin (ly:output-def-lookup layout 'rightmargin))
+ (bottom-edge (- vsize
+ (ly:output-def-lookup layout 'bottommargin)))
+
+ (head (page-headfoot layout scopes number 'make-header 'headsep UP last?))
+ (foot (page-headfoot layout scopes number 'make-footer 'footsep DOWN last?))
+
+ (head-height (if (ly:stencil? head)
+ (interval-length (ly:stencil-extent head Y))
+ 0.0))
+
+ (height-proc (ly:output-def-lookup layout 'page-music-height))
+
+ (page-stencil (ly:make-stencil '()
+ (cons leftmargin hsize)
+ (cons (- topmargin) 0)))
+ (last-system #f)
+ (last-y 0.0)
+ (add-to-page (lambda (stencil y)
+ (set! page-stencil
+ (ly:stencil-add page-stencil
+ (ly:stencil-translate stencil
+ (cons
+ system-xoffset
+ (- 0 head-height y topmargin))
+
+ )))))
+ (add-system
+ (lambda (stencil-position)
+ (let* ((system (car stencil-position))
+ (stencil (ly:paper-system-stencil system))
+ (y (cadr stencil-position))
+ (is-title (ly:paper-system-title?
+ (car stencil-position))))
+ (add-to-page stencil y)
+ (if (and (ly:stencil? system-separator-stencil)
+ last-system
+ (not (ly:paper-system-title? system))
+ (not (ly:paper-system-title? last-system)))
+ (add-to-page
+ system-separator-stencil
+ (average (- last-y
+ (car (ly:paper-system-staff-extents last-system)))
+ (- y
+ (cdr (ly:paper-system-staff-extents system))))))
+ (set! last-system system)
+ (set! last-y y)))))
+
+ (if #f
+ (display (list
+ "leftmargin " leftmargin "rightmargin " rightmargin
+ )))