1 ;;;; paper.scm -- manipulate the paper and layout block.
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2004--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 (define-public (set-paper-dimension-variables mod)
8 (module-define! mod 'dimension-variables
9 '(pt mm cm in staffheight staff-space
10 betweensystemspace betweensystempadding
11 linewidth indent hsize vsize
12 staffspace linethickness ledgerlinethickness
13 blotdiameter interscoreline leftmargin rightmargin)))
15 (define-public (layout-set-staff-size sz)
16 "Function to be called inside a \\layout{} block to set the staff size."
17 (let* ((m (current-module))
22 ;; linear interpolation.
35 (module-define! m 'text-font-size (* 12 (/ sz (* 20 pt))))
37 (module-define! m 'outputscale ss)
38 (module-define! m 'fonts
40 (make-cmr-tree (/ sz (* 20 pt)))
41 (make-century-schoolbook-tree
43 (module-define! m 'staffheight sz)
44 (module-define! m 'staff-space ss)
45 (module-define! m 'staffspace ss)
47 ;; !! synchronize with feta-params.mf
48 (module-define! m 'linethickness lt)
49 (module-define! m 'ledgerlinethickness (+ (* 0.5 pt) (/ ss 10)))
50 (module-define! m 'blotdiameter (* 0.4 pt))
51 (module-define! m 'interscoreline (* 4 mm))))
53 (define-safe-public (set-global-staff-size sz)
54 "Set the default staff size, where SZ is thought to be in PT."
55 (let* ((old-mod (current-module))
56 (pap (eval '$defaultpaper old-mod))
57 (in-layout? (or (module-defined? old-mod 'is-paper)
58 (module-defined? old-mod 'is-layout)))
60 ; maybe not necessary.
61 ; but let's be paranoid. Maybe someone still refers to the
63 (new-paper (ly:output-def-clone pap))
65 (new-scope (ly:output-def-scope new-paper)))
68 (ly:warning (_ "Not in toplevel scope")))
69 (set-current-module new-scope)
70 (layout-set-staff-size (* sz (eval 'pt new-scope)))
71 (set-current-module old-mod)
72 (module-define! old-mod '$defaultpaper new-paper)))
74 (define-public paper-alist
75 '(("a6" . (cons (* 105 mm) (* 148.95 mm)))
76 ("a5" . (cons (* 148.95 mm) (* 210 mm)))
77 ("a4" . (cons (* 210 mm) (* 297.9 mm)))
78 ("a3" . (cons (* 297.9 mm) (* 420 mm)))
79 ("legal" . (cons (* 8.5 in) (* 14.0 in)))
80 ("letter" . (cons (* 8.5 in) (* 11.0 in)))
81 ("tabloid" . (cons (* 11.0 in) (* 17.0 in)))))
83 ;; todo: take dimension arguments.
85 (define (set-paper-dimensions m w h)
86 "M is a module (i.e. layout->scope_ )"
87 (let* ((mm (eval 'mm m)))
88 (module-define! m 'hsize w)
89 (module-define! m 'vsize h)
90 (module-define! m 'linewidth (- w (* 20 mm)))
91 (module-define! m 'indent (/ w 14))
93 ;; page layout - what to do with (printer specific!) margin settings?
94 (module-define! m 'topmargin (* 5 mm))
95 (module-define! m 'bottommargin (* 6 mm))
96 (module-define! m 'headsep (* 4 mm))
97 (module-define! m 'footsep (* 4 mm))
98 (module-define! m 'leftmargin #f)
99 (module-define! m 'firstpagenumber 1)
100 (module-define! m 'printfirstpagenumber #f)
101 (module-define! m 'rightmargin (* 10 mm))))
103 (define (internal-set-paper-size module name landscape?)
105 (cons (cdr x) (car x)))
107 (let* ((entry (assoc name paper-alist))
108 (is-paper? (module-defined? module 'is-paper))
109 (mm (eval 'mm module)))
113 (ly:warning (_ "This is not a \\layout {} object, ~S" module)))
116 (set! entry (eval (cdr entry) module))
118 (set! entry (swap entry)))
119 (set-paper-dimensions module (car entry) (cdr entry))
121 (module-define! module 'papersizename name)
124 (module-define! module 'landscape #t)))
126 (ly:warning (_ ("Unknown papersize: ~a" name)))))))
128 (define-safe-public (set-default-paper-size name . rest)
129 (internal-set-paper-size
130 (ly:output-def-scope (eval '$defaultpaper (current-module)))
132 (memq 'landscape rest)))
134 (define-public (set-paper-size name . rest)
135 (if (module-defined? (current-module) 'is-paper)
136 (internal-set-paper-size (current-module) name
137 (memq 'landscape rest))
139 ;;; TODO: should raise (generic) exception with throw, and catch
140 ;;; that in parse-scm.cc
141 (ly:warning (_ "Must use #(set-paper-size .. ) within \\paper { ... }"))))
143 (define-public (scale-layout pap scale)
144 (let* ((new-pap (ly:output-def-clone pap))
145 (dim-vars (ly:output-def-lookup pap 'dimension-variables))
146 (old-scope (ly:output-def-scope pap))
147 (scope (ly:output-def-scope new-pap)))
151 (let* ((var (module-variable old-scope v))
152 (val (if (variable? var) (variable-ref var) #f)))
155 (module-define! scope v
158 ;; spurious warnings, eg. for hsize, vsize.
159 ;; (ly:warning (_ "not a number, ~S = ~S " v val))