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))
66 ;;; helper functions, not part of output interface
67 (define (escape-parentheses s)
68 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
70 (define (ps-encoding text)
71 (escape-parentheses text))
74 (define-public (ps-string-def prefix key val)
75 (string-append "/" prefix (symbol->string key) " ("
76 (escape-parentheses val)
80 (define (ps-number-def prefix key val)
81 (let ((s (if (integer? val)
82 (ly:number->string val)
83 (ly:number->string (exact->inexact val)))))
84 (string-append "/" prefix (symbol->string key) " " s " def\n")))
88 ;;; Lily output interface, PostScript implementation --- cleanup and docme
91 ;;; Output-interface functions
92 (define (beam width slope thick blot)
94 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
97 (define (bezier-sandwich lst thick)
99 (string-join (map ly:number-pair->string lst) " ")
101 (ly:number->string thick)
102 " draw_bezier_sandwich"))
104 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
107 (list arch_angle arch_width arch_height height arch_thick thick))
110 (define (circle radius thick)
112 "~a ~a draw_circle" radius thick))
114 (define (char font i)
116 (ps-font-command font) " setfont "
117 "(\\" (ly:inexact->string i 8) ") show"))
119 (define (dashed-line thick on off dx dy)
121 (ly:number->string dx) " "
122 (ly:number->string dy) " "
123 (ly:number->string thick)
125 (ly:number->string on) " "
126 (ly:number->string off)
127 " ] 0 draw_dashed_line"))
129 ;; what the heck is this interface ?
130 (define (dashed-slur thick on off l)
132 (string-join (map ly:number-pair->string l) " ")
134 (ly:number->string thick)
136 (ly:number->string on)
138 (ly:number->string off)
139 " ] 0 draw_dashed_slur"))
141 (define (dot x y radius)
145 (list x y radius)) " draw_dot"))
147 (define (draw-line thick x1 y1 x2 y2)
149 "1 setlinecap 1 setlinejoin "
150 (ly:number->string thick) " setlinewidth "
151 (ly:number->string x1) " "
152 (ly:number->string y1) " moveto "
153 (ly:number->string x2) " "
154 (ly:number->string y2) " lineto stroke"))
156 (define (embedded-ps string)
160 (define (ez-ball ch letter-col ball-col)
163 (ly:numbers->string (list letter-col ball-col))
168 ;; FIXME: use draw_round_box
169 (define (filledbox breapth width depth height)
170 (string-append (ly:numbers->string (list breapth width depth height))
173 (define (glyph-string
177 (format #f "gsave 1 output-scale div 1 output-scale div scale
178 /~a findfont ~a scalefont setfont\n~a grestore" postscript-font-name size
189 (format #f " /~a glyphshow " g)
190 (format #f " ~a ~a rmoveto /~a glyphshow "
195 (define (grob-cause offset grob)
196 (let* ((cause (ly:grob-property grob 'cause))
197 (music-origin (if (ly:music? cause)
198 (ly:music-property cause 'origin)))
199 (location (if (ly:input-location? music-origin)
200 (ly:input-file-line-column music-origin)
203 (file (if location (string-append (getcwd) "/" (car location))
205 (x-ext (ly:grob-extent grob grob X))
206 (y-ext (ly:grob-extent grob grob Y))
210 (< 0 (interval-length x-ext))
211 (< 0 (interval-length y-ext)))
213 (format "~a ~a ~a ~a (textedit://~a:~a:~a) mark_URI\n"
214 (+ (car offset) (car x-ext))
215 (+ (cdr offset) (car y-ext))
216 (+ (car offset) (cdr x-ext))
217 (+ (cdr offset) (cdr y-ext))
223 ;; WTF is this in every backend?
224 (define (horizontal-line x1 x2 th)
225 (draw-line th x1 0 x2 0))
227 (define (lily-def key val)
228 (let ((prefix "lilypondlayout"))
230 (substring key 0 (min (string-length prefix) (string-length key)))
232 (string-append "/" key " {" val "} bind def\n")
233 (string-append "/" key " (" val ") def\n"))))
235 (define (named-glyph font glyph)
237 (ps-font-command font) " setfont "
238 "/" glyph " glyphshow "))
243 (define (placebox x y s)
245 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
247 (define (polygon points blotdiameter)
249 (ly:numbers->string points) " "
250 (ly:number->string (/ (length points) 2)) " "
251 (ly:number->string blotdiameter)
254 (define (repeat-slash wid slope thick)
256 (ly:numbers->string (list wid slope thick))
257 " draw_repeat_slash"))
259 ;; restore color from stack
261 (string-append "setrgbcolor\n"))
263 (define (round-filled-box x y width height blotdiam)
266 (list x y width height blotdiam)) " draw_round_box"))
268 ;; save current color on stack and set new color
269 (define (setcolor r g b)
270 (string-append "currentrgbcolor "
271 (ly:numbers->string (list r g b))
274 (define (text font s)
275 ; (ly:warn "TEXT backend-command encountered in Pango backend\nargs: ~a ~a" font str)
277 (let* ((space-length (cdar (ly:text-dimension font " ")))
278 (space-move (string-append (number->string space-length)
280 (out-vec (decode-byte-string s)))
283 (ps-font-command font) " setfont "
291 (string-append "/" (symbol->string sym) " glyphshow")))
297 (define (url-link url x y)
298 (format "~a ~a ~a ~a (~a) mark_URI"
305 (define (utf8-string pango-font-description string)
306 (ly:warn "utf8-string encountered in PS backend"))
308 (define (white-dot x y radius)
312 (list x y radius)) " draw_white_dot"))
314 (define (white-text scale s)
315 (let ((mystring (string-append
316 "(" s ") " (number->string scale)
318 " draw_white_text")))
322 (define (zigzag-line centre? zzw zzh thick dx dy)
324 (if centre? "true" "false") " "
325 (ly:number->string zzw) " "
326 (ly:number->string zzh) " "
327 (ly:number->string thick) " "
329 (ly:number->string dx) " "
330 (ly:number->string dy)
331 " draw_zigzag_line"))