1 ;;;; output-ps.scm -- implement Scheme output interface for PostScript
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2006 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
50 ;;; helper functions, not part of output interface
51 (define (escape-parentheses s)
52 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
54 (define (ps-encoding text)
55 (escape-parentheses text))
58 (/ (round (* 100 num)) 100))
61 (/ (round (* 10000 num)) 10000))
64 (format #f "~f" (round4 num)))
66 (define (number-pair->string4 numpair)
67 (format #f "~f ~f" (round4 (car numpair)) (round4 (cdr numpair))))
69 (define (numbers->string4 numlist)
70 (string-join (map str4 numlist) " "))
73 (define-public (ps-string-def prefix key val)
74 (format #f "/ ~a~a (~a) def\n"
77 (escape-parentheses val)))
79 (define (ps-number-def prefix key val)
80 (let ((s (if (integer? val)
81 (ly:number->string val)
82 (ly:number->string (exact->inexact val)))))
83 (format #f "/~a~a ~a def\n"
85 (symbol->string key) s)))
89 ;;; Lily output interface, PostScript implementation --- cleanup and docme
93 (define (bezier-sandwich lst thick)
94 (format #f "~a ~a draw_bezier_sandwich"
95 (string-join (map number-pair->string4 lst) " ")
99 (format #f "~a (\\~a) show"
100 (ps-font-command font)
101 (ly:inexact->string i 8)))
103 (define (circle radius thick fill)
105 "~f ~f ~a draw_circle" (round4 radius) (round4 thick)
110 (define (dashed-line thick on off dx dy)
111 (format #f "~a ~a ~a [ ~a ~a ] 0 draw_dashed_line"
118 ;; what the heck is this interface ?
119 (define (dashed-slur thick on off l)
120 (format #f "~a ~a [ ~a ~a ] 0 draw_dashed_slur"
121 (string-join (map number-pair->string4 l) " ")
126 (define (dot x y radius)
127 (format #f " ~a draw_dot"
128 (numbers->string4 (list x y radius))))
130 (define (draw-line thick x1 y1 x2 y2)
131 (format #f "1 setlinecap 1 setlinejoin ~a setlinewidth ~a ~a moveto ~a ~a lineto stroke"
138 (define (embedded-ps string)
141 (define (glyph-string postscript-font-name
146 (format #f "gsave \n/~a ~a output-scale div selectfont\n~a grestore"
158 (prefix (if (string? g) "/" "")))
160 (format #f "~f ~f ~a~a\n" (round2 (+ w x))
164 (format #f "~a print_glyphs" (length w-x-y-named-glyphs)))
167 (define (grob-cause offset grob)
168 (let* ((cause (ly:grob-property grob 'cause))
169 (music-origin (if (ly:music? cause)
170 (ly:music-property cause 'origin))))
171 (if (not (ly:input-location? music-origin))
173 (let* ((location (ly:input-file-line-char-column music-origin))
174 (raw-file (car location))
175 (file (if (is-absolute? raw-file)
177 (string-append (ly-getcwd) "/" raw-file)))
178 (x-ext (ly:grob-extent grob grob X))
179 (y-ext (ly:grob-extent grob grob Y)))
181 (if (and (< 0 (interval-length x-ext))
182 (< 0 (interval-length y-ext)))
183 (format #f "~$ ~$ ~$ ~$ (textedit://~a:~a:~a:~a) mark_URI\n"
184 (+ (car offset) (car x-ext))
185 (+ (cdr offset) (car y-ext))
186 (+ (car offset) (cdr x-ext))
187 (+ (cdr offset) (cdr y-ext))
192 ;; backslash is interpreted by GS.
193 (string-regexp-substitute "\\\\" "/"
194 (string-regexp-substitute " " "%20" file))
200 (define (lily-def key val)
201 (let ((prefix "lilypondlayout"))
203 (substring key 0 (min (string-length prefix) (string-length key)))
205 (string-append "/" key " {" val "} bind def\n")
206 (string-append "/" key " (" val ") def\n"))))
208 (define (named-glyph font glyph)
209 (format #f "~a /~a glyphshow " ;;Why is there a space at the end?
210 (ps-font-command font)
216 (define (placebox x y s)
218 "gsave ~a ~a translate
227 (define (polygon points blot-diameter filled?)
228 (format #f "~a ~a ~a ~a draw_polygon"
229 (numbers->string4 points)
230 (str4 (/ (length points) 2))
232 (if filled? "true" "false")))
234 (define (repeat-slash wid slope thick)
235 (format #f "~a draw_repeat_slash"
236 (numbers->string4 (list wid slope thick))))
238 ;; restore color from stack
239 (define (resetcolor) "setrgbcolor\n")
241 (define (round-filled-box x y width height blotdiam)
242 (format #f "~a draw_round_box"
244 (list x y width height blotdiam))))
246 ;; save current color on stack and set new color
247 (define (setcolor r g b)
248 (format #f "currentrgbcolor ~a setrgbcolor\n"
249 (numbers->string4 (list r g b))))
251 (define (text font s)
252 ;; (ly:warning (_ "TEXT backend-command encountered in Pango backend"))
253 ;; (ly:warning (_ "Arguments: ~a ~a"" font str))
255 (let* ((space-length (cdar (ly:text-dimension font " ")))
256 (space-move (string-append (number->string space-length)
258 (out-vec (decode-byte-string s)))
261 (ps-font-command font) " "
269 (string-append "/" (symbol->string sym) " glyphshow")))
275 (define (url-link url x y)
276 (format #f "~$ ~$ ~$ ~$ (~a) mark_URI"
283 (define (utf-8-string pango-font-description string)
284 (ly:warning (_ "utf-8-string encountered in PS backend")))
287 (define (zigzag-line centre? zzw zzh thick dx dy)
288 (format #f "~a ~a ~a ~a 0 0 ~a ~a draw_zigzag_line"
289 (if centre? "true" "false")