1 ;;;; output-ps.scm -- implement Scheme output interface for PostScript
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2005 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 (define-module (scm output-ps)
19 ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
50 ;;; helper functions, not part of output interface
51 (define (escape-parentheses s)
52 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
54 (define (ps-encoding text)
55 (escape-parentheses text))
58 (define-public (ps-string-def prefix key val)
59 (string-append "/" prefix (symbol->string key) " ("
60 (escape-parentheses val)
64 (define (ps-number-def prefix key val)
65 (let ((s (if (integer? val)
66 (ly:number->string val)
67 (ly:number->string (exact->inexact val)))))
68 (string-append "/" prefix (symbol->string key) " " s " def\n")))
72 ;;; Lily output interface, PostScript implementation --- cleanup and docme
76 (define (bezier-sandwich lst thick)
78 (string-join (map ly:number-pair->string lst) " ")
80 (ly:number->string thick)
81 " draw_bezier_sandwich"))
85 (ps-font-command font) " setfont "
86 "(\\" (ly:inexact->string i 8) ") show"))
88 (define (circle radius thick fill)
90 "~a ~a ~a draw_circle" radius thick
95 (define (dashed-line thick on off dx dy)
97 (ly:number->string dx) " "
98 (ly:number->string dy) " "
99 (ly:number->string thick)
101 (ly:number->string on) " "
102 (ly:number->string off)
103 " ] 0 draw_dashed_line"))
105 ;; what the heck is this interface ?
106 (define (dashed-slur thick on off l)
108 (string-join (map ly:number-pair->string l) " ")
110 (ly:number->string thick)
112 (ly:number->string on)
114 (ly:number->string off)
115 " ] 0 draw_dashed_slur"))
117 (define (dot x y radius)
121 (list x y radius)) " draw_dot"))
123 (define (draw-line thick x1 y1 x2 y2)
125 "1 setlinecap 1 setlinejoin "
126 (ly:number->string thick) " setlinewidth "
127 (ly:number->string x1) " "
128 (ly:number->string y1) " moveto "
129 (ly:number->string x2) " "
130 (ly:number->string y2) " lineto stroke"))
132 (define (embedded-ps string)
136 (define (glyph-string
141 (define (encoding-vector-hack glyphs)
143 ;; GS fucks up with glyphs that are not in the
145 (define (inner j glyphs)
146 (if (or (null? glyphs) (> j 256))
148 (cons (format "dup ~a /~a put\n"
150 (inner (1+ j) (cdr glyphs)))))
152 (format "256 array 0 1 255 { 1 index exch /.notdef put} for\n ~a
153 /EncHack reencode-font /EncHack findfont"
154 (apply string-append (inner 32 glyphs))))
157 (format #f "gsave 1 output-scale div 1 output-scale div scale
158 /~a ~a ~a scalefont setfont\n~a grestore"
161 " /CIDFont findresource "
172 (prefix (if (string? g) "/" "")))
176 (format #f " ~a~a glyphshow\n" prefix g)
177 (format #f " ~a ~a rmoveto ~a~a glyphshow\n"
183 (define (grob-cause offset grob)
184 (let* ((cause (ly:grob-property grob 'cause))
185 (music-origin (if (ly:music? cause)
186 (ly:music-property cause 'origin))))
187 (if (not (ly:input-location? music-origin))
189 (let* ((location (ly:input-file-line-char-column music-origin))
190 (raw-file (car location))
191 (file (if (is-absolute? raw-file)
193 (string-append (ly-getcwd) "/" raw-file)))
194 (x-ext (ly:grob-extent grob grob X))
195 (y-ext (ly:grob-extent grob grob Y)))
197 (if (and (< 0 (interval-length x-ext))
198 (< 0 (interval-length y-ext)))
199 (format "~a ~a ~a ~a (textedit://~a:~a:~a:~a) mark_URI\n"
200 (+ (car offset) (car x-ext))
201 (+ (cdr offset) (car y-ext))
202 (+ (car offset) (cdr x-ext))
203 (+ (cdr offset) (cdr y-ext))
207 (re-sub " " "%20" file)
213 (define (lily-def key val)
214 (let ((prefix "lilypondlayout"))
216 (substring key 0 (min (string-length prefix) (string-length key)))
218 (string-append "/" key " {" val "} bind def\n")
219 (string-append "/" key " (" val ") def\n"))))
221 (define (named-glyph font glyph)
223 (ps-font-command font) " setfont "
224 "/" glyph " glyphshow "))
229 (define (placebox x y s)
231 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
233 (define (polygon points blotdiameter filled?)
235 (ly:numbers->string points) " "
236 (ly:number->string (/ (length points) 2)) " "
237 (ly:number->string blotdiameter)
238 (if filled? " true " " false ")
241 (define (repeat-slash wid slope thick)
243 (ly:numbers->string (list wid slope thick))
244 " draw_repeat_slash"))
246 ;; restore color from stack
248 (string-append "setrgbcolor\n"))
250 (define (round-filled-box x y width height blotdiam)
253 (list x y width height blotdiam)) " draw_round_box"))
255 ;; save current color on stack and set new color
256 (define (setcolor r g b)
257 (string-append "currentrgbcolor "
258 (ly:numbers->string (list r g b))
261 (define (text font s)
262 ;; (ly:warning (_ "TEXT backend-command encountered in Pango backend"))
263 ;; (ly:warning (_ "Arguments: ~a ~a"" font str))
265 (let* ((space-length (cdar (ly:text-dimension font " ")))
266 (space-move (string-append (number->string space-length)
268 (out-vec (decode-byte-string s)))
271 (ps-font-command font) " setfont "
279 (string-append "/" (symbol->string sym) " glyphshow")))
285 (define (url-link url x y)
286 (format "~a ~a ~a ~a (~a) mark_URI"
293 (define (utf-8-string pango-font-description string)
294 (ly:warning (_ "utf-8-string encountered in PS backend")))
298 (define (zigzag-line centre? zzw zzh thick dx dy)
300 (if centre? "true" "false") " "
301 (ly:number->string zzw) " "
302 (ly:number->string zzh) " "
303 (ly:number->string thick) " "
305 (ly:number->string dx) " "
306 (ly:number->string dy)
307 " draw_zigzag_line"))