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))
80 "(\\" (inexact->string i 8) ") show " ))
83 (string-append "% " s "\n"))
85 (define (dashed-line thick on off dx dy)
87 (ly:number->string dx)
89 (ly:number->string dy)
91 (ly:number->string thick)
93 (ly:number->string on)
95 (ly:number->string off)
96 " ] 0 draw_dashed_line"))
98 ;; what the heck is this interface ?
99 (define (dashed-slur thick dash l)
101 (apply string-append (map number-pair->string l))
102 (ly:number->string thick)
104 (ly:number->string dash)
107 (ly:number->string (* 10 thick))
108 " ] 0 draw_dashed_slur"))
110 (define (define-fonts internal-external-name-mag-pairs)
112 (define (font-load-command name-mag command)
114 (define (possibly-capitalize-font-name name)
115 (if (equal? (substring name 0 2) "cm")
122 ;; Ugh, the Bluesky type1 fonts for computer modern use capitalized
123 ;; postscript font names.
124 (possibly-capitalize-font-name (car name-mag))
126 "20 " (ly:number->string (cdr name-mag)) " mul "
127 "output-scale div scalefont setfont } bind def "
130 (define (ps-encoded-fontswitch name-mag-pair)
131 (let* ((key (car name-mag-pair))
132 (value (cdr name-mag-pair)))
135 (string-append "lilyfont"
138 (number->string (cdr value)))))))
140 (set! font-name-alist (map ps-encoded-fontswitch
141 internal-external-name-mag-pairs))
144 (map (lambda (x) (font-load-command (car x) (cdr x)))
145 (map cdr font-name-alist))))
147 (define (define-origin file line col) "")
149 (define (dot x y radius)
153 (list x y radius)) " draw_dot"))
155 (define (zigzag-line centre? zzw zzh thick dx dy)
157 (if centre? "true" "false")
159 (ly:number->string zzw)
161 (ly:number->string zzh)
163 (ly:number->string thick)
165 (ly:number->string dx)
167 (ly:number->string dy)
168 " draw_zigzag_line "))
170 (define (draw-line thick x1 y1 x2 y2)
174 (ly:number->string thick)
176 (ly:number->string x1)
178 (ly:number->string y1)
180 (ly:number->string x2)
182 (ly:number->string y2)
186 "\nend-lilypond-output\n")
188 (define (ez-ball ch letter-col ball-col)
191 (numbers->string (list letter-col ball-col))
192 " /Helvetica-Bold " ;; ugh
195 (define (filledbox breapth width depth height)
196 (string-append (numbers->string (list breapth width depth height))
199 (define (fontify name-mag-pair exp)
201 (define (select-font name-mag-pair)
202 (let* ((c (assoc name-mag-pair font-name-alist)))
206 (display (object-type (car name-mag-pair)))
207 (display (object-type (caaar font-name-alist)))
208 (ly:warn (string-append
209 "Programming error: No such font known "
210 (car name-mag-pair) " "
211 (ly:number->string (cdr name-mag-pair))))
213 ;; Upon error, issue no command
215 (string-append " " (cddr c) " "))))
217 (string-append (select-font name-mag-pair) exp))
219 (define (header creator generate)
222 "%%Creator: " creator generate "\n"))
226 ;; URG: now we can't use scm output without Lily
227 (ly:gulp-file "lilyponddefs.ps")
228 " {exch pop //systemdict /run get exec} "
229 (ly:gulp-file "music-drawing-routines.ps")
230 "{ exch pop //systemdict /run get exec } "
231 ;; ps-testing wreaks havoc when used with lilypond-book.
232 ;; -- is this still true with new modules system?
233 ;; (if (defined? 'ps-testing) "\n /testing true def" "")
234 ;; "\n /testing true def"
237 (define (lily-def key val)
238 (let ((prefix "lilypondpaper"))
240 (substring key 0 (min (string-length prefix) (string-length key)))
242 (string-append "/" key " {" val "} bind def\n")
243 (string-append "/" key " (" val ") def\n"))))
245 (define (no-origin) "")
247 (define (placebox x y s)
249 (ly:number->string x) " " (ly:number->string y) " {" s "} place-box\n"))
251 (define (repeat-slash wid slope thick)
253 (numbers->string (list wid slope thick))
254 " draw_repeat_slash"))
256 (define (roundfilledbox x y width height blotdiam)
260 (list x y width height blotdiam)) " draw_round_box"))
262 ;; TODO: use HEIGHT argument
263 (define (start-system width height)
265 "\n" (ly:number->string height)
268 "set-ps-scale-to-lily-scale"))
270 (define (stem breapth width depth height)
272 (numbers->string (list breapth width depth height))
275 (define (stop-last-system)
278 (define (stop-system)
282 (string-append "(" s ") show "))