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
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 (x-ext (ly:grob-extent grob grob X))
219 (y-ext (ly:grob-extent grob grob Y))
223 (format "~a ~a ~a ~a (lily-edit.sh ~a ~a ~a) mark_file_line\n"
224 (+ (car offset) (car x-ext))
225 (+ (cdr offset) (car y-ext))
226 (+ (car offset) (cdr x-ext))
227 (+ (cdr offset) (cdr y-ext))
233 ;; WTF is this in every backend?
234 (define (horizontal-line x1 x2 th)
235 (draw-line th x1 0 x2 0))
237 (define (lily-def key val)
238 (let ((prefix "lilypondlayout"))
240 (substring key 0 (min (string-length prefix) (string-length key)))
242 (string-append "/" key " {" val "} bind def\n")
243 (string-append "/" key " (" val ") def\n"))))
245 (define (named-glyph font glyph)
247 (ps-font-command font) " setfont "
248 "/" glyph " glyphshow "))
253 (define (placebox x y s)
255 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
257 (define (polygon points blotdiameter)
259 (ly:numbers->string points) " "
260 (ly:number->string (/ (length points) 2)) " "
261 (ly:number->string blotdiameter)
264 (define (repeat-slash wid slope thick)
266 (ly:numbers->string (list wid slope thick))
267 " draw_repeat_slash"))
269 (define (round-filled-box x y width height blotdiam)
272 (list x y width height blotdiam)) " draw_round_box"))
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)
281 (out-vec (decode-byte-string input-enc s)))
284 (ps-font-command font) " setfont "
292 (string-append "/" (symbol->string sym) " glyphshow")))
295 ;; FIXME: BARF helvetica?
296 (define (white-text scale s)
297 (let ((mystring (string-append
298 "(" s ") " (number->string scale)
300 " draw_white_text")))
304 ;; FIXME: broken with user install of GS 8.x
311 (define (white-dot x y radius)
315 (list x y radius)) " draw_white_dot"))
317 (define (zigzag-line centre? zzw zzh thick dx dy)
319 (if centre? "true" "false") " "
320 (ly:number->string zzw) " "
321 (ly:number->string zzh) " "
322 (ly:number->string thick) " "
324 (ly:number->string dx) " "
325 (ly:number->string dy)
326 " draw_zigzag_line"))