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)
57 ;; (append (ly:all-stencil-expressions) (ly:all-output-backend-commands)))
60 ;;(write (ly:all-output-backend-commands))
61 ;;(write (ly:all-stencil-expressions))
64 ;;; helper functions, not part of output interface
65 (define (escape-parentheses s)
66 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
68 (define (offset-add a b)
69 (cons (+ (car a) (car b))
72 (define (ps-encoding text)
73 (escape-parentheses text))
76 (define-public (ps-string-def prefix key val)
77 (string-append "/" prefix (symbol->string key) " ("
78 (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 l thick)
100 (string-join (map ly:number-pair->string l) " ")
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 (define (dashed-line thick on off dx dy)
118 (ly:number->string dx) " "
119 (ly:number->string dy) " "
120 (ly:number->string thick)
122 (ly:number->string on) " "
123 (ly:number->string off)
124 " ] 0 draw_dashed_line"))
126 ;; what the heck is this interface ?
127 (define (dashed-slur thick dash l)
129 (string-join (map ly:number-pair->string l) " ")
131 (ly:number->string thick)
133 (ly:number->string dash)
136 (ly:number->string (* 10 thick))
137 " ] 0 draw_dashed_slur"))
139 ; todo: merge with tex-font-command?
143 (define (dot x y radius)
147 (list x y radius)) " draw_dot"))
149 (define (white-dot x y radius)
153 (list x y radius)) " draw_white_dot"))
155 (define (draw-line thick x1 y1 x2 y2)
157 "1 setlinecap 1 setlinejoin "
158 (ly:number->string thick) " setlinewidth "
159 (ly:number->string x1) " "
160 (ly:number->string y1) " moveto "
161 (ly:number->string x2) " "
162 (ly:number->string y2) " lineto stroke"))
164 (define (ez-ball ch letter-col ball-col)
167 (ly:numbers->string (list letter-col ball-col))
168 " /Helvetica-Bold " ;; ugh
171 (define (filledbox breapth width depth height) ; FIXME : use draw_round_box
172 (string-append (ly:numbers->string (list breapth width depth height))
175 ;; WTF is this in every backend?
176 (define (horizontal-line x1 x2 th)
177 (draw-line th x1 0 x2 0))
179 (define (lily-def key val)
180 (let ((prefix "lilypondpaper"))
182 (substring key 0 (min (string-length prefix) (string-length key)))
184 (string-append "/" key " {" val "} bind def\n")
185 (string-append "/" key " (" val ") def\n"))))
188 (define (placebox x y s)
190 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
192 (define (polygon points blotdiameter)
194 (ly:numbers->string points) " "
195 (ly:number->string (/ (length points) 2)) " "
196 (ly:number->string blotdiameter)
199 (define (repeat-slash wid slope thick)
201 (ly:numbers->string (list wid slope thick))
202 " draw_repeat_slash"))
204 (define (round-filled-box x y width height blotdiam)
207 (list x y width height blotdiam)) " draw_round_box"))
210 (define (stem breapth width depth height) ; FIXME: use draw_round_box.
212 (ly:numbers->string (list breapth width depth height))
215 (define (symmetric-x-triangle thick w h)
217 (ly:numbers->string (list h w thick))
218 " draw_symmetric_x_triangle"))
220 (define (text font s)
224 ;; ugh, we should find a better way to
225 ;; extract the hsbw for /space from the font.
227 (space-length (cdar (ly:text-dimension font "t")))
229 (add-command (lambda (x) (set! commands (cons x commands)))) )
233 "Translate space as into moveto, group the rest in words."
234 (if (and (< 0 (string-length word))
235 (equal? #\space chr))
237 (string-append "(" (ps-encoding word) ") show\n")))
239 (if (equal? #\space chr)
240 (add-command (string-append (number->string space-length) " 0.0 rmoveto ")) )
242 (if (equal? #\space chr)
244 (string-append word (make-string 1 chr))))
246 (string-append s " "))
249 (ps-font-command font) " setfont "
250 (string-join (reverse commands)))
256 (define (zigzag-line centre? zzw zzh thick dx dy)
258 (if centre? "true" "false") " "
259 (ly:number->string zzw) " "
260 (ly:number->string zzh) " "
261 (ly:number->string thick) " "
263 (ly:number->string dx) " "
264 (ly:number->string dy)
265 " draw_zigzag_line"))
268 (define (grob-cause grob)