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
59 ;; (append (ly:all-stencil-expressions) (ly:all-output-backend-commands)))
62 ;;(write (ly:all-output-backend-commands))
63 ;;(write (ly:all-stencil-expressions))
65 ;;; helper functions, not part of output interface
66 (define (escape-parentheses s)
67 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
69 (define (ps-encoding text)
70 (escape-parentheses text))
73 (define-public (ps-string-def prefix key val)
74 (string-append "/" prefix (symbol->string key) " ("
75 (escape-parentheses val)
79 (define (ps-number-def prefix key val)
80 (let ((s (if (integer? val)
81 (ly:number->string val)
82 (ly:number->string (exact->inexact val)))))
83 (string-append "/" prefix (symbol->string key) " " s " def\n")))
87 ;;; Lily output interface, PostScript implementation --- cleanup and docme
90 ;;; Output-interface functions
91 (define (beam width slope thick blot)
93 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
96 (define (bezier-sandwich lst thick)
98 (string-join (map ly:number-pair->string lst) " ")
100 (ly:number->string thick)
101 " draw_bezier_sandwich"))
103 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
106 (list arch_angle arch_width arch_height height arch_thick thick))
109 (define (circle radius thick fill)
111 "~a ~a ~a draw_circle" radius thick
117 (define (char font i)
119 (ps-font-command font) " setfont "
120 "(\\" (ly:inexact->string i 8) ") show"))
122 (define (dashed-line thick on off dx dy)
124 (ly:number->string dx) " "
125 (ly:number->string dy) " "
126 (ly:number->string thick)
128 (ly:number->string on) " "
129 (ly:number->string off)
130 " ] 0 draw_dashed_line"))
132 ;; what the heck is this interface ?
133 (define (dashed-slur thick on off l)
135 (string-join (map ly:number-pair->string l) " ")
137 (ly:number->string thick)
139 (ly:number->string on)
141 (ly:number->string off)
142 " ] 0 draw_dashed_slur"))
144 (define (dot x y radius)
148 (list x y radius)) " draw_dot"))
150 (define (draw-line thick x1 y1 x2 y2)
152 "1 setlinecap 1 setlinejoin "
153 (ly:number->string thick) " setlinewidth "
154 (ly:number->string x1) " "
155 (ly:number->string y1) " moveto "
156 (ly:number->string x2) " "
157 (ly:number->string y2) " lineto stroke"))
159 (define (embedded-ps string)
163 (define (ez-ball ch letter-col ball-col)
166 (ly:numbers->string (list letter-col ball-col))
171 ;; FIXME: use draw_round_box
172 (define (filledbox breapth width depth height)
173 (string-append (ly:numbers->string (list breapth width depth height))
176 (define (glyph-string
180 (format #f "gsave 1 output-scale div 1 output-scale div scale
181 /~a findfont ~a scalefont setfont\n~a grestore" postscript-font-name size
192 (format #f " /~a glyphshow\n" g)
193 (format #f " ~a ~a rmoveto /~a glyphshow\n"
197 (define (grob-cause offset grob)
198 (let* ((cause (ly:grob-property grob 'cause))
199 (music-origin (if (ly:music? cause)
200 (ly:music-property cause 'origin))))
201 (if (not (ly:input-location? music-origin))
203 (let* ((location (ly:input-file-line-column music-origin))
204 (raw-file (car location))
205 (file (if (and (> (string-length raw-file) 0)
206 (eq? (string-ref raw-file 0) #\/))
208 (string-append (getcwd) "/" raw-file)))
209 (x-ext (ly:grob-extent grob grob X))
210 (y-ext (ly:grob-extent grob grob Y)))
212 (if (and (< 0 (interval-length x-ext))
213 (< 0 (interval-length y-ext)))
214 (format "~a ~a ~a ~a (textedit://~a:~a:~a) mark_URI\n"
215 (+ (car offset) (car x-ext))
216 (+ (cdr offset) (car y-ext))
217 (+ (car offset) (cdr x-ext))
218 (+ (cdr offset) (cdr y-ext))
224 ;; WTF is this in every backend?
225 (define (horizontal-line x1 x2 th)
226 (draw-line th x1 0 x2 0))
228 (define (lily-def key val)
229 (let ((prefix "lilypondlayout"))
231 (substring key 0 (min (string-length prefix) (string-length key)))
233 (string-append "/" key " {" val "} bind def\n")
234 (string-append "/" key " (" val ") def\n"))))
236 (define (named-glyph font glyph)
238 (ps-font-command font) " setfont "
239 "/" glyph " glyphshow "))
244 (define (placebox x y s)
246 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
248 (define (polygon points blotdiameter filled?)
250 (ly:numbers->string points) " "
251 (ly:number->string (/ (length points) 2)) " "
252 (ly:number->string blotdiameter)
253 (if filled? " true " " false ")
256 (define (repeat-slash wid slope thick)
258 (ly:numbers->string (list wid slope thick))
259 " draw_repeat_slash"))
261 ;; restore color from stack
263 (string-append "setrgbcolor\n"))
265 (define (round-filled-box x y width height blotdiam)
268 (list x y width height blotdiam)) " draw_round_box"))
270 ;; save current color on stack and set new color
271 (define (setcolor r g b)
272 (string-append "currentrgbcolor "
273 (ly:numbers->string (list r g b))
276 (define (text font s)
277 ;; (ly:warning (_ "TEXT backend-command encountered in Pango backend"))
278 ;; (ly:warning (_ "Arguments: ~a ~a"" font str))
280 (let* ((space-length (cdar (ly:text-dimension font " ")))
281 (space-move (string-append (number->string space-length)
283 (out-vec (decode-byte-string s)))
286 (ps-font-command font) " setfont "
294 (string-append "/" (symbol->string sym) " glyphshow")))
300 (define (url-link url x y)
301 (format "~a ~a ~a ~a (~a) mark_URI"
308 (define (utf8-string pango-font-description string)
309 (ly:warning (_ "utf8-string encountered in PS backend")))
311 (define (white-dot x y radius)
315 (list x y radius)) " draw_white_dot"))
317 (define (white-text scale s)
318 (let ((mystring (string-append
319 "(" s ") " (number->string scale)
321 " draw_white_text")))
325 (define (zigzag-line centre? zzw zzh thick dx dy)
327 (if centre? "true" "false") " "
328 (ly:number->string zzw) " "
329 (ly:number->string zzh) " "
330 (ly:number->string thick) " "
332 (ly:number->string dx) " "
333 (ly:number->string dy)
334 " draw_zigzag_line"))