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
56 ;; (append (ly:all-stencil-expressions) (ly:all-output-backend-commands)))
59 ;;(write (ly:all-output-backend-commands))
60 ;;(write (ly:all-stencil-expressions))
62 ;;; helper functions, not part of output interface
63 (define (escape-parentheses s)
64 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
66 (define (ps-encoding text)
67 (escape-parentheses text))
70 (define-public (ps-string-def prefix key val)
71 (string-append "/" prefix (symbol->string key) " ("
72 (escape-parentheses val)
76 (define (ps-number-def prefix key val)
77 (let ((s (if (integer? val)
78 (ly:number->string val)
79 (ly:number->string (exact->inexact val)))))
80 (string-append "/" prefix (symbol->string key) " " s " def\n")))
84 ;;; Lily output interface, PostScript implementation --- cleanup and docme
87 ;;; Output-interface functions
88 (define (beam width slope thick blot)
90 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
93 (define (bezier-sandwich lst thick)
95 (string-join (map ly:number-pair->string lst) " ")
97 (ly:number->string thick)
98 " draw_bezier_sandwich"))
100 (define (char font i)
102 (ps-font-command font) " setfont "
103 "(\\" (ly:inexact->string i 8) ") show"))
105 (define (circle radius thick fill)
107 "~a ~a ~a draw_circle" radius thick
112 (define (dashed-line thick on off dx dy)
114 (ly:number->string dx) " "
115 (ly:number->string dy) " "
116 (ly:number->string thick)
118 (ly:number->string on) " "
119 (ly:number->string off)
120 " ] 0 draw_dashed_line"))
122 ;; what the heck is this interface ?
123 (define (dashed-slur thick on off l)
125 (string-join (map ly:number-pair->string l) " ")
127 (ly:number->string thick)
129 (ly:number->string on)
131 (ly:number->string off)
132 " ] 0 draw_dashed_slur"))
134 (define (dot x y radius)
138 (list x y radius)) " draw_dot"))
140 (define (draw-line thick x1 y1 x2 y2)
142 "1 setlinecap 1 setlinejoin "
143 (ly:number->string thick) " setlinewidth "
144 (ly:number->string x1) " "
145 (ly:number->string y1) " moveto "
146 (ly:number->string x2) " "
147 (ly:number->string y2) " lineto stroke"))
149 (define (embedded-ps string)
152 ;; FIXME: use draw_round_box
153 (define (filledbox breapth width depth height)
154 (string-append (ly:numbers->string (list breapth width depth height))
157 (define (glyph-string
162 (format #f "gsave 1 output-scale div 1 output-scale div scale
163 /~a ~a ~a scalefont setfont\n~a grestore"
166 " /CIDFont findresource "
177 (prefix (if (string? g) "/" "")))
181 (format #f " ~a~a glyphshow\n" prefix g)
182 (format #f " ~a ~a rmoveto ~a~a glyphshow\n"
188 (define (grob-cause offset grob)
189 (let* ((cause (ly:grob-property grob 'cause))
190 (music-origin (if (ly:music? cause)
191 (ly:music-property cause 'origin))))
192 (if (not (ly:input-location? music-origin))
194 (let* ((location (ly:input-file-line-column music-origin))
195 (raw-file (car location))
196 (file (if (is-absolute? raw-file)
198 (string-append (ly-getcwd) "/" raw-file)))
199 (x-ext (ly:grob-extent grob grob X))
200 (y-ext (ly:grob-extent grob grob Y)))
202 (if (and (< 0 (interval-length x-ext))
203 (< 0 (interval-length y-ext)))
204 (format "~a ~a ~a ~a (textedit://~a:~a:~a) mark_URI\n"
205 (+ (car offset) (car x-ext))
206 (+ (cdr offset) (car y-ext))
207 (+ (car offset) (cdr x-ext))
208 (+ (cdr offset) (cdr y-ext))
214 (define (lily-def key val)
215 (let ((prefix "lilypondlayout"))
217 (substring key 0 (min (string-length prefix) (string-length key)))
219 (string-append "/" key " {" val "} bind def\n")
220 (string-append "/" key " (" val ") def\n"))))
222 (define (named-glyph font glyph)
224 (ps-font-command font) " setfont "
225 "/" glyph " glyphshow "))
230 (define (placebox x y s)
232 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
234 (define (polygon points blotdiameter filled?)
236 (ly:numbers->string points) " "
237 (ly:number->string (/ (length points) 2)) " "
238 (ly:number->string blotdiameter)
239 (if filled? " true " " false ")
242 (define (repeat-slash wid slope thick)
244 (ly:numbers->string (list wid slope thick))
245 " draw_repeat_slash"))
247 ;; restore color from stack
249 (string-append "setrgbcolor\n"))
251 (define (round-filled-box x y width height blotdiam)
254 (list x y width height blotdiam)) " draw_round_box"))
256 ;; save current color on stack and set new color
257 (define (setcolor r g b)
258 (string-append "currentrgbcolor "
259 (ly:numbers->string (list r g b))
262 (define (text font s)
263 ;; (ly:warning (_ "TEXT backend-command encountered in Pango backend"))
264 ;; (ly:warning (_ "Arguments: ~a ~a"" font str))
266 (let* ((space-length (cdar (ly:text-dimension font " ")))
267 (space-move (string-append (number->string space-length)
269 (out-vec (decode-byte-string s)))
272 (ps-font-command font) " setfont "
280 (string-append "/" (symbol->string sym) " glyphshow")))
286 (define (url-link url x y)
287 (format "~a ~a ~a ~a (~a) mark_URI"
294 (define (utf8-string pango-font-description string)
295 (ly:warning (_ "utf8-string encountered in PS backend")))
300 (define (white-dot x y radius)
304 (list x y radius)) " draw_white_dot"))
306 (define (white-text scale s)
307 (let ((mystring (string-append
308 "(" s ") " (number->string scale)
310 " draw_white_text")))
314 (define (zigzag-line centre? zzw zzh thick dx dy)
316 (if centre? "true" "false") " "
317 (ly:number->string zzw) " "
318 (ly:number->string zzh) " "
319 (ly:number->string thick) " "
321 (ly:number->string dx) " "
322 (ly:number->string dy)
323 " draw_zigzag_line"))