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
59 ;; (append (ly:all-stencil-expressions) (ly:all-output-backend-commands)))
62 ;;(write (ly:all-output-backend-commands))
63 ;;(write (ly:all-stencil-expressions))
66 ;;; helper functions, not part of output interface
67 (define (escape-parentheses s)
68 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
70 (define (offset-add a b)
71 (cons (+ (car a) (car b))
74 (define (ps-encoding text)
75 (escape-parentheses text))
78 (define-public (ps-string-def prefix key val)
79 (string-append "/" prefix (symbol->string key) " ("
80 (escape-parentheses val)
84 (define (ps-number-def prefix key val)
85 (let ((s (if (integer? val)
86 (ly:number->string val)
87 (ly:number->string (exact->inexact val)))))
88 (string-append "/" prefix (symbol->string key) " " s " def\n")))
92 ;;; Lily output interface, PostScript implementation --- cleanup and docme
95 ;;; Output-interface functions
96 (define (beam width slope thick blot)
98 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
101 (define (bezier-sandwich lst thick)
103 (string-join (map ly:number-pair->string lst) " ")
105 (ly:number->string thick)
106 " draw_bezier_sandwich"))
108 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
111 (list arch_angle arch_width arch_height height arch_thick thick))
114 (define (char font i)
116 (ps-font-command font) " setfont "
117 "(\\" (ly:inexact->string i 8) ") show" ))
119 (define (named-glyph font glyph)
121 (ps-font-command font) " setfont "
122 "/" glyph " glyphshow "))
124 (define (dashed-line thick on off dx dy)
126 (ly:number->string dx) " "
127 (ly:number->string dy) " "
128 (ly:number->string thick)
130 (ly:number->string on) " "
131 (ly:number->string off)
132 " ] 0 draw_dashed_line"))
134 ;; what the heck is this interface ?
135 (define (dashed-slur thick dash l)
137 (string-join (map ly:number-pair->string l) " ")
139 (ly:number->string thick)
141 (ly:number->string dash)
144 (ly:number->string (* 10 thick))
145 " ] 0 draw_dashed_slur"))
147 ; todo: merge with tex-font-command?
149 (define (embedded-ps string)
152 (define (dot x y radius)
156 (list x y radius)) " draw_dot"))
158 (define (white-dot x y radius)
162 (list x y radius)) " draw_white_dot"))
164 (define (draw-line thick x1 y1 x2 y2)
166 "1 setlinecap 1 setlinejoin "
167 (ly:number->string thick) " setlinewidth "
168 (ly:number->string x1) " "
169 (ly:number->string y1) " moveto "
170 (ly:number->string x2) " "
171 (ly:number->string y2) " lineto stroke"))
173 (define (ez-ball ch letter-col ball-col)
176 (ly:numbers->string (list letter-col ball-col))
177 " /Helvetica-Bold " ;; ugh
180 (define (filledbox breapth width depth height) ; FIXME : use draw_round_box
181 (string-append (ly:numbers->string (list breapth width depth height))
184 ;; WTF is this in every backend?
185 (define (horizontal-line x1 x2 th)
186 (draw-line th x1 0 x2 0))
188 (define (lily-def key val)
189 (let ((prefix "lilypondlayout"))
191 (substring key 0 (min (string-length prefix) (string-length key)))
193 (string-append "/" key " {" val "} bind def\n")
194 (string-append "/" key " (" val ") def\n"))))
197 (define (placebox x y s)
199 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
201 (define (polygon points blotdiameter)
203 (ly:numbers->string points) " "
204 (ly:number->string (/ (length points) 2)) " "
205 (ly:number->string blotdiameter)
208 (define (repeat-slash wid slope thick)
210 (ly:numbers->string (list wid slope thick))
211 " draw_repeat_slash"))
213 (define (round-filled-box x y width height blotdiam)
216 (list x y width height blotdiam)) " draw_round_box"))
218 (define (old-text font s)
221 ;; ugh, we should find a better way to
222 ;; extract the hsbw for /space from the font.
224 ((space-length (cdar (ly:text-dimension font " ")))
226 (add-command (lambda (x) (set! commands (cons x commands)))) )
230 "Translate space as into moveto, group the rest in words."
231 (if (and (< 0 (string-length word))
232 (equal? #\space chr))
234 (string-append "(" (ps-encoding word) ") show\n")))
236 (if (equal? #\space chr)
237 (add-command (string-append (number->string space-length) " 0.0 rmoveto ")) )
239 (if (equal? #\space chr)
241 (string-append word (make-string 1 chr))))
243 (string-append s " "))
246 (ps-font-command font) " setfont "
247 (string-join (reverse commands)))
250 (define (new-text font s)
252 ((space-length (cdar (ly:text-dimension font " ")))
253 (space-move (string-append (number->string space-length) " 0.0 rmoveto "))
255 (input-enc (assoc-get 'input-name
256 (ly:font-encoding-alist font)
258 (out-vec (decode-byte-string input-enc s)))
262 (ps-font-command font) " setfont "
270 (string-append "/" (symbol->string sym) " glyphshow")))
274 ;(define text old-text)
275 (define text new-text)
277 (define (white-text scale s)
278 (let ((mystring (string-append "(" s ") " (number->string scale) " /Helvetica-bold "
279 " draw_white_text")))
285 (define (zigzag-line centre? zzw zzh thick dx dy)
287 (if centre? "true" "false") " "
288 (ly:number->string zzw) " "
289 (ly:number->string zzh) " "
290 (ly:number->string thick) " "
292 (ly:number->string dx) " "
293 (ly:number->string dy)
294 " draw_zigzag_line"))
297 (define (grob-cause grob)