1 ;;;; ps.scm -- implement Scheme output routines for PostScript
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2003 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 (debug-enable 'backtrace)
12 (define-module (scm output-ps))
13 (define this-module (current-module))
22 ;;; Lily output interface --- cleanup and docme
24 ;; TODO: fucks up if outputting strings with parentheses.
27 (define-public (ps-output-expression expr port)
28 (display (eval expr this-module) port))
33 ;; alist containing fontname -> fontcommand assoc (both strings)
34 (define font-name-alist '())
37 ;; Interface functions
38 (define (beam width slope thick)
40 (numbers->string (list slope width thick)) " draw_beam" ))
43 (define (bezier-sandwich l thick)
45 (apply string-append (map number-pair->string l))
46 (ly:number->string thick)
47 " draw_bezier_sandwich "))
49 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
52 (list arch_angle arch_width arch_height height arch_thick thick))
55 (define (symmetric-x-triangle thick w h)
57 (numbers->string (list h w thick))
58 " draw_symmetric_x_triangle"))
63 "(\\" (inexact->string i 8) ") show " ))
67 (string-append "% " s "\n"))
70 (define (dashed-line thick on off dx dy)
72 (ly:number->string dx)
74 (ly:number->string dy)
76 (ly:number->string thick)
78 (ly:number->string on)
80 (ly:number->string off)
81 " ] 0 draw_dashed_line"))
83 ;; what the heck is this interface ?
84 (define (dashed-slur thick dash l)
86 (apply string-append (map number-pair->string l))
87 (ly:number->string thick)
89 (ly:number->string dash)
92 (ly:number->string (* 10 thick))
93 " ] 0 draw_dashed_slur"))
95 (define lily-traced-cm-fonts
107 (define (define-fonts internal-external-name-mag-pairs)
109 (define (font-load-command name-mag command)
111 ;; frobnicate NAME to jibe with external definitions.
112 (define (possibly-capitalize-font-name name)
114 ((and (equal? (substring name 0 2) "cm")
115 (not (member name lily-traced-cm-fonts)))
116 (string-upcase name))
117 ((equal? (substring name 0 4) "feta")
118 (regexp-substitute/global #f "feta([a-z-]*)([0-9]+)" name 'pre "GNU-LilyPond-feta" 1 "-" 2 'post))
124 ;; Ugh, the Bluesky type1 fonts for computer modern use capitalized
125 ;; postscript font names.
126 (possibly-capitalize-font-name (car name-mag))
128 "20 " (ly:number->string (cdr name-mag)) " mul "
129 "output-scale div scalefont setfont } bind def "
132 (define (ps-encoded-fontswitch name-mag-pair)
133 (let* ((key (car name-mag-pair))
134 (value (cdr name-mag-pair)))
137 (string-append "lilyfont"
140 (number->string (cdr value)))))))
142 (set! font-name-alist (map ps-encoded-fontswitch
143 internal-external-name-mag-pairs))
146 (map (lambda (x) (font-load-command (car x) (cdr x)))
147 (map cdr font-name-alist))))
149 (define (define-origin file line col) "")
151 (define (dot x y radius)
155 (list x y radius)) " draw_dot"))
157 (define (zigzag-line centre? zzw zzh thick dx dy)
159 (if centre? "true" "false")
161 (ly:number->string zzw)
163 (ly:number->string zzh)
165 (ly:number->string thick)
167 (ly:number->string dx)
169 (ly:number->string dy)
170 " draw_zigzag_line "))
172 (define (draw-line thick x1 y1 x2 y2)
176 (ly:number->string thick)
178 (ly:number->string x1)
180 (ly:number->string y1)
182 (ly:number->string x2)
184 (ly:number->string y2)
187 (define (polygon points blotdiameter)
190 (numbers->string points)
191 (ly:number->string (/ (length points) 2))
192 (ly:number->string blotdiameter)
196 "\nend-lilypond-output\n")
198 (define (ez-ball ch letter-col ball-col)
201 (numbers->string (list letter-col ball-col))
202 " /Helvetica-Bold " ;; ugh
205 (define (filledbox breapth width depth height)
206 (string-append (numbers->string (list breapth width depth height))
209 (define (horizontal-line x1 x2 th)
210 (draw-line th x1 0 x2 0))
212 (define (fontify name-mag-pair exp)
214 (define (select-font name-mag-pair)
215 (let* ((c (assoc name-mag-pair font-name-alist)))
219 (display (object-type (car name-mag-pair)))
220 (display (object-type (caaar font-name-alist)))
221 (ly:warn (string-append
222 "Programming error: No such font known "
223 (car name-mag-pair) " "
224 (ly:number->string (cdr name-mag-pair))))
226 ;; Upon error, issue no command
228 (string-append " " (cddr c) " "))))
230 (string-append (select-font name-mag-pair) exp))
232 (define (header creator generate)
235 "%%Creator: " creator generate "\n"))
239 ;; URG: now we can't use scm output without Lily
240 (ly:gulp-file "lilyponddefs.ps")
241 " {exch pop //systemdict /run get exec} "
242 (ly:gulp-file "music-drawing-routines.ps")
243 "{ exch pop //systemdict /run get exec } "
244 ;; ps-testing wreaks havoc when used with lilypond-book.
245 ;; -- is this still true with new modules system?
246 ;; (if (defined? 'ps-testing) "\n /testing true def" "")
247 ;; "\n /testing true def"
250 (define (lily-def key val)
251 (let ((prefix "lilypondpaper"))
253 (substring key 0 (min (string-length prefix) (string-length key)))
255 (string-append "/" key " {" val "} bind def\n")
256 (string-append "/" key " (" val ") def\n"))))
258 (define (no-origin) "")
260 (define (placebox x y s)
262 (ly:number->string x) " " (ly:number->string y) " {" s "} place-box\n"))
264 (define (repeat-slash wid slope thick)
266 (numbers->string (list wid slope thick))
267 " draw_repeat_slash"))
269 (define (round-filled-box x y width height blotdiam)
273 (list x y width height blotdiam)) " draw_round_box"))
275 (define (start-system width height)
277 "\n" (ly:number->string height)
280 "set-ps-scale-to-lily-scale"))
282 (define (stem breapth width depth height)
284 (numbers->string (list breapth width depth height))
287 (define (stop-last-system)
290 (define (stop-system)
294 (string-append "(" s ") show "))