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 fill)
112 "~a ~a ~a draw_circle" radius thick
118 (define (char font i)
120 (ps-font-command font) " setfont "
121 "(\\" (ly:inexact->string i 8) ") show"))
123 (define (dashed-line thick on off dx dy)
125 (ly:number->string dx) " "
126 (ly:number->string dy) " "
127 (ly:number->string thick)
129 (ly:number->string on) " "
130 (ly:number->string off)
131 " ] 0 draw_dashed_line"))
133 ;; what the heck is this interface ?
134 (define (dashed-slur thick on off l)
136 (string-join (map ly:number-pair->string l) " ")
138 (ly:number->string thick)
140 (ly:number->string on)
142 (ly:number->string off)
143 " ] 0 draw_dashed_slur"))
145 (define (dot x y radius)
149 (list x y radius)) " draw_dot"))
151 (define (draw-line thick x1 y1 x2 y2)
153 "1 setlinecap 1 setlinejoin "
154 (ly:number->string thick) " setlinewidth "
155 (ly:number->string x1) " "
156 (ly:number->string y1) " moveto "
157 (ly:number->string x2) " "
158 (ly:number->string y2) " lineto stroke"))
160 (define (embedded-ps string)
164 (define (ez-ball ch letter-col ball-col)
167 (ly:numbers->string (list letter-col ball-col))
172 ;; FIXME: use draw_round_box
173 (define (filledbox breapth width depth height)
174 (string-append (ly:numbers->string (list breapth width depth height))
177 (define (glyph-string
181 (format #f "gsave 1 output-scale div 1 output-scale div scale
182 /~a findfont ~a scalefont setfont\n~a grestore" postscript-font-name size
193 (format #f " /~a glyphshow\n" g)
194 (format #f " ~a ~a rmoveto /~a glyphshow\n"
199 (define (grob-cause offset grob)
200 (let* ((cause (ly:grob-property grob 'cause))
201 (music-origin (if (ly:music? cause)
202 (ly:music-property cause 'origin)))
203 (location (if (ly:input-location? music-origin)
204 (ly:input-file-line-column music-origin)
207 (file (if (string? location)
209 (> (string-length location) 0)
210 (eq? (string-ref (car location) 0 ) #\/))
213 (string-append (getcwd) "/" (car location)))
215 (x-ext (ly:grob-extent grob grob X))
216 (y-ext (ly:grob-extent grob grob Y)))
219 (< 0 (interval-length x-ext))
220 (< 0 (interval-length y-ext)))
222 (format "~a ~a ~a ~a (textedit://~a:~a:~a) mark_URI\n"
223 (+ (car offset) (car x-ext))
224 (+ (cdr offset) (car y-ext))
225 (+ (car offset) (cdr x-ext))
226 (+ (cdr offset) (cdr y-ext))
232 ;; WTF is this in every backend?
233 (define (horizontal-line x1 x2 th)
234 (draw-line th x1 0 x2 0))
236 (define (lily-def key val)
237 (let ((prefix "lilypondlayout"))
239 (substring key 0 (min (string-length prefix) (string-length key)))
241 (string-append "/" key " {" val "} bind def\n")
242 (string-append "/" key " (" val ") def\n"))))
244 (define (named-glyph font glyph)
246 (ps-font-command font) " setfont "
247 "/" glyph " glyphshow "))
252 (define (placebox x y s)
254 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
256 (define (polygon points blotdiameter)
258 (ly:numbers->string points) " "
259 (ly:number->string (/ (length points) 2)) " "
260 (ly:number->string blotdiameter)
263 (define (repeat-slash wid slope thick)
265 (ly:numbers->string (list wid slope thick))
266 " draw_repeat_slash"))
268 ;; restore color from stack
270 (string-append "setrgbcolor\n"))
272 (define (round-filled-box x y width height blotdiam)
275 (list x y width height blotdiam)) " draw_round_box"))
277 ;; save current color on stack and set new color
278 (define (setcolor r g b)
279 (string-append "currentrgbcolor "
280 (ly:numbers->string (list r g b))
283 (define (text font s)
284 ;; (ly:warning (_ "TEXT backend-command encountered in Pango backend"))
285 ;; (ly:warning (_ "Arguments: ~a ~a"" font str))
287 (let* ((space-length (cdar (ly:text-dimension font " ")))
288 (space-move (string-append (number->string space-length)
290 (out-vec (decode-byte-string s)))
293 (ps-font-command font) " setfont "
301 (string-append "/" (symbol->string sym) " glyphshow")))
307 (define (url-link url x y)
308 (format "~a ~a ~a ~a (~a) mark_URI"
315 (define (utf8-string pango-font-description string)
316 (ly:warning (_ "utf8-string encountered in PS backend")))
318 (define (white-dot x y radius)
322 (list x y radius)) " draw_white_dot"))
324 (define (white-text scale s)
325 (let ((mystring (string-append
326 "(" s ") " (number->string scale)
328 " draw_white_text")))
332 (define (zigzag-line centre? zzw zzh thick dx dy)
334 (if centre? "true" "false") " "
335 (ly:number->string zzw) " "
336 (ly:number->string zzh) " "
337 (ly:number->string thick) " "
339 (ly:number->string dx) " "
340 (ly:number->string dy)
341 " draw_zigzag_line"))