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
54 ;;; helper functions, not part of output interface
55 (define (escape-parentheses s)
56 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
58 (define (ps-encoding text)
59 (escape-parentheses text))
62 (define-public (ps-string-def prefix key val)
63 (string-append "/" prefix (symbol->string key) " ("
64 (escape-parentheses val)
68 (define (ps-number-def prefix key val)
69 (let ((s (if (integer? val)
70 (ly:number->string val)
71 (ly:number->string (exact->inexact val)))))
72 (string-append "/" prefix (symbol->string key) " " s " def\n")))
76 ;;; Lily output interface, PostScript implementation --- cleanup and docme
79 ;;; Output-interface functions
80 (define (beam width slope thick blot)
82 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
85 (define (bezier-sandwich lst thick)
87 (string-join (map ly:number-pair->string lst) " ")
89 (ly:number->string thick)
90 " draw_bezier_sandwich"))
94 (ps-font-command font) " setfont "
95 "(\\" (ly:inexact->string i 8) ") show"))
97 (define (circle radius thick fill)
99 "~a ~a ~a draw_circle" radius thick
104 (define (dashed-line thick on off dx dy)
106 (ly:number->string dx) " "
107 (ly:number->string dy) " "
108 (ly:number->string thick)
110 (ly:number->string on) " "
111 (ly:number->string off)
112 " ] 0 draw_dashed_line"))
114 ;; what the heck is this interface ?
115 (define (dashed-slur thick on off l)
117 (string-join (map ly:number-pair->string l) " ")
119 (ly:number->string thick)
121 (ly:number->string on)
123 (ly:number->string off)
124 " ] 0 draw_dashed_slur"))
126 (define (dot x y radius)
130 (list x y radius)) " draw_dot"))
132 (define (draw-line thick x1 y1 x2 y2)
134 "1 setlinecap 1 setlinejoin "
135 (ly:number->string thick) " setlinewidth "
136 (ly:number->string x1) " "
137 (ly:number->string y1) " moveto "
138 (ly:number->string x2) " "
139 (ly:number->string y2) " lineto stroke"))
141 (define (embedded-ps string)
144 ;; FIXME: use draw_round_box
145 (define (filledbox breapth width depth height)
146 (string-append (ly:numbers->string (list breapth width depth height))
149 (define (glyph-string
154 (define (encoding-vector-hack glyphs)
156 ;; GS fucks up with glyphs that are not in the
158 (define (inner j glyphs)
159 (if (or (null? glyphs) (> j 256))
161 (cons (format "dup ~a /~a put\n"
163 (inner (1+ j) (cdr glyphs)))))
165 (format "256 array 0 1 255 { 1 index exch /.notdef put} for\n ~a
166 /EncHack reencode-font /EncHack findfont"
167 (apply string-append (inner 32 glyphs))))
170 (format #f "gsave 1 output-scale div 1 output-scale div scale
171 /~a ~a ~a scalefont setfont\n~a grestore"
174 " /CIDFont findresource "
185 (prefix (if (string? g) "/" "")))
189 (format #f " ~a~a glyphshow\n" prefix g)
190 (format #f " ~a ~a rmoveto ~a~a glyphshow\n"
196 (define (grob-cause offset grob)
197 (let* ((cause (ly:grob-property grob 'cause))
198 (music-origin (if (ly:music? cause)
199 (ly:music-property cause 'origin))))
200 (if (not (ly:input-location? music-origin))
202 (let* ((location (ly:input-file-line-column music-origin))
203 (raw-file (car location))
204 (file (if (is-absolute? raw-file)
206 (string-append (ly-getcwd) "/" raw-file)))
207 (x-ext (ly:grob-extent grob grob X))
208 (y-ext (ly:grob-extent grob grob Y)))
210 (if (and (< 0 (interval-length x-ext))
211 (< 0 (interval-length y-ext)))
212 (format "~a ~a ~a ~a (textedit://~a:~a:~a) mark_URI\n"
213 (+ (car offset) (car x-ext))
214 (+ (cdr offset) (car y-ext))
215 (+ (car offset) (cdr x-ext))
216 (+ (cdr offset) (cdr y-ext))
222 (define (lily-def key val)
223 (let ((prefix "lilypondlayout"))
225 (substring key 0 (min (string-length prefix) (string-length key)))
227 (string-append "/" key " {" val "} bind def\n")
228 (string-append "/" key " (" val ") def\n"))))
230 (define (named-glyph font glyph)
232 (ps-font-command font) " setfont "
233 "/" glyph " glyphshow "))
238 (define (placebox x y s)
240 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
242 (define (polygon points blotdiameter filled?)
244 (ly:numbers->string points) " "
245 (ly:number->string (/ (length points) 2)) " "
246 (ly:number->string blotdiameter)
247 (if filled? " true " " false ")
250 (define (repeat-slash wid slope thick)
252 (ly:numbers->string (list wid slope thick))
253 " draw_repeat_slash"))
255 ;; restore color from stack
257 (string-append "setrgbcolor\n"))
259 (define (round-filled-box x y width height blotdiam)
262 (list x y width height blotdiam)) " draw_round_box"))
264 ;; save current color on stack and set new color
265 (define (setcolor r g b)
266 (string-append "currentrgbcolor "
267 (ly:numbers->string (list r g b))
270 (define (text font s)
271 ;; (ly:warning (_ "TEXT backend-command encountered in Pango backend"))
272 ;; (ly:warning (_ "Arguments: ~a ~a"" font str))
274 (let* ((space-length (cdar (ly:text-dimension font " ")))
275 (space-move (string-append (number->string space-length)
277 (out-vec (decode-byte-string s)))
280 (ps-font-command font) " setfont "
288 (string-append "/" (symbol->string sym) " glyphshow")))
294 (define (url-link url x y)
295 (format "~a ~a ~a ~a (~a) mark_URI"
302 (define (utf8-string pango-font-description string)
303 (ly:warning (_ "utf8-string encountered in PS backend")))
308 (define (white-dot x y radius)
312 (list x y radius)) " draw_white_dot"))
314 (define (white-text scale s)
315 (let ((mystring (string-append
316 "(" s ") " (number->string scale)
318 " draw_white_text")))
322 (define (zigzag-line centre? zzw zzh thick dx dy)
324 (if centre? "true" "false") " "
325 (ly:number->string zzw) " "
326 (ly:number->string zzh) " "
327 (ly:number->string thick) " "
329 (ly:number->string dx) " "
330 (ly:number->string dy)
331 " draw_zigzag_line"))