1 ;;;; output-ps.scm -- implement Scheme output interface for PostScript
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2006 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)
135 (define (glyph-string
141 /~a ~a ~a output-scale div scalefont setfont\n~a grestore"
144 " /CIDFont findresource "
155 (prefix (if (string? g) "/" "")))
157 (format #f " gsave ~a~a glyphshow grestore ~a ~a rmoveto \n" prefix g (+ w x) y)
159 w-x-y-named-glyphs))))
161 (define (grob-cause offset grob)
162 (let* ((cause (ly:grob-property grob 'cause))
163 (music-origin (if (ly:music? cause)
164 (ly:music-property cause 'origin))))
165 (if (not (ly:input-location? music-origin))
167 (let* ((location (ly:input-file-line-char-column music-origin))
168 (raw-file (car location))
169 (file (if (is-absolute? raw-file)
171 (string-append (ly-getcwd) "/" raw-file)))
172 (x-ext (ly:grob-extent grob grob X))
173 (y-ext (ly:grob-extent grob grob Y)))
175 (if (and (< 0 (interval-length x-ext))
176 (< 0 (interval-length y-ext)))
177 (format "~a ~a ~a ~a (textedit://~a:~a:~a:~a) mark_URI\n"
178 (ly:number->string (+ (car offset) (car x-ext)))
179 (ly:number->string (+ (cdr offset) (car y-ext)))
180 (ly:number->string (+ (car offset) (cdr x-ext)))
181 (ly:number->string (+ (cdr offset) (cdr y-ext)))
185 (string-regexp-substitute " " "%20" file)
191 (define (lily-def key val)
192 (let ((prefix "lilypondlayout"))
194 (substring key 0 (min (string-length prefix) (string-length key)))
196 (string-append "/" key " {" val "} bind def\n")
197 (string-append "/" key " (" val ") def\n"))))
199 (define (named-glyph font glyph)
201 (ps-font-command font) " setfont "
202 "/" glyph " glyphshow "))
207 (define (placebox x y s)
209 "gsave ~a ~a translate
214 (ly:number->string x)
215 (ly:number->string y)
218 (define (polygon points blot-diameter filled?)
220 (ly:numbers->string points) " "
221 (ly:number->string (/ (length points) 2)) " "
222 (ly:number->string blot-diameter)
223 (if filled? " true " " false ")
226 (define (repeat-slash wid slope thick)
228 (ly:numbers->string (list wid slope thick))
229 " draw_repeat_slash"))
231 ;; restore color from stack
233 (string-append "setrgbcolor\n"))
235 (define (round-filled-box x y width height blotdiam)
238 (list x y width height blotdiam)) " draw_round_box"))
240 ;; save current color on stack and set new color
241 (define (setcolor r g b)
242 (string-append "currentrgbcolor "
243 (ly:numbers->string (list r g b))
246 (define (text font s)
247 ;; (ly:warning (_ "TEXT backend-command encountered in Pango backend"))
248 ;; (ly:warning (_ "Arguments: ~a ~a"" font str))
250 (let* ((space-length (cdar (ly:text-dimension font " ")))
251 (space-move (string-append (number->string space-length)
253 (out-vec (decode-byte-string s)))
256 (ps-font-command font) " setfont "
264 (string-append "/" (symbol->string sym) " glyphshow")))
270 (define (url-link url x y)
271 (format "~a ~a ~a ~a (~a) mark_URI"
278 (define (utf-8-string pango-font-description string)
279 (ly:warning (_ "utf-8-string encountered in PS backend")))
283 (define (zigzag-line centre? zzw zzh thick dx dy)
285 (if centre? "true" "false") " "
286 (ly:number->string zzw) " "
287 (ly:number->string zzh) " "
288 (ly:number->string thick) " "
290 (ly:number->string dx) " "
291 (ly:number->string dy)
292 " draw_zigzag_line"))