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)) (* (- y1 y2) (- y1 y2)))) 2)))
59 (apply string-append (map number-pair->string l))
60 (ly:number->string thick)
61 " draw_bezier_sandwich "
62 (bezier-ending (list-ref l 3) (list-ref l 0) (list-ref l 5))
63 (bezier-ending (list-ref l 7) (list-ref l 0) (list-ref l 5))))
66 (define (bezier-sandwich l thick)
68 (apply string-append (map number-pair->string l))
69 (ly:number->string thick)
70 " draw_bezier_sandwich "))
72 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
75 (list arch_angle arch_width arch_height height arch_thick thick))
78 (define (symmetric-x-triangle thick w h)
80 (numbers->string (list h w thick))
81 " draw_symmetric_x_triangle"))
86 "(\\" (inexact->string i 8) ") show " ))
90 (string-append "% " s "\n"))
93 (define (dashed-line thick on off dx dy)
95 (ly:number->string dx)
97 (ly:number->string dy)
99 (ly:number->string thick)
101 (ly:number->string on)
103 (ly:number->string off)
104 " ] 0 draw_dashed_line"))
106 ;; what the heck is this interface ?
107 (define (dashed-slur thick dash l)
109 (apply string-append (map number-pair->string l))
110 (ly:number->string thick)
112 (ly:number->string dash)
115 (ly:number->string (* 10 thick))
116 " ] 0 draw_dashed_slur"))
118 (define (define-fonts internal-external-name-mag-pairs)
120 (define (font-load-command name-mag command)
122 (define (possibly-capitalize-font-name name)
123 (if (equal? (substring name 0 2) "cm")
130 ;; Ugh, the Bluesky type1 fonts for computer modern use capitalized
131 ;; postscript font names.
132 (possibly-capitalize-font-name (car name-mag))
134 "20 " (ly:number->string (cdr name-mag)) " mul "
135 "output-scale div scalefont setfont } bind def "
138 (define (ps-encoded-fontswitch name-mag-pair)
139 (let* ((key (car name-mag-pair))
140 (value (cdr name-mag-pair)))
143 (string-append "lilyfont"
146 (number->string (cdr value)))))))
148 (set! font-name-alist (map ps-encoded-fontswitch
149 internal-external-name-mag-pairs))
152 (map (lambda (x) (font-load-command (car x) (cdr x)))
153 (map cdr font-name-alist))))
155 (define (define-origin file line col) "")
157 (define (dot x y radius)
161 (list x y radius)) " draw_dot"))
163 (define (zigzag-line centre? zzw zzh thick dx dy)
165 (if centre? "true" "false")
167 (ly:number->string zzw)
169 (ly:number->string zzh)
171 (ly:number->string thick)
173 (ly:number->string dx)
175 (ly:number->string dy)
176 " draw_zigzag_line "))
178 (define (draw-line thick x1 y1 x2 y2)
182 (ly:number->string thick)
184 (ly:number->string x1)
186 (ly:number->string y1)
188 (ly:number->string x2)
190 (ly:number->string y2)
193 (define (polygon points blotdiameter)
196 (numbers->string points)
197 (ly:number->string (/ (length points) 2))
198 (ly:number->string blotdiameter)
202 "\nend-lilypond-output\n")
204 (define (ez-ball ch letter-col ball-col)
207 (numbers->string (list letter-col ball-col))
208 " /Helvetica-Bold " ;; ugh
211 (define (filledbox breapth width depth height)
212 (string-append (numbers->string (list breapth width depth height))
215 (define (fontify name-mag-pair exp)
217 (define (select-font name-mag-pair)
218 (let* ((c (assoc name-mag-pair font-name-alist)))
222 (display (object-type (car name-mag-pair)))
223 (display (object-type (caaar font-name-alist)))
224 (ly:warn (string-append
225 "Programming error: No such font known "
226 (car name-mag-pair) " "
227 (ly:number->string (cdr name-mag-pair))))
229 ;; Upon error, issue no command
231 (string-append " " (cddr c) " "))))
233 (string-append (select-font name-mag-pair) exp))
235 (define (header creator generate)
238 "%%Creator: " creator generate "\n"))
242 ;; URG: now we can't use scm output without Lily
243 (ly:gulp-file "lilyponddefs.ps")
244 " {exch pop //systemdict /run get exec} "
245 (ly:gulp-file "music-drawing-routines.ps")
246 "{ exch pop //systemdict /run get exec } "
247 ;; ps-testing wreaks havoc when used with lilypond-book.
248 ;; -- is this still true with new modules system?
249 ;; (if (defined? 'ps-testing) "\n /testing true def" "")
250 ;; "\n /testing true def"
253 (define (lily-def key val)
254 (let ((prefix "lilypondpaper"))
256 (substring key 0 (min (string-length prefix) (string-length key)))
258 (string-append "/" key " {" val "} bind def\n")
259 (string-append "/" key " (" val ") def\n"))))
261 (define (no-origin) "")
263 (define (placebox x y s)
265 (ly:number->string x) " " (ly:number->string y) " {" s "} place-box\n"))
267 (define (repeat-slash wid slope thick)
269 (numbers->string (list wid slope thick))
270 " draw_repeat_slash"))
272 (define (roundfilledbox x y width height blotdiam)
276 (list x y width height blotdiam)) " draw_round_box"))
278 ;; TODO: use HEIGHT argument
279 (define (start-system width height)
281 "\n" (ly:number->string height)
284 "set-ps-scale-to-lily-scale"))
286 (define (stem breapth width depth height)
288 (numbers->string (list breapth width depth height))
291 (define (stop-last-system)
294 (define (stop-system)
298 (string-append "(" s ") show "))