1 ;;;; output-ps.scm -- implement Scheme output interface 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>
8 ;;;; Note: currently misused as testbed for titles with markup, see
9 ;;;; input/test/title-markup.ly
12 ;;;; * %% Papersize in (header ...)
13 ;;;; * text setting, kerning.
14 ;;;; * document output-interface
16 (debug-enable 'backtrace)
18 (define-module (scm output-ps)
21 ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
60 ;; (append (ly:all-stencil-expressions) (ly:all-output-backend-commands)))
63 ;;(write (ly:all-output-backend-commands))
64 ;;(write (ly:all-stencil-expressions))
67 ;;; helper functions, not part of output interface
68 (define (escape-parentheses s)
69 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
71 (define (offset-add a b)
72 (cons (+ (car a) (car b))
75 (define (ps-encoding text)
76 (escape-parentheses text))
79 (define-public (ps-string-def prefix key val)
80 (string-append "/" prefix (symbol->string key) " ("
81 (escape-parentheses val)
85 (define (ps-number-def prefix key val)
86 (let ((s (if (integer? val)
87 (ly:number->string val)
88 (ly:number->string (exact->inexact val)))))
89 (string-append "/" prefix (symbol->string key) " " s " def\n")))
93 ;;; Lily output interface, PostScript implementation --- cleanup and docme
96 ;;; Output-interface functions
97 (define (beam width slope thick blot)
99 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
102 (define (bezier-sandwich l thick)
104 (string-join (map ly:number-pair->string l) " ")
106 (ly:number->string thick)
107 " draw_bezier_sandwich"))
109 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
112 (list arch_angle arch_width arch_height height arch_thick thick))
115 (define (char font i)
117 (ps-font-command font) " setfont "
118 "(\\" (ly:inexact->string i 8) ") show" ))
120 (define (dashed-line thick on off dx dy)
122 (ly:number->string dx) " "
123 (ly:number->string dy) " "
124 (ly:number->string thick)
126 (ly:number->string on) " "
127 (ly:number->string off)
128 " ] 0 draw_dashed_line"))
130 ;; what the heck is this interface ?
131 (define (dashed-slur thick dash l)
133 (string-join (map ly:number-pair->string l) " ")
135 (ly:number->string thick)
137 (ly:number->string dash)
140 (ly:number->string (* 10 thick))
141 " ] 0 draw_dashed_slur"))
143 ; todo: merge with tex-font-command?
145 (define (embedded-ps string)
148 (define (dot x y radius)
152 (list x y radius)) " draw_dot"))
154 (define (white-dot x y radius)
158 (list x y radius)) " draw_white_dot"))
160 (define (draw-line thick x1 y1 x2 y2)
162 "1 setlinecap 1 setlinejoin "
163 (ly:number->string thick) " setlinewidth "
164 (ly:number->string x1) " "
165 (ly:number->string y1) " moveto "
166 (ly:number->string x2) " "
167 (ly:number->string y2) " lineto stroke"))
169 (define (ez-ball ch letter-col ball-col)
172 (ly:numbers->string (list letter-col ball-col))
173 " /Helvetica-Bold " ;; ugh
176 (define (filledbox breapth width depth height) ; FIXME : use draw_round_box
177 (string-append (ly:numbers->string (list breapth width depth height))
180 ;; WTF is this in every backend?
181 (define (horizontal-line x1 x2 th)
182 (draw-line th x1 0 x2 0))
184 (define (lily-def key val)
185 (let ((prefix "lilypondpaper"))
187 (substring key 0 (min (string-length prefix) (string-length key)))
189 (string-append "/" key " {" val "} bind def\n")
190 (string-append "/" key " (" val ") def\n"))))
193 (define (placebox x y s)
195 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
197 (define (polygon points blotdiameter)
199 (ly:numbers->string points) " "
200 (ly:number->string (/ (length points) 2)) " "
201 (ly:number->string blotdiameter)
204 (define (repeat-slash wid slope thick)
206 (ly:numbers->string (list wid slope thick))
207 " draw_repeat_slash"))
209 (define (round-filled-box x y width height blotdiam)
212 (list x y width height blotdiam)) " draw_round_box"))
215 (define (stem breapth width depth height) ; FIXME: use draw_round_box.
217 (ly:numbers->string (list breapth width depth height))
220 (define (symmetric-x-triangle thick w h)
222 (ly:numbers->string (list h w thick))
223 " draw_symmetric_x_triangle"))
225 (define (text font s)
228 ;; ugh, we should find a better way to
229 ;; extract the hsbw for /space from the font.
231 ((space-length (cdar (ly:text-dimension font "t")))
233 (add-command (lambda (x) (set! commands (cons x commands)))) )
237 "Translate space as into moveto, group the rest in words."
238 (if (and (< 0 (string-length word))
239 (equal? #\space chr))
241 (string-append "(" (ps-encoding word) ") show\n")))
243 (if (equal? #\space chr)
244 (add-command (string-append (number->string space-length) " 0.0 rmoveto ")) )
246 (if (equal? #\space chr)
248 (string-append word (make-string 1 chr))))
250 (string-append s " "))
253 (ps-font-command font) " setfont "
254 (string-join (reverse commands)))
258 (define (white-text scale s)
259 (let ((mystring (string-append "(" s ") " (number->string scale) " /Helvetica-bold "
260 " draw_white_text")))
266 (define (zigzag-line centre? zzw zzh thick dx dy)
268 (if centre? "true" "false") " "
269 (ly:number->string zzw) " "
270 (ly:number->string zzh) " "
271 (ly:number->string thick) " "
273 (ly:number->string dx) " "
274 (ly:number->string dy)
275 " draw_zigzag_line"))
278 (define (grob-cause grob)