1 ;;; ps.scm -- implement Scheme output routines for PostScript
3 ;;; source file of the GNU LilyPond music typesetter
5 ;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 (define-module (scm ps)
13 (define this-module (current-module))
15 (debug-enable 'backtrace)
17 (if (or (equal? (minor-version) "4")
18 (equal? (minor-version) "3.4"))
19 (define-public (ps-output-expression expr port)
20 (display (eval-in-module expr this-module) port))
22 (define-public (ps-output-expression expr port)
23 (display (eval expr this-module) port)))
35 (define (tex-encoded-fontswitch name-mag)
36 (let* ((iname-mag (car name-mag))
37 (ename-mag (cdr name-mag)))
40 (string-append "magfont"
41 (string-encode-integer
42 (hashq (car ename-mag) 1000000))
44 (string-encode-integer
45 (inexact->exact (* 1000 (cdr ename-mag)))))))))
47 (define (fontify name-mag-pair exp)
48 (string-append (select-font name-mag-pair)
52 (define (define-fonts internal-external-name-mag-pairs)
53 (set! font-name-alist (map tex-encoded-fontswitch
54 internal-external-name-mag-pairs))
57 (font-load-command (car x) (cdr x)))
58 (map cdr font-name-alist))))
62 ;; alist containing fontname -> fontcommand assoc (both strings)
63 (define font-alist '())
65 (define current-font "")
67 (define (select-font name-mag-pair)
70 (c (assoc name-mag-pair font-name-alist))
76 (display (object-type (car name-mag-pair)))
77 (display (object-type (caaar font-name-alist)))
79 (ly-warn (string-append
80 "Programming error: No such font known "
81 (car name-mag-pair) " "
82 (ly-number->string (cdr name-mag-pair))
85 "") ; issue no command
86 (string-append " " (cddr c) " "))
89 (define (font-load-command name-mag command)
93 (capitalize-font-name (car name-mag))
95 "20 " (ly-number->string (cdr name-mag)) " mul "
96 "output-scale div scalefont setfont } bind def "
99 ;; Ugh, the Bluesky type1 fonts for computer modern use capitalized
100 ;; postscript font names.
101 (define (capitalize-font-name name)
102 (if (equal? (substring name 0 2) "cm")
106 (define (beam width slope thick)
108 (numbers->string (list slope width thick)) " draw_beam" ))
111 (string-append "% " s "\n"))
113 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
115 (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
118 (invoke-char " show" i))
121 (define (hairpin thick width starth endh )
123 (numbers->string (list width starth endh thick))
126 ;; what the heck is this interface ?
127 (define (dashed-slur thick dash l)
129 (apply string-append (map control->string l))
130 (ly-number->string thick)
132 (ly-number->string dash)
134 (ly-number->string (* 10 thick)) ;UGH. 10 ?
135 " ] 0 draw_dashed_slur"))
137 (define (dashed-line thick on off dx dy)
139 (ly-number->string dx)
141 (ly-number->string dy)
143 (ly-number->string thick)
145 (ly-number->string on)
147 (ly-number->string off)
148 " ] 0 draw_dashed_line"))
150 (define (repeat-slash wid slope thick)
151 (string-append (numbers->string (list wid slope thick))
152 " draw_repeat_slash"))
155 "\nend-lilypond-output\n")
157 (define (experimental-on) "")
159 (define (filledbox breapth width depth height)
160 (string-append (numbers->string (list breapth width depth height))
163 (define (dot x y radius)
166 (list x y radius)) " draw_dot"))
168 (define (roundfilledbox x width y height blotdiam)
170 (dot (- 0 x) (- 0 y) (/ blotdiam 2))
171 (dot width (- 0 y) (/ blotdiam 2))
172 (dot width height (/ blotdiam 2))
173 (dot (- 0 x) height (/ blotdiam 2))
174 (filledbox (+ x (/ blotdiam 2)) (+ width (/ blotdiam 2)) y height)
175 (filledbox x width (+ y (/ blotdiam 2)) (+ height (/ blotdiam 2)))))
178 (define (font-def i s)
181 (substring s 0 (- (string-length s) 4))
182 " findfont 12 scalefont setfont} bind def \n"))
184 (define (font-switch i)
185 (string-append (font i) " "))
189 ;; URG: now we can't use scm output without Lily
190 (ly-gulp-file "lilyponddefs.ps")
191 " {exch pop //systemdict /run get exec} "
192 (ly-gulp-file "music-drawing-routines.ps")
193 "{ exch pop //systemdict /run get exec } "
194 ;; ps-testing is broken: global module
195 (if (defined? 'ps-testing) "\n /testing true def" "")
196 ;; "\n /testing true def"
199 (define (lily-def key val)
201 (if (string=? (substring key 0 (min (string-length "lilypondpaper") (string-length key))) "lilypondpaper")
202 (string-append "/" key " {" val "} bind def\n")
203 (string-append "/" key " (" val ") def\n")
207 (define (header creator generate)
210 "%%Creator: " creator generate "\n"))
212 (define (invoke-char s i)
214 "(\\" (inexact->string i 8) ") " s " " ))
217 (define (placebox x y s)
219 (ly-number->string x) " " (ly-number->string y) " {" s "} place-box\n"))
221 (define (bezier-sandwich l thick)
223 (apply string-append (map control->string l))
224 (ly-number->string thick)
225 " draw_bezier_sandwich "
226 (bezier-ending (list-ref l 3) (list-ref l 0) (list-ref l 5))
227 (bezier-ending (list-ref l 7) (list-ref l 0) (list-ref l 5))))
229 (define (bezier-ending z0 z1 z2)
239 (/ (sqrt (+ (* (- x1 x2) (- x1 x2)) (* (- y1 y2) (- y1 y2)))) 2)))
242 ; TODO: use HEIGHT argument
244 (define (start-line height)
247 (ly-number->string height)
249 set-ps-scale-to-lily-scale
253 (define (stem breapth width depth height)
254 (string-append (numbers->string (list breapth width depth height))
260 (define (stop-last-line)
264 (string-append "(" s ") show "))
267 (define (volta h w thick vert_start vert_end)
269 (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
272 (define (tuplet ht gap dx dy thick dir)
274 (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
281 (define (ez-ball ch letter-col ball-col)
284 (numbers->string (list letter-col ball-col))
285 " /Helvetica-Bold " ;; ugh
288 (define (define-origin a b c ) "")
289 (define (no-origin) "")