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.1")
18 (equal? (minor-version) "4")
19 (equal? (minor-version) "3.4"))
20 (define-public (ps-output-expression expr port)
21 (display (eval-in-module expr this-module) port))
23 (define-public (ps-output-expression expr port)
24 (display (eval expr this-module) port)))
36 (define (tex-encoded-fontswitch name-mag)
37 (let* ((iname-mag (car name-mag))
38 (ename-mag (cdr name-mag)))
41 (string-append "magfont"
42 (string-encode-integer
43 (hashq (car ename-mag) 1000000))
45 (string-encode-integer
46 (inexact->exact (* 1000 (cdr ename-mag)))))))))
48 (define (fontify name-mag-pair exp)
49 (string-append (select-font name-mag-pair)
53 (define (define-fonts internal-external-name-mag-pairs)
54 (set! font-name-alist (map tex-encoded-fontswitch
55 internal-external-name-mag-pairs))
58 (font-load-command (car x) (cdr x)))
59 (map cdr font-name-alist))))
63 ;; alist containing fontname -> fontcommand assoc (both strings)
64 (define font-alist '())
66 (define current-font "")
68 (define (select-font name-mag-pair)
71 (c (assoc name-mag-pair font-name-alist))
77 (display (object-type (car name-mag-pair)))
78 (display (object-type (caaar font-name-alist)))
80 (ly-warn (string-append
81 "Programming error: No such font known "
82 (car name-mag-pair) " "
83 (ly-number->string (cdr name-mag-pair))
86 "") ; issue no command
87 (string-append " " (cddr c) " "))
90 (define (font-load-command name-mag command)
94 (capitalize-font-name (car name-mag))
96 "20 " (ly-number->string (cdr name-mag)) " mul "
97 "output-scale div scalefont setfont } bind def "
100 ;; Ugh, the Bluesky type1 fonts for computer modern use capitalized
101 ;; postscript font names.
102 (define (capitalize-font-name name)
103 (if (equal? (substring name 0 2) "cm")
107 (define (beam width slope thick)
109 (numbers->string (list slope width thick)) " draw_beam" ))
112 (string-append "% " s "\n"))
114 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
116 (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
119 (invoke-char " show" i))
123 ;; what the heck is this interface ?
124 (define (dashed-slur thick dash l)
126 (apply string-append (map control->string l))
127 (ly-number->string thick)
129 (ly-number->string dash)
131 (ly-number->string (* 10 thick)) ;UGH. 10 ?
132 " ] 0 draw_dashed_slur"))
134 (define (dashed-line thick on off dx dy)
136 (ly-number->string dx)
138 (ly-number->string dy)
140 (ly-number->string thick)
142 (ly-number->string on)
144 (ly-number->string off)
145 " ] 0 draw_dashed_line"))
147 (define (draw-line thick x1 y1 x2 y2)
152 (ly-number->string thick)
154 (ly-number->string x1)
156 (ly-number->string y1)
158 (ly-number->string x2)
160 (ly-number->string y2)
165 (define (repeat-slash wid slope thick)
166 (string-append (numbers->string (list wid slope thick))
167 " draw_repeat_slash"))
170 "\nend-lilypond-output\n")
172 (define (experimental-on) "")
174 (define (filledbox breapth width depth height)
175 (string-append (numbers->string (list breapth width depth height))
178 (define (roundfilledbox x width y height blotdiam)
181 (list x width y height blotdiam)) " draw_round_box"))
183 (define (dot x y radius)
186 (list x y radius)) " draw_dot"))
189 (define (font-def i s)
192 (substring s 0 (- (string-length s) 4))
193 " findfont 12 scalefont setfont} bind def \n"))
195 (define (font-switch i)
196 (string-append (font i) " "))
200 ;; URG: now we can't use scm output without Lily
201 (ly-gulp-file "lilyponddefs.ps")
202 " {exch pop //systemdict /run get exec} "
203 (ly-gulp-file "music-drawing-routines.ps")
204 "{ exch pop //systemdict /run get exec } "
205 ;; ps-testing is broken: global module
206 (if (defined? 'ps-testing) "\n /testing true def" "")
207 ;; "\n /testing true def"
210 (define (lily-def key val)
212 (if (string=? (substring key 0 (min (string-length "lilypondpaper") (string-length key))) "lilypondpaper")
213 (string-append "/" key " {" val "} bind def\n")
214 (string-append "/" key " (" val ") def\n")
218 (define (header creator generate)
221 "%%Creator: " creator generate "\n"))
223 (define (invoke-char s i)
225 "(\\" (inexact->string i 8) ") " s " " ))
228 (define (placebox x y s)
230 (ly-number->string x) " " (ly-number->string y) " {" s "} place-box\n"))
233 (define (bezier-sandwich l thick)
235 (apply string-append (map control->string l))
236 (ly-number->string thick)
237 " draw_bezier_sandwich "))
239 ;; two beziers with round endings
240 (define (bezier-bow l thick)
242 (apply string-append (map control->string l))
243 (ly-number->string thick)
244 " draw_bezier_sandwich "
245 (bezier-ending (list-ref l 3) (list-ref l 0) (list-ref l 5))
246 (bezier-ending (list-ref l 7) (list-ref l 0) (list-ref l 5))))
248 ;; two beziers with round endings
249 (define (bezier-ending z0 z1 z2)
259 (/ (sqrt (+ (* (- x1 x2) (- x1 x2)) (* (- y1 y2) (- y1 y2)))) 2)))
262 ; TODO: use HEIGHT argument
264 (define (start-system height)
267 (ly-number->string height)
269 set-ps-scale-to-lily-scale
273 (define (stem breapth width depth height)
274 (string-append (numbers->string (list breapth width depth height))
277 (define (stop-system)
280 (define (stop-last-system)
284 (string-append "(" s ") show "))
290 (define (ez-ball ch letter-col ball-col)
293 (numbers->string (list letter-col ball-col))
294 " /Helvetica-Bold " ;; ugh
297 (define (define-origin a b c ) "")
298 (define (no-origin) "")