1 ;;;; paper.scm -- manipulate the paper and layout block.
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2004--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 (define-public (set-paper-dimension-variables mod)
8 (module-define! mod 'dimension-variables
11 between-system-padding
37 (define (calc-line-thickness staff-space pt)
38 ;; linear interpolation.
40 ;; !! synchronize with feta-params.mf
49 (* f1 (- staff-space x0))
50 (* f0 (- x1 staff-space)))
53 (define-public (layout-set-absolute-staff-size-in-module module staff-height)
55 ((pt (eval 'pt module))
56 (ss (/ staff-height 4))
57 (factor (/ staff-height (* 20 pt)))
58 (setm! (lambda (sym val)
59 (module-define! module sym val))))
61 (setm! 'text-font-size (* 12 factor))
63 (setm! 'output-scale ss)
64 (setm! 'fonts (make-century-schoolbook-tree factor))
65 (setm! 'staff-height staff-height)
66 (setm! 'staff-space ss)
68 (setm! 'line-thickness (calc-line-thickness ss pt))
71 (setm! 'ledger-line-thickness (+ (* 0.5 pt) (/ ss 10)))
74 (setm! 'blot-diameter (* 0.4 pt))
77 (define-public (layout-set-absolute-staff-size sz)
78 "Function to be called inside a \\layout{} block to set the staff
79 size. SZ is in points"
80 (layout-set-absolute-staff-size-in-module (current-module) sz))
82 (define-public (layout-set-staff-size sz)
83 "Function to be called inside a \\layout{} block to set the staff
84 size. SZ is in points"
86 (layout-set-absolute-staff-size (* (eval 'pt (current-module)) sz)))
88 (define-safe-public (set-global-staff-size sz)
89 "Set the default staff size, where SZ is thought to be in PT."
90 (let* ((current-mod (current-module))
91 (parser (eval 'parser current-mod))
92 (pap (ly:parser-lookup parser '$defaultpaper))
93 (in-layout? (or (module-defined? current-mod 'is-paper)
94 (module-defined? current-mod 'is-layout)))
96 ; maybe not necessary.
97 ; but let's be paranoid. Maybe someone still refers to the
99 (new-paper (ly:output-def-clone pap))
101 (new-scope (ly:output-def-scope new-paper)))
104 (ly:warning (_ "set-global-staff-size: not in toplevel scope")))
106 (layout-set-absolute-staff-size-in-module new-scope
107 (* sz (eval 'pt new-scope)))
108 (module-define! current-mod '$defaultpaper new-paper)))
110 (define-public paper-alist
112 ;; don't use decimals.
113 ;; ISO 216 has a tolerance of +- 2mm
115 '(("a10" . (cons (* 26 mm) (* 37 mm)))
116 ("a9" . (cons (* 37 mm) (* 52 mm)))
117 ("a8" . (cons (* 52 mm) (* 74 mm)))
118 ("a7" . (cons (* 74 mm) (* 105 mm)))
119 ("a6" . (cons (* 105 mm) (* 148 mm)))
120 ("a5" . (cons (* 148 mm) (* 210 mm)))
121 ("a4" . (cons (* 210 mm) (* 297 mm)))
122 ("a3" . (cons (* 297 mm) (* 420 mm)))
123 ("a2" . (cons (* 420 mm) (* 594 mm)))
124 ("a1" . (cons (* 594 mm) (* 841 mm)))
125 ("a0" . (cons (* 841 mm) (* 1189 mm)))
126 ("b10" . (cons (* 31 mm) (* 44 mm)))
127 ("b9" . (cons (* 44 mm) (* 62 mm)))
128 ("b8" . (cons (* 62 mm) (* 88 mm)))
129 ("b7" . (cons (* 88 mm) (* 125 mm)))
130 ("b6" . (cons (* 125 mm) (* 176 mm)))
131 ("b5" . (cons (* 176 mm) (* 250 mm)))
132 ("b4" . (cons (* 250 mm) (* 353 mm)))
133 ("b3" . (cons (* 353 mm) (* 500 mm)))
134 ("b2" . (cons (* 500 mm) (* 707 mm)))
135 ("b1" . (cons (* 707 mm) (* 1000 mm)))
136 ("b0" . (cons (* 1000 mm) (* 1414 mm)))
137 ;; Below are two extended sizes defined in DIn 476
138 ("4a0" . (cons (* 1682 mm) (* 2378 mm)))
139 ("2a0" . (cons (* 1189 mm) (* 1682 mm)))
140 ;; Below are ISO 269 standard C series
141 ("c10" . (cons (* 28 mm) (* 40 mm)))
142 ("c9" . (cons (* 40 mm) (* 57 mm)))
143 ("c8" . (cons (* 57 mm) (* 81 mm)))
144 ("c7" . (cons (* 81 mm) (* 114 mm)))
145 ("c6" . (cons (* 114 mm) (* 162 mm)))
146 ("c5" . (cons (* 162 mm) (* 229 mm)))
147 ("c4" . (cons (* 229 mm) (* 324 mm)))
148 ("c3" . (cons (* 324 mm) (* 458 mm)))
149 ("c2" . (cons (* 458 mm) (* 648 mm)))
150 ("c1" . (cons (* 648 mm) (* 917 mm)))
151 ("c0" . (cons (* 917 mm) (* 1297 mm)))
152 ;; Below are North American paper sizes
153 ("legal" . (cons (* 8.5 in) (* 14.0 in)))
154 ("letter" . (cons (* 8.5 in) (* 11.0 in)))
155 ;; Ledger (17x11) is a 90 degree rotation of Tabloid
156 ("11x17" . (cons (* 11.0 in) (* 17.0 in)))
157 ;; government-letter by IEEE Printer Working Group, for children's writing
158 ("government-letter" . (cons (* 8 in) (* 10.5 in)))
159 ("government-legal" . (cons (* 8.5 in) (* 13.0 in)))
160 ("philippine-legal" . (cons (* 8.5 in) (* 13.0 in)))
162 ("ansi a" . (cons (* 8.5 in) (* 11.0 in)))
163 ("ansi b" . (cons (* 17.0 in) (* 11.0 in)))
164 ("ansi c" . (cons (* 17.0 in) (* 22.0 in)))
165 ("ansi d" . (cons (* 22.0 in) (* 34.0 in)))
166 ("ansi e" . (cons (* 34.0 in) (* 44.0 in)))
167 ("engineering f" . (cons (* 28.0 in) (* 40.0 in)))
168 ;; G and H are very rare, and the lengths are variable up to 90 inches
169 ;; North American Architectural sizes
170 ("arch a" . (cons (* 9.0 in) (* 12.0 in)))
171 ("arch b" . (cons (* 12.0 in) (* 18.0 in)))
172 ("arch c" . (cons (* 18.0 in) (* 24.0 in)))
173 ("arch d" . (cons (* 24.0 in) (* 36.0 in)))
174 ("arch e" . (cons (* 36.0 in) (* 48.0 in)))
175 ("arch e1" . (cons (* 30.0 in) (* 42.0 in)))
177 ;; Some are antique sizes which are still using in UK
178 ("statement" . (cons (* 5.5 in) (* 8.5 in)))
179 ("half letter" . (cons (* 5.5 in) (* 8.5 in)))
180 ("quarto" . (cons (* 8.0 in) (* 10.0 in)))
181 ("octavo" . (cons (* 6.75 in) (* 10.5 in)))
182 ("executive" . (cons (* 7.25 in) (* 10.5 in)))
183 ("monarch" . (cons (* 7.25 in) (* 10.5 in)))
184 ("foolscap" . (cons (* 8.27 in) (* 13.0 in)))
185 ("folio" . (cons (* 8.27 in) (* 13.0 in)))
186 ("super-b" . (cons (* 13.0 in) (* 19.0 in)))
187 ("post" . (cons (* 15.5 in) (* 19.5 in)))
188 ("crown" . (cons (* 15.0 in) (* 20.0 in)))
189 ("large post" . (cons (* 16.5 in) (* 21.0 in)))
190 ("demy" . (cons (* 17.5 in) (* 22.5 in)))
191 ("medium" . (cons (* 18.0 in) (* 23.0 in)))
192 ("broadsheet" . (cons (* 18.0 in) (* 24.0 in)))
193 ("royal" . (cons (* 20.0 in) (* 25.0 in)))
194 ("elephant" . (cons (* 23.0 in) (* 28.0 in)))
195 ("double demy" . (cons (* 22.5 in) (* 35.0 in)))
196 ("quad demy" . (cons (* 35.0 in) (* 45.0 in)))
197 ("atlas" . (cons (* 26.0 in) (* 34.0 in)))
198 ("imperial" . (cons (* 22.0 in) (* 30.0 in)))
199 ("antiquarian" . (cons (* 31.0 in) (* 53.0 in)))
201 ("pa0" . (cons (* 840 mm) (* 1120 mm)))
202 ("pa1" . (cons (* 560 mm) (* 840 mm)))
203 ("pa2" . (cons (* 420 mm) (* 560 mm)))
204 ("pa3" . (cons (* 280 mm) (* 420 mm)))
205 ("pa4" . (cons (* 210 mm) (* 280 mm)))
206 ("pa5" . (cons (* 140 mm) (* 210 mm)))
207 ("pa6" . (cons (* 105 mm) (* 140 mm)))
208 ("pa7" . (cons (* 70 mm) (* 105 mm)))
209 ("pa8" . (cons (* 52 mm) (* 70 mm)))
210 ("pa9" . (cons (* 35 mm) (* 52 mm)))
211 ("pa10" . (cons (* 26 mm) (* 35 mm)))
212 ;; F4 used in southeast Asia and Australia
213 ("f4" . (cons (* 210 mm) (* 330 mm)))
216 ;; todo: take dimension arguments.
218 (define (set-paper-dimensions m w h)
219 "M is a module (i.e. layout->scope_ )"
220 (let* ((mm (eval 'mm m)))
221 (module-define! m 'paper-width w)
222 (module-define! m 'paper-height h)
223 (module-define! m 'line-width (- w
224 (ly:modules-lookup (list m) 'left-margin (* 10 mm))
225 (ly:modules-lookup (list m) 'right-margin (* 10 mm))))
227 (module-define! m 'indent (/ w 14))
228 (module-define! m 'short-indent 0)
230 ;; page layout - what to do with (printer specific!) margin settings?
234 (define (internal-set-paper-size module name landscape?)
236 (cons (cdr x) (car x)))
238 (let* ((entry (assoc name paper-alist))
239 (is-paper? (module-defined? module 'is-paper))
240 (mm (eval 'mm module)))
244 (ly:warning (_ "This is not a \\layout {} object, ~S") module))
247 (set! entry (eval (cdr entry) module))
249 (set! entry (swap entry)))
250 (set-paper-dimensions module (car entry) (cdr entry))
252 (module-define! module 'papersizename name)
253 (module-define! module 'landscape
254 (if landscape? #t #f)))
256 (ly:warning (_ "Unknown paper size: ~a") name)))))
258 (define-safe-public (set-default-paper-size name . rest)
259 (internal-set-paper-size
260 (ly:output-def-scope (eval '$defaultpaper (current-module)))
262 (memq 'landscape rest)))
264 (define-public (set-paper-size name . rest)
265 (if (module-defined? (current-module) 'is-paper)
266 (internal-set-paper-size (current-module) name
267 (memq 'landscape rest))
269 ;;; TODO: should raise (generic) exception with throw, and catch
270 ;;; that in parse-scm.cc
271 (ly:warning (_ "Must use #(set-paper-size .. ) within \\paper { ... }"))))
273 (define-public (scale-layout pap scale)
274 (let* ((new-pap (ly:output-def-clone pap))
275 (dim-vars (ly:output-def-lookup pap 'dimension-variables))
276 (old-scope (ly:output-def-scope pap))
277 (scope (ly:output-def-scope new-pap)))
281 (let* ((var (module-variable old-scope v))
282 (val (if (variable? var) (variable-ref var) #f)))
285 (module-define! scope v
288 ;; spurious warnings, eg. for paper-width, paper-height.
289 ;; (ly:warning (_ "not a number, ~S = ~S " v val))