1 ;;;; output-ps.scm -- implement Scheme output interface for PostScript
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2004 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
58 ;; (append (ly:all-stencil-expressions) (ly:all-output-backend-commands)))
61 ;;(write (ly:all-output-backend-commands))
62 ;;(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 (offset-add a b)
70 (cons (+ (car a) (car b))
73 (define (ps-encoding text)
74 (escape-parentheses text))
77 (define-public (ps-string-def prefix key val)
78 (string-append "/" prefix (symbol->string key) " ("
79 (escape-parentheses val)
83 (define (ps-number-def prefix key val)
84 (let ((s (if (integer? val)
85 (ly:number->string val)
86 (ly:number->string (exact->inexact val)))))
87 (string-append "/" prefix (symbol->string key) " " s " def\n")))
91 ;;; Lily output interface, PostScript implementation --- cleanup and docme
94 ;;; Output-interface functions
95 (define (beam width slope thick blot)
97 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
100 (define (bezier-sandwich lst thick)
102 (string-join (map ly:number-pair->string lst) " ")
104 (ly:number->string thick)
105 " draw_bezier_sandwich"))
107 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
110 (list arch_angle arch_width arch_height height arch_thick thick))
113 (define (char font i)
115 (ps-font-command font) " setfont "
116 "(\\" (ly:inexact->string i 8) ") show"))
118 (define (dashed-line thick on off dx dy)
120 (ly:number->string dx) " "
121 (ly:number->string dy) " "
122 (ly:number->string thick)
124 (ly:number->string on) " "
125 (ly:number->string off)
126 " ] 0 draw_dashed_line"))
128 ;; what the heck is this interface ?
129 (define (dashed-slur thick dash lst)
131 (string-join (map ly:number-pair->string lst) " ")
133 (ly:number->string thick)
135 (ly:number->string dash)
138 (ly:number->string (* 10 thick))
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))
170 ;; FIXME: use draw_round_box
171 (define (filledbox breapth width depth height)
172 (string-append (ly:numbers->string (list breapth width depth height))
176 (define (utf8-string pango-font-description string)
177 (ly:warn "utf8-string encountered in PS backend"))
179 (define (glyph-string
183 (format #f "gsave 1 output-scale div 1 output-scale div scale
184 /~a findfont ~a scalefont setfont\n~a grestore" postscript-font-name size
195 (format #f " /~a glyphshow " g)
196 (format #f " ~a ~a rmoveto /~a glyphshow "
201 (define (grob-cause grob)
204 ;; WTF is this in every backend?
205 (define (horizontal-line x1 x2 th)
206 (draw-line th x1 0 x2 0))
208 (define (lily-def key val)
209 (let ((prefix "lilypondlayout"))
211 (substring key 0 (min (string-length prefix) (string-length key)))
213 (string-append "/" key " {" val "} bind def\n")
214 (string-append "/" key " (" val ") def\n"))))
216 (define (named-glyph font glyph)
218 (ps-font-command font) " setfont "
219 "/" glyph " glyphshow "))
224 (define (placebox x y s)
226 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
228 (define (polygon points blotdiameter)
230 (ly:numbers->string points) " "
231 (ly:number->string (/ (length points) 2)) " "
232 (ly:number->string blotdiameter)
235 (define (repeat-slash wid slope thick)
237 (ly:numbers->string (list wid slope thick))
238 " draw_repeat_slash"))
240 (define (round-filled-box x y width height blotdiam)
243 (list x y width height blotdiam)) " draw_round_box"))
245 (define (text font s)
246 ; (ly:warn "TEXT backend-command encountered in Pango backend\nargs: ~a ~a" font str)
248 (let* ((space-length (cdar (ly:text-dimension font " ")))
249 (space-move (string-append (number->string space-length)
252 (out-vec (decode-byte-string input-enc s)))
255 (ps-font-command font) " setfont "
263 (string-append "/" (symbol->string sym) " glyphshow")))
266 ;; FIXME: BARF helvetica?
267 (define (white-text scale s)
268 (let ((mystring (string-append
269 "(" s ") " (number->string scale)
271 " draw_white_text")))
275 ;; FIXME: broken with user install of GS 8.x
282 (define (white-dot x y radius)
286 (list x y radius)) " draw_white_dot"))
288 (define (zigzag-line centre? zzw zzh thick dx dy)
290 (if centre? "true" "false") " "
291 (ly:number->string zzw) " "
292 (ly:number->string zzh) " "
293 (ly:number->string thick) " "
295 (ly:number->string dx) " "
296 (ly:number->string dy)
297 " draw_zigzag_line"))