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 (ps-encoding text)
72 (escape-parentheses text))
75 (define-public (ps-string-def prefix key val)
76 (string-append "/" prefix (symbol->string key) " ("
77 (escape-parentheses val)
81 (define (ps-number-def prefix key val)
82 (let ((s (if (integer? val)
83 (ly:number->string val)
84 (ly:number->string (exact->inexact val)))))
85 (string-append "/" prefix (symbol->string key) " " s " def\n")))
89 ;;; Lily output interface, PostScript implementation --- cleanup and docme
92 ;;; Output-interface functions
93 (define (beam width slope thick blot)
95 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
98 (define (bezier-sandwich lst thick)
100 (string-join (map ly:number-pair->string lst) " ")
102 (ly:number->string thick)
103 " draw_bezier_sandwich"))
105 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
108 (list arch_angle arch_width arch_height height arch_thick thick))
111 (define (char font i)
113 (ps-font-command font) " setfont "
114 "(\\" (ly:inexact->string i 8) ") show"))
116 ;; save current color on stack and set new color
117 (define (setcolor r g b)
118 (string-append "currentrgbcolor "
119 (ly:numbers->string (list r g b))
122 ;; restore color from stack
124 (string-append "setrgbcolor\n"))
126 (define (dashed-line thick on off dx dy)
128 (ly:number->string dx) " "
129 (ly:number->string dy) " "
130 (ly:number->string thick)
132 (ly:number->string on) " "
133 (ly:number->string off)
134 " ] 0 draw_dashed_line"))
136 ;; what the heck is this interface ?
137 (define (dashed-slur thick on off l)
139 (string-join (map ly:number-pair->string l) " ")
141 (ly:number->string thick)
143 (ly:number->string on)
145 (ly:number->string off)
146 " ] 0 draw_dashed_slur"))
148 (define (dot x y radius)
152 (list x y radius)) " draw_dot"))
154 (define (draw-line thick x1 y1 x2 y2)
156 "1 setlinecap 1 setlinejoin "
157 (ly:number->string thick) " setlinewidth "
158 (ly:number->string x1) " "
159 (ly:number->string y1) " moveto "
160 (ly:number->string x2) " "
161 (ly:number->string y2) " lineto stroke"))
163 (define (embedded-ps string)
167 (define (ez-ball ch letter-col ball-col)
170 (ly:numbers->string (list letter-col ball-col))
175 ;; FIXME: use draw_round_box
176 (define (filledbox breapth width depth height)
177 (string-append (ly:numbers->string (list breapth width depth height))
181 (define (utf8-string pango-font-description string)
182 (ly:warn "utf8-string encountered in PS backend"))
184 (define (glyph-string
188 (format #f "gsave 1 output-scale div 1 output-scale div scale
189 /~a findfont ~a scalefont setfont\n~a grestore" postscript-font-name size
200 (format #f " /~a glyphshow " g)
201 (format #f " ~a ~a rmoveto /~a glyphshow "
206 (define (grob-cause offset grob)
207 (let* ((cause (ly:grob-property grob 'cause))
208 (music-origin (if (ly:music? cause)
209 (ly:music-property cause 'origin)))
210 (location (if (ly:input-location? music-origin)
211 (ly:input-file-line-column music-origin)
214 (file (if location (string-append (getcwd) "/" (car location))
216 (x-ext (ly:grob-extent grob grob X))
217 (y-ext (ly:grob-extent grob grob Y))
221 (< 0 (interval-length x-ext))
222 (< 0 (interval-length y-ext)))
224 (format "~a ~a ~a ~a (textedit://~a:~a:~a) mark_URI\n"
225 (+ (car offset) (car x-ext))
226 (+ (cdr offset) (car y-ext))
227 (+ (car offset) (cdr x-ext))
228 (+ (cdr offset) (cdr y-ext))
234 ;; WTF is this in every backend?
235 (define (horizontal-line x1 x2 th)
236 (draw-line th x1 0 x2 0))
238 (define (lily-def key val)
239 (let ((prefix "lilypondlayout"))
241 (substring key 0 (min (string-length prefix) (string-length key)))
243 (string-append "/" key " {" val "} bind def\n")
244 (string-append "/" key " (" val ") def\n"))))
246 (define (named-glyph font glyph)
248 (ps-font-command font) " setfont "
249 "/" glyph " glyphshow "))
254 (define (placebox x y s)
256 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
258 (define (polygon points blotdiameter)
260 (ly:numbers->string points) " "
261 (ly:number->string (/ (length points) 2)) " "
262 (ly:number->string blotdiameter)
265 (define (repeat-slash wid slope thick)
267 (ly:numbers->string (list wid slope thick))
268 " draw_repeat_slash"))
270 (define (round-filled-box x y width height blotdiam)
273 (list x y width height blotdiam)) " draw_round_box"))
275 (define (text font s)
276 ; (ly:warn "TEXT backend-command encountered in Pango backend\nargs: ~a ~a" font str)
278 (let* ((space-length (cdar (ly:text-dimension font " ")))
279 (space-move (string-append (number->string space-length)
282 (out-vec (decode-byte-string input-enc s)))
285 (ps-font-command font) " setfont "
293 (string-append "/" (symbol->string sym) " glyphshow")))
299 (define (url-link url x y)
300 (format "~a ~a ~a ~a (~a) mark_URI"
307 (define (white-dot x y radius)
311 (list x y radius)) " draw_white_dot"))
313 (define (white-text scale s)
314 (let ((mystring (string-append
315 "(" s ") " (number->string scale)
317 " draw_white_text")))
321 (define (zigzag-line centre? zzw zzh thick dx dy)
323 (if centre? "true" "false") " "
324 (ly:number->string zzw) " "
325 (ly:number->string zzh) " "
326 (ly:number->string thick) " "
328 (ly:number->string dx) " "
329 (ly:number->string dy)
330 " draw_zigzag_line"))