Notes, complete.
[opus_libre.git] / doc / snippets / vertically-spread-markups.ly
blobe4f7f97bc35ab2ee101b141b248c96714ef39521
1 \version "2.14"
3 \header {
4 texidoc = "Title pages may require to vertically center, stretch or spread markups
5 throughout the full vertical extent of the paper. Here is a function that achieves
6 just that, much like the commonly-used `fill-line' markup command."
8 tagline = ##f
11 \paper {
12 #(set-paper-size "a6")
15 #(define-markup-command (fill-page layout props args)
16 (markup-list?)
17 ;; This code was shamelessly copied from the fill-line function.
18 #:properties ((text-direction UP)
19 (line-space 0.6)
20 (page-height #f))
22 (define (get-fill-space line-count page-height line-space text-heights)
23 (cond
24 ((null? text-heights) '())
26 ;; special case first padding
27 ((= (length text-heights) line-count)
28 (cons
29 (- (- (/ page-height (1- line-count)) (car text-heights))
30 (/ (car (cdr text-heights)) 2))
31 (get-fill-space line-count page-height line-space (cdr text-heights))))
32 ;; special case last padding
33 ((= (length text-heights) 2)
34 (list (- (/ page-height (1- line-count))
35 (+ (/ (car text-heights) 2) (car (cdr text-heights)))) 0))
36 (else
37 (let ((default-padding
38 (- (/ page-height (1- line-count))
39 (/ (+ (car text-heights) (car (cdr text-heights))) 2))))
40 (cons
41 (if (> line-space default-padding)
42 line-space
43 default-padding)
44 (get-fill-space line-count page-height line-space (cdr text-heights)))))))
46 (let* ((orig-stencils (interpret-markup-list layout props args))
47 (stencils
48 (map (lambda (stc)
49 (if (ly:stencil-empty? stc)
50 point-stencil
51 stc)) orig-stencils))
52 (text-heights
53 (map (lambda (stc)
54 (if (ly:stencil-empty? stc)
55 0.0
56 (interval-length (ly:stencil-extent stc Y))))
57 stencils))
58 (text-height (apply + text-heights))
59 (line-count (length stencils))
60 (page-height (- (ly:output-def-lookup layout 'paper-height)
61 (+ (ly:output-def-lookup layout 'top-margin)
62 (ly:output-def-lookup layout 'bottom-margin))))
63 (fill-space
64 (cond
65 ((= line-count 1)
66 (list
67 (/ (- page-height text-height) 2)
68 (/ (- page-height text-height) 2)))
69 ((= line-count 2)
70 (list
71 (- page-height text-height)))
72 (else
73 (get-fill-space line-count page-height line-space text-heights))))
75 (page-contents (if (= line-count 1)
76 (list
77 point-stencil
78 (car stencils)
79 point-stencil)
80 stencils)))
82 (if (null? (remove ly:stencil-empty? orig-stencils))
83 empty-stencil
84 (begin
85 (if (= text-direction UP)
86 (set! page-contents (reverse page-contents)))
87 (set! page-contents
88 (stack-stencils-padding-list
89 Y UP fill-space page-contents))
90 (if (> line-count 1)
91 (set! page-contents
92 (ly:stencil-translate-axis
93 page-contents
94 (- (car (ly:stencil-extent (car stencils) Y)))
95 Y)))
96 page-contents))))
98 \markup \fill-page {
99 \line { This markup }
100 \line { is spread }
101 \line { equally }
102 \line { on the page. }