1 ;;;; ps.scm -- implement Scheme output routines for PostScript
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2002 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 (debug-enable 'backtrace)
12 (define-module (scm ps))
13 (define this-module (current-module))
21 ;;; Lily output interface --- cleanup and docme
26 (define-public (ps-output-expression expr port)
27 (display (eval expr this-module) port))
32 ;; alist containing fontname -> fontcommand assoc (both strings)
33 (define font-name-alist '())
36 ;; Interface functions
37 (define (beam width slope thick)
39 (numbers->string (list slope width thick)) " draw_beam" ))
41 ;; two beziers with round endings
42 (define (bezier-bow l thick)
44 (define (bezier-ending z0 z1 z2)
55 (/ (sqrt (+ (* (- x1 x2) (- x1 x2))
56 (* (- y1 y2) (- y1 y2)))) 2)))
60 (bezier-sandwich l thick)
61 (bezier-ending (list-ref l 3) (list-ref l 0) (list-ref l 5))
62 (bezier-ending (list-ref l 7) (list-ref l 0) (list-ref l 5))))
65 (define (bezier-sandwich l thick)
67 (apply string-append (map number-pair->string l))
68 (ly:number->string thick)
69 " draw_bezier_sandwich "))
71 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
74 (list arch_angle arch_width arch_height height arch_thick thick))
77 (define (symmetric-x-triangle thick w h)
79 (numbers->string (list h w thick))
80 " draw_symmetric_x_triangle"))
85 "(\\" (inexact->string i 8) ") show " ))
89 (string-append "% " s "\n"))
92 (define (dashed-line thick on off dx dy)
94 (ly:number->string dx)
96 (ly:number->string dy)
98 (ly:number->string thick)
100 (ly:number->string on)
102 (ly:number->string off)
103 " ] 0 draw_dashed_line"))
105 ;; what the heck is this interface ?
106 (define (dashed-slur thick dash l)
108 (apply string-append (map number-pair->string l))
109 (ly:number->string thick)
111 (ly:number->string dash)
114 (ly:number->string (* 10 thick))
115 " ] 0 draw_dashed_slur"))
117 (define (define-fonts internal-external-name-mag-pairs)
119 (define (font-load-command name-mag command)
121 (define (possibly-capitalize-font-name name)
122 (if (equal? (substring name 0 2) "cm")
129 ;; Ugh, the Bluesky type1 fonts for computer modern use capitalized
130 ;; postscript font names.
131 (possibly-capitalize-font-name (car name-mag))
133 "20 " (ly:number->string (cdr name-mag)) " mul "
134 "output-scale div scalefont setfont } bind def "
137 (define (ps-encoded-fontswitch name-mag-pair)
138 (let* ((key (car name-mag-pair))
139 (value (cdr name-mag-pair)))
142 (string-append "lilyfont"
145 (number->string (cdr value)))))))
147 (set! font-name-alist (map ps-encoded-fontswitch
148 internal-external-name-mag-pairs))
151 (map (lambda (x) (font-load-command (car x) (cdr x)))
152 (map cdr font-name-alist))))
154 (define (define-origin file line col) "")
156 (define (dot x y radius)
160 (list x y radius)) " draw_dot"))
162 (define (zigzag-line centre? zzw zzh thick dx dy)
164 (if centre? "true" "false")
166 (ly:number->string zzw)
168 (ly:number->string zzh)
170 (ly:number->string thick)
172 (ly:number->string dx)
174 (ly:number->string dy)
175 " draw_zigzag_line "))
177 (define (draw-line thick x1 y1 x2 y2)
181 (ly:number->string thick)
183 (ly:number->string x1)
185 (ly:number->string y1)
187 (ly:number->string x2)
189 (ly:number->string y2)
192 (define (polygon points blotdiameter)
195 (numbers->string points)
196 (ly:number->string (/ (length points) 2))
197 (ly:number->string blotdiameter)
201 "\nend-lilypond-output\n")
203 (define (ez-ball ch letter-col ball-col)
206 (numbers->string (list letter-col ball-col))
207 " /Helvetica-Bold " ;; ugh
210 (define (filledbox breapth width depth height)
211 (string-append (numbers->string (list breapth width depth height))
214 (define (fontify name-mag-pair exp)
216 (define (select-font name-mag-pair)
217 (let* ((c (assoc name-mag-pair font-name-alist)))
221 (display (object-type (car name-mag-pair)))
222 (display (object-type (caaar font-name-alist)))
223 (ly:warn (string-append
224 "Programming error: No such font known "
225 (car name-mag-pair) " "
226 (ly:number->string (cdr name-mag-pair))))
228 ;; Upon error, issue no command
230 (string-append " " (cddr c) " "))))
232 (string-append (select-font name-mag-pair) exp))
234 (define (header creator generate)
237 "%%Creator: " creator generate "\n"))
241 ;; URG: now we can't use scm output without Lily
242 (ly:gulp-file "lilyponddefs.ps")
243 " {exch pop //systemdict /run get exec} "
244 (ly:gulp-file "music-drawing-routines.ps")
245 "{ exch pop //systemdict /run get exec } "
246 ;; ps-testing wreaks havoc when used with lilypond-book.
247 ;; -- is this still true with new modules system?
248 ;; (if (defined? 'ps-testing) "\n /testing true def" "")
249 ;; "\n /testing true def"
252 (define (lily-def key val)
253 (let ((prefix "lilypondpaper"))
255 (substring key 0 (min (string-length prefix) (string-length key)))
257 (string-append "/" key " {" val "} bind def\n")
258 (string-append "/" key " (" val ") def\n"))))
260 (define (no-origin) "")
262 (define (placebox x y s)
264 (ly:number->string x) " " (ly:number->string y) " {" s "} place-box\n"))
266 (define (repeat-slash wid slope thick)
268 (numbers->string (list wid slope thick))
269 " draw_repeat_slash"))
271 (define (roundfilledbox x y width height blotdiam)
275 (list x y width height blotdiam)) " draw_round_box"))
277 (define (start-system width height)
279 "\n" (ly:number->string height)
282 "set-ps-scale-to-lily-scale"))
284 (define (stem breapth width depth height)
286 (numbers->string (list breapth width depth height))
289 (define (stop-last-system)
292 (define (stop-system)
296 (string-append "(" s ") show "))