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
52 ;;; helper functions, not part of output interface
53 (define (escape-parentheses s)
54 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
56 (define (ps-encoding text)
57 (escape-parentheses text))
60 (define-public (ps-string-def prefix key val)
61 (string-append "/" prefix (symbol->string key) " ("
62 (escape-parentheses val)
66 (define (ps-number-def prefix key val)
67 (let ((s (if (integer? val)
68 (ly:number->string val)
69 (ly:number->string (exact->inexact val)))))
70 (string-append "/" prefix (symbol->string key) " " s " def\n")))
74 ;;; Lily output interface, PostScript implementation --- cleanup and docme
77 ;;; Output-interface functions
78 (define (beam width slope thick blot)
80 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
83 (define (bezier-sandwich lst thick)
85 (string-join (map ly:number-pair->string lst) " ")
87 (ly:number->string thick)
88 " draw_bezier_sandwich"))
92 (ps-font-command font) " setfont "
93 "(\\" (ly:inexact->string i 8) ") show"))
95 (define (circle radius thick fill)
97 "~a ~a ~a draw_circle" radius thick
102 (define (dashed-line thick on off dx dy)
104 (ly:number->string dx) " "
105 (ly:number->string dy) " "
106 (ly:number->string thick)
108 (ly:number->string on) " "
109 (ly:number->string off)
110 " ] 0 draw_dashed_line"))
112 ;; what the heck is this interface ?
113 (define (dashed-slur thick on off l)
115 (string-join (map ly:number-pair->string l) " ")
117 (ly:number->string thick)
119 (ly:number->string on)
121 (ly:number->string off)
122 " ] 0 draw_dashed_slur"))
124 (define (dot x y radius)
128 (list x y radius)) " draw_dot"))
130 (define (draw-line thick x1 y1 x2 y2)
132 "1 setlinecap 1 setlinejoin "
133 (ly:number->string thick) " setlinewidth "
134 (ly:number->string x1) " "
135 (ly:number->string y1) " moveto "
136 (ly:number->string x2) " "
137 (ly:number->string y2) " lineto stroke"))
139 (define (embedded-ps string)
142 ;; FIXME: use draw_round_box
143 (define (filledbox breapth width depth height)
144 (string-append (ly:numbers->string (list breapth width depth height))
147 (define (glyph-string
152 (define (encoding-vector-hack glyphs)
154 ;; GS fucks up with glyphs that are not in the
156 (define (inner j glyphs)
157 (if (or (null? glyphs) (> j 256))
159 (cons (format "dup ~a /~a put\n"
161 (inner (1+ j) (cdr glyphs)))))
163 (format "256 array 0 1 255 { 1 index exch /.notdef put} for\n ~a
164 /EncHack reencode-font /EncHack findfont"
165 (apply string-append (inner 32 glyphs))))
168 (format #f "gsave 1 output-scale div 1 output-scale div scale
169 /~a ~a ~a scalefont setfont\n~a grestore"
172 " /CIDFont findresource "
183 (prefix (if (string? g) "/" "")))
187 (format #f " ~a~a glyphshow\n" prefix g)
188 (format #f " ~a ~a rmoveto ~a~a glyphshow\n"
194 (define (grob-cause offset grob)
195 (let* ((cause (ly:grob-property grob 'cause))
196 (music-origin (if (ly:music? cause)
197 (ly:music-property cause 'origin))))
198 (if (not (ly:input-location? music-origin))
200 (let* ((location (ly:input-file-line-char-column music-origin))
201 (raw-file (car location))
202 (file (if (is-absolute? raw-file)
204 (string-append (ly-getcwd) "/" raw-file)))
205 (x-ext (ly:grob-extent grob grob X))
206 (y-ext (ly:grob-extent grob grob Y)))
208 (if (and (< 0 (interval-length x-ext))
209 (< 0 (interval-length y-ext)))
210 (format "~a ~a ~a ~a (textedit://~a:~a:~a:~a) mark_URI\n"
211 (+ (car offset) (car x-ext))
212 (+ (cdr offset) (car y-ext))
213 (+ (car offset) (cdr x-ext))
214 (+ (cdr offset) (cdr y-ext))
221 (define (lily-def key val)
222 (let ((prefix "lilypondlayout"))
224 (substring key 0 (min (string-length prefix) (string-length key)))
226 (string-append "/" key " {" val "} bind def\n")
227 (string-append "/" key " (" val ") def\n"))))
229 (define (named-glyph font glyph)
231 (ps-font-command font) " setfont "
232 "/" glyph " glyphshow "))
237 (define (placebox x y s)
239 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
241 (define (polygon points blotdiameter filled?)
243 (ly:numbers->string points) " "
244 (ly:number->string (/ (length points) 2)) " "
245 (ly:number->string blotdiameter)
246 (if filled? " true " " false ")
249 (define (repeat-slash wid slope thick)
251 (ly:numbers->string (list wid slope thick))
252 " draw_repeat_slash"))
254 ;; restore color from stack
256 (string-append "setrgbcolor\n"))
258 (define (round-filled-box x y width height blotdiam)
261 (list x y width height blotdiam)) " draw_round_box"))
263 ;; save current color on stack and set new color
264 (define (setcolor r g b)
265 (string-append "currentrgbcolor "
266 (ly:numbers->string (list r g b))
269 (define (text font s)
270 ;; (ly:warning (_ "TEXT backend-command encountered in Pango backend"))
271 ;; (ly:warning (_ "Arguments: ~a ~a"" font str))
273 (let* ((space-length (cdar (ly:text-dimension font " ")))
274 (space-move (string-append (number->string space-length)
276 (out-vec (decode-byte-string s)))
279 (ps-font-command font) " setfont "
287 (string-append "/" (symbol->string sym) " glyphshow")))
293 (define (url-link url x y)
294 (format "~a ~a ~a ~a (~a) mark_URI"
301 (define (utf8-string pango-font-description string)
302 (ly:warning (_ "utf8-string encountered in PS backend")))
306 (define (zigzag-line centre? zzw zzh thick dx dy)
308 (if centre? "true" "false") " "
309 (ly:number->string zzw) " "
310 (ly:number->string zzh) " "
311 (ly:number->string thick) " "
313 (ly:number->string dx) " "
314 (ly:number->string dy)
315 " draw_zigzag_line"))