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 (format #f "gsave 1 output-scale div 1 output-scale div scale
155 /~a ~a ~a scalefont setfont\n~a grestore"
158 " /CIDFont findresource "
169 (prefix (if (string? g) "/" "")))
173 (format #f " ~a~a glyphshow\n" prefix g)
174 (format #f " ~a ~a rmoveto ~a~a glyphshow\n"
180 (define (grob-cause offset grob)
181 (let* ((cause (ly:grob-property grob 'cause))
182 (music-origin (if (ly:music? cause)
183 (ly:music-property cause 'origin))))
184 (if (not (ly:input-location? music-origin))
186 (let* ((location (ly:input-file-line-column music-origin))
187 (raw-file (car location))
188 (file (if (is-absolute? raw-file)
190 (string-append (ly-getcwd) "/" raw-file)))
191 (x-ext (ly:grob-extent grob grob X))
192 (y-ext (ly:grob-extent grob grob Y)))
194 (if (and (< 0 (interval-length x-ext))
195 (< 0 (interval-length y-ext)))
196 (format "~a ~a ~a ~a (textedit://~a:~a:~a) mark_URI\n"
197 (+ (car offset) (car x-ext))
198 (+ (cdr offset) (car y-ext))
199 (+ (car offset) (cdr x-ext))
200 (+ (cdr offset) (cdr y-ext))
206 (define (lily-def key val)
207 (let ((prefix "lilypondlayout"))
209 (substring key 0 (min (string-length prefix) (string-length key)))
211 (string-append "/" key " {" val "} bind def\n")
212 (string-append "/" key " (" val ") def\n"))))
214 (define (named-glyph font glyph)
216 (ps-font-command font) " setfont "
217 "/" glyph " glyphshow "))
222 (define (placebox x y s)
224 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
226 (define (polygon points blotdiameter filled?)
228 (ly:numbers->string points) " "
229 (ly:number->string (/ (length points) 2)) " "
230 (ly:number->string blotdiameter)
231 (if filled? " true " " false ")
234 (define (repeat-slash wid slope thick)
236 (ly:numbers->string (list wid slope thick))
237 " draw_repeat_slash"))
239 ;; restore color from stack
241 (string-append "setrgbcolor\n"))
243 (define (round-filled-box x y width height blotdiam)
246 (list x y width height blotdiam)) " draw_round_box"))
248 ;; save current color on stack and set new color
249 (define (setcolor r g b)
250 (string-append "currentrgbcolor "
251 (ly:numbers->string (list r g b))
254 (define (text font s)
255 ;; (ly:warning (_ "TEXT backend-command encountered in Pango backend"))
256 ;; (ly:warning (_ "Arguments: ~a ~a"" font str))
258 (let* ((space-length (cdar (ly:text-dimension font " ")))
259 (space-move (string-append (number->string space-length)
261 (out-vec (decode-byte-string s)))
264 (ps-font-command font) " setfont "
272 (string-append "/" (symbol->string sym) " glyphshow")))
278 (define (url-link url x y)
279 (format "~a ~a ~a ~a (~a) mark_URI"
286 (define (utf8-string pango-font-description string)
287 (ly:warning (_ "utf8-string encountered in PS backend")))
292 (define (white-dot x y radius)
296 (list x y radius)) " draw_white_dot"))
298 (define (white-text scale s)
299 (let ((mystring (string-append
300 "(" s ") " (number->string scale)
302 " draw_white_text")))
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"))