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)
53 ;;; helper functions, not part of output interface
54 (define (escape-parentheses s)
55 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
57 (define (offset-add a b)
58 (cons (+ (car a) (car b))
61 (define (ps-encoding text)
62 (escape-parentheses text))
65 (define-public (ps-string-def prefix key val)
66 (string-append "/" prefix (symbol->string key) " ("
67 (escape-parentheses val)
70 (define (ps-number-def prefix key val)
71 (let ((s (if (integer? val)
72 (ly:number->string val)
73 (ly:number->string (exact->inexact val)))))
74 (string-append "/" prefix (symbol->string key) " " s " def\n")))
78 ;;; Lily output interface, PostScript implementation --- cleanup and docme
81 ;;; Output-interface functions
82 (define (beam width slope thick blot)
84 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
87 (define (bezier-sandwich l thick)
89 (string-join (map ly:number-pair->string l) " ")
91 (ly:number->string thick)
92 " draw_bezier_sandwich"))
94 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
97 (list arch_angle arch_width arch_height height arch_thick thick))
100 (define (char font i)
102 (ps-font-command font) " setfont "
103 "(\\" (ly:inexact->string i 8) ") show" ))
105 (define (dashed-line thick on off dx dy)
107 (ly:number->string dx) " "
108 (ly:number->string dy) " "
109 (ly:number->string thick)
111 (ly:number->string on) " "
112 (ly:number->string off)
113 " ] 0 draw_dashed_line"))
115 ;; what the heck is this interface ?
116 (define (dashed-slur thick dash l)
118 (string-join (map ly:number-pair->string l) " ")
120 (ly:number->string thick)
122 (ly:number->string dash)
125 (ly:number->string (* 10 thick))
126 " ] 0 draw_dashed_slur"))
128 ; todo: merge with tex-font-command?
132 (define (define-origin file line col) "")
134 (define (dot x y radius)
138 (list x y radius)) " draw_dot"))
140 (define (draw-line thick x1 y1 x2 y2)
142 "1 setlinecap 1 setlinejoin "
143 (ly:number->string thick) " setlinewidth "
144 (ly:number->string x1) " "
145 (ly:number->string y1) " moveto "
146 (ly:number->string x2) " "
147 (ly:number->string y2) " lineto stroke"))
149 (define (ez-ball ch letter-col ball-col)
152 (ly:numbers->string (list letter-col ball-col))
153 " /Helvetica-Bold " ;; ugh
156 (define (filledbox breapth width depth height) ; FIXME : use draw_round_box
157 (string-append (ly:numbers->string (list breapth width depth height))
160 ;; WTF is this in every backend?
161 (define (horizontal-line x1 x2 th)
162 (draw-line th x1 0 x2 0))
164 (define (lily-def key val)
165 (let ((prefix "lilypondpaper"))
167 (substring key 0 (min (string-length prefix) (string-length key)))
169 (string-append "/" key " {" val "} bind def\n")
170 (string-append "/" key " (" val ") def\n"))))
172 (define (no-origin) "")
176 (define (placebox x y s)
178 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
180 (define (polygon points blotdiameter)
182 (ly:numbers->string points) " "
183 (ly:number->string (/ (length points) 2)) " "
184 (ly:number->string blotdiameter)
187 (define (repeat-slash wid slope thick)
189 (ly:numbers->string (list wid slope thick))
190 " draw_repeat_slash"))
192 (define (round-filled-box x y width height blotdiam)
195 (list x y width height blotdiam)) " draw_round_box"))
198 (define (stem breapth width depth height) ; FIXME: use draw_round_box.
200 (ly:numbers->string (list breapth width depth height))
203 (define (symmetric-x-triangle thick w h)
205 (ly:numbers->string (list h w thick))
206 " draw_symmetric_x_triangle"))
208 (define (text font s)
212 ;; ugh, we should find a better way to
213 ;; extract the hsbw for /space from the font.
215 (space-length (cdar (ly:text-dimension font "t")))
217 (add-command (lambda (x) (set! commands (cons x commands)))) )
221 "Translate space as into moveto, group the rest in words."
222 (if (and (< 0 (string-length word))
223 (equal? #\space chr))
225 (string-append "(" (ps-encoding word) ") show\n")))
227 (if (equal? #\space chr)
228 (add-command (string-append (number->string space-length) " 0.0 rmoveto ")) )
230 (if (equal? #\space chr)
232 (string-append word (make-string 1 chr))))
234 (string-append s " "))
237 (ps-font-command font) " setfont "
238 (string-join (reverse commands)))
244 (define (zigzag-line centre? zzw zzh thick dx dy)
246 (if centre? "true" "false") " "
247 (ly:number->string zzw) " "
248 (ly:number->string zzh) " "
249 (ly:number->string thick) " "
251 (ly:number->string dx) " "
252 (ly:number->string dy)
253 " draw_zigzag_line"))