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 (debug-enable 'backtrace)
18 (define-module (scm output-ps)
21 ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
60 ;; (append (ly:all-stencil-expressions) (ly:all-output-backend-commands)))
63 ;;(write (ly:all-output-backend-commands))
64 ;;(write (ly:all-stencil-expressions))
67 ;;; helper functions, not part of output interface
68 (define (escape-parentheses s)
69 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
71 (define (offset-add a b)
72 (cons (+ (car a) (car b))
75 (define (ps-encoding text)
76 (escape-parentheses text))
79 (define-public (ps-string-def prefix key val)
80 (string-append "/" prefix (symbol->string key) " ("
81 (escape-parentheses val)
85 (define (ps-number-def prefix key val)
86 (let ((s (if (integer? val)
87 (ly:number->string val)
88 (ly:number->string (exact->inexact val)))))
89 (string-append "/" prefix (symbol->string key) " " s " def\n")))
93 ;;; Lily output interface, PostScript implementation --- cleanup and docme
96 ;;; Output-interface functions
97 (define (beam width slope thick blot)
99 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
102 (define (bezier-sandwich lst thick)
104 (string-join (map ly:number-pair->string lst) " ")
106 (ly:number->string thick)
107 " draw_bezier_sandwich"))
109 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
112 (list arch_angle arch_width arch_height height arch_thick thick))
115 (define (char font i)
117 (ps-font-command font) " setfont "
118 "(\\" (ly:inexact->string i 8) ") show"))
120 ;; save current color on stack and set new color
121 (define (setcolor r g b)
122 (string-append "currentrgbcolor "
123 (ly:numbers->string (list r g b))
126 ;; restore color from stack
128 (string-append "setrgbcolor\n"))
130 (define (dashed-line thick on off dx dy)
132 (ly:number->string dx) " "
133 (ly:number->string dy) " "
134 (ly:number->string thick)
136 (ly:number->string on) " "
137 (ly:number->string off)
138 " ] 0 draw_dashed_line"))
140 ;; what the heck is this interface ?
141 (define (dashed-slur thick on off l)
143 (string-join (map ly:number-pair->string l) " ")
145 (ly:number->string thick)
147 (ly:number->string on)
149 (ly:number->string off)
150 " ] 0 draw_dashed_slur"))
152 (define (dot x y radius)
156 (list x y radius)) " draw_dot"))
158 (define (draw-line thick x1 y1 x2 y2)
160 "1 setlinecap 1 setlinejoin "
161 (ly:number->string thick) " setlinewidth "
162 (ly:number->string x1) " "
163 (ly:number->string y1) " moveto "
164 (ly:number->string x2) " "
165 (ly:number->string y2) " lineto stroke"))
167 (define (embedded-ps string)
171 (define (ez-ball ch letter-col ball-col)
174 (ly:numbers->string (list letter-col ball-col))
179 ;; FIXME: use draw_round_box
180 (define (filledbox breapth width depth height)
181 (string-append (ly:numbers->string (list breapth width depth height))
185 (define (utf8-string pango-font-description string)
186 (ly:warn "utf8-string encountered in PS backend"))
188 (define (glyph-string
192 (format #f "gsave 1 output-scale div 1 output-scale div scale
193 /~a findfont ~a scalefont setfont\n~a grestore" postscript-font-name size
204 (format #f " /~a glyphshow " g)
205 (format #f " ~a ~a rmoveto /~a glyphshow "
210 (define (grob-cause offset grob)
211 (let* ((cause (ly:grob-property grob 'cause))
212 (music-origin (if (ly:music? cause)
213 (ly:music-property cause 'origin)))
214 (location (if (ly:input-location? music-origin)
215 (ly:input-file-line-column music-origin)
218 (file (if location (string-append (getcwd) "/" (car location))
220 (x-ext (ly:grob-extent grob grob X))
221 (y-ext (ly:grob-extent grob grob Y))
225 (format "~a ~a ~a ~a (textedit://~a:~a:~a) mark_URI\n"
226 (+ (car offset) (car x-ext))
227 (+ (cdr offset) (car y-ext))
228 (+ (car offset) (cdr x-ext))
229 (+ (cdr offset) (cdr y-ext))
235 (define (url-link url x y)
236 (format "~a ~a ~a ~a (~a) mark_URI"
243 ;; WTF is this in every backend?
244 (define (horizontal-line x1 x2 th)
245 (draw-line th x1 0 x2 0))
247 (define (lily-def key val)
248 (let ((prefix "lilypondlayout"))
250 (substring key 0 (min (string-length prefix) (string-length key)))
252 (string-append "/" key " {" val "} bind def\n")
253 (string-append "/" key " (" val ") def\n"))))
255 (define (named-glyph font glyph)
257 (ps-font-command font) " setfont "
258 "/" glyph " glyphshow "))
263 (define (placebox x y s)
265 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
267 (define (polygon points blotdiameter)
269 (ly:numbers->string points) " "
270 (ly:number->string (/ (length points) 2)) " "
271 (ly:number->string blotdiameter)
274 (define (repeat-slash wid slope thick)
276 (ly:numbers->string (list wid slope thick))
277 " draw_repeat_slash"))
279 (define (round-filled-box x y width height blotdiam)
282 (list x y width height blotdiam)) " draw_round_box"))
284 (define (text font s)
285 ; (ly:warn "TEXT backend-command encountered in Pango backend\nargs: ~a ~a" font str)
287 (let* ((space-length (cdar (ly:text-dimension font " ")))
288 (space-move (string-append (number->string space-length)
291 (out-vec (decode-byte-string input-enc s)))
294 (ps-font-command font) " setfont "
302 (string-append "/" (symbol->string sym) " glyphshow")))
305 ;; FIXME: BARF helvetica?
306 (define (white-text scale s)
307 (let ((mystring (string-append
308 "(" s ") " (number->string scale)
310 " draw_white_text")))
314 ;; FIXME: broken with user install of GS 8.x
321 (define (white-dot x y radius)
325 (list x y radius)) " draw_white_dot"))
327 (define (zigzag-line centre? zzw zzh thick dx dy)
329 (if centre? "true" "false") " "
330 (ly:number->string zzw) " "
331 (ly:number->string zzh) " "
332 (ly:number->string thick) " "
334 (ly:number->string dx) " "
335 (ly:number->string dy)
336 " draw_zigzag_line"))