1 ;;;; ps.scm -- implement Scheme output routines for PostScript
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 (debug-enable 'backtrace)
11 (define-module (scm output-ps))
12 (define this-module (current-module))
21 ;;; Lily output interface --- cleanup and docme
23 ;; TODO: fucks up if outputting strings with parentheses.
26 (define-public (ps-output-expression expr port)
27 (display (expression->string expr) port))
29 (define (expression->string expr)
30 (eval expr this-module))
34 ;; alist containing fontname -> fontcommand assoc (both strings)
35 (define font-name-alist '())
38 ;; Interface functions
39 (define (beam width slope thick blot)
41 (numbers->string (list slope width thick blot)) " draw_beam" ))
44 (define (bezier-sandwich l thick)
46 (apply string-append (map number-pair->string l))
47 (ly:number->string thick)
48 " draw_bezier_sandwich "))
50 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
53 (list arch_angle arch_width arch_height height arch_thick thick))
56 (define (symmetric-x-triangle thick w h)
58 (numbers->string (list h w thick))
59 " draw_symmetric_x_triangle"))
64 "(\\" (inexact->string i 8) ") show " ))
68 (string-append "% " s "\n"))
71 (define (dashed-line thick on off dx dy)
73 (ly:number->string dx)
75 (ly:number->string dy)
77 (ly:number->string thick)
79 (ly:number->string on)
81 (ly:number->string off)
82 " ] 0 draw_dashed_line"))
84 ;; what the heck is this interface ?
85 (define (dashed-slur thick dash l)
87 (apply string-append (map number-pair->string l))
88 (ly:number->string thick)
90 (ly:number->string dash)
93 (ly:number->string (* 10 thick))
94 " ] 0 draw_dashed_slur"))
96 (define lily-traced-cm-fonts
111 (define (define-fonts internal-external-name-mag-pairs)
113 (define (font-load-command name-mag command)
115 ;; frobnicate NAME to jibe with external definitions.
116 (define (possibly-capitalize-font-name name)
118 ((and (equal? (substring name 0 2) "cm")
119 (not (member name lily-traced-cm-fonts)))
120 (string-upcase name))
121 ((equal? (substring name 0 4) "feta")
122 (regexp-substitute/global #f "feta([a-z-]*)([0-9]+)" name 'pre "GNU-LilyPond-feta" 1 "-" 2 'post))
125 ;;(format (current-error-port) "DEFINE-FONTS: ~S\n" internal-external-name-mag-pairs)
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 (horizontal-line x1 x2 th)
216 (draw-line th x1 0 x2 0))
218 (define (fontify name-mag-pair exp)
220 (define (select-font name-mag-pair)
221 (let ((c (assoc name-mag-pair font-name-alist)))
224 (string-append " " (cddr c) " ")
227 (format "Programming error: No such font: ~S" name-mag-pair))
229 (display "FAILED\n" (current-error-port))
230 (if #f ;(pair? name-mag-pair))
231 (display (object-type (car name-mag-pair)) (current-error-port))
232 (write name-mag-pair (current-error-port)))
233 (if #f ; (pair? font-name-alist)
235 (object-type (caaar font-name-alist)) (current-error-port))
236 (write font-name-alist (current-error-port)))
238 ;; (format #f "\n%FAILED: (select-font ~S)\n" name-mag-pair))
241 (string-append (select-font name-mag-pair) exp))
243 (define (header creator generate)
246 "%%Creator: " creator generate "\n"))
250 ;; URG: now we can't use scm output without Lily
251 (ly:gulp-file "lilyponddefs.ps")
252 "{exch pop //systemdict /run get exec}\n\n"
253 (ly:gulp-file "music-drawing-routines.ps")
254 "{ exch pop //systemdict /run get exec }\n\n"
255 ;; ps-testing wreaks havoc when used with lilypond-book.
256 ;; -- is this still true with new modules system?
257 ;; (if (defined? 'ps-testing) "\n /testing true def" "")
258 ; "\n /testing true def"
261 (define (lily-def key val)
262 (let ((prefix "lilypondpaper"))
264 (substring key 0 (min (string-length prefix) (string-length key)))
266 (string-append "/" key " {" val "} bind def\n")
267 (string-append "/" key " (" val ") def\n"))))
269 (define (no-origin) "")
271 (define (placebox x y s)
273 (ly:number->string x) " " (ly:number->string y) " {" s "} place-box\n"))
275 (define (repeat-slash wid slope thick)
277 (numbers->string (list wid slope thick))
278 " draw_repeat_slash"))
280 (define (round-filled-box x y width height blotdiam)
284 (list x y width height blotdiam)) " draw_round_box"))
286 (define (start-system width height)
288 "\n" (ly:number->string height)
291 "set-ps-scale-to-lily-scale"))
293 (define (stem breapth width depth height)
295 (numbers->string (list breapth width depth height))
298 (define (stop-last-system)
301 (define (stop-system)
305 (string-append "(" s ") show "))
311 (define (top-of-file)
312 (header (string-append "GNU LilyPond (" (lilypond-version) "), ")
313 (strftime "%c" (localtime (current-time))))
317 (string-append "Engraved by LilyPond (" (lilypond-version) ")")))
319 (define (output-paper-def pd)
324 (let ((val (variable-ref var))
325 (key (symbol->string sym)))
329 (ps-string-def "lilypondpaper" sym val))
331 (ps-number-def "lilypondpaper" sym
334 (number->string (exact->inexact val)))))
337 (ly:output-def-scope pd))))
340 (define (ps-string-def a b c)
341 (string-append "/" a (symbol->string b) " (" c ") def\n"))
343 (define (ps-number-def a b c)
344 (string-append "/" a (symbol->string b) " " c " def\n"))
347 (define (output-scopes paper scopes fields basename)
349 ;; FIXME: customise/generate these
350 (let ((nmp '((("feta20" . 0.569055118110236) "feta20" . 1.0)
351 (("cmbx10" . 0.569055118110236) "cmbx10" . 1.0)
352 (("cmr10" . 0.569055118110236) "cmr10" . 1.0)
353 (("cmr10" . 0.638742773474948) "cmr10" . 1.0)
354 (("cmcsc10" . 0.451659346558038) "cmcs10" . 1.0)
355 (("cmcsc10" . 0.638742773474948) "cmcs10" . 1.0)
356 (("cmbx8" . 0.564574183197548) "cmbx8" . 1.0)))
358 (props '(((font-family . roman)
360 (font-shape . upright)
364 (define (output-scope scope)
369 (let ((val (variable-ref var))
370 (tex-key (symbol->string sym)))
372 (if (memq sym fields)
373 (header-to-file basename sym val))
376 ;; define strings, for /make-lilypond-title to pick up
377 ((string? val) (ps-string-def "lilypond" sym val))
379 ;; output markups ourselves
380 ((markup? val) (string-append
383 (interpret-markup paper props val)))
385 ((number? val) (ps-number-def
386 "lilypond" sym (if (integer? val)
389 (exact->inexact val)))))
397 (apply string-append (map output-scope scopes)))))