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)
20 #:export (define-fonts
63 ;;; helper functions, not part of output interface
64 (define (escape-parentheses s)
65 (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
67 (define (offset-add a b)
68 (cons (+ (car a) (car b))
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)
80 (define (ps-number-def prefix key val)
81 (let ((s (if (integer? val)
82 (ly:number->string val)
83 (ly:number->string (exact->inexact val)))))
84 (string-append "/" prefix (symbol->string key) " " s " def\n")))
88 ;;; Lily output interface, PostScript implementation --- cleanup and docme
91 ;;; Output-interface functions
92 (define (beam width slope thick blot)
94 (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
97 (define (bezier-sandwich l thick)
99 (string-join (map ly:number-pair->string l) " ")
101 (ly:number->string thick)
102 " draw_bezier_sandwich"))
104 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
107 (list arch_angle arch_width arch_height height arch_thick thick))
110 (define (char font i)
112 (ps-font-command font) " setfont "
113 "(\\" (ly:inexact->string i 8) ") show" ))
116 (string-append "% " s "\n"))
118 (define (dashed-line thick on off dx dy)
120 (ly:number->string dx) " "
121 (ly:number->string dy) " "
122 (ly:number->string thick)
124 (ly:number->string on) " "
125 (ly:number->string off)
126 " ] 0 draw_dashed_line"))
128 ;; what the heck is this interface ?
129 (define (dashed-slur thick dash l)
131 (string-join (map ly:number-pair->string l) " ")
133 (ly:number->string thick)
135 (ly:number->string dash)
138 (ly:number->string (* 10 thick))
139 " ] 0 draw_dashed_slur"))
141 ; todo: merge with tex-font-command?
143 (define-public (ps-font-command font . override-coding)
144 (let* ((name (ly:font-filename font))
145 (magnify (ly:font-magnification font))
146 (coding-alist (ly:font-encoding-alist font))
147 (input-encoding (assoc-get 'input-name coding-alist))
148 (font-encoding (assoc-get 'output-name coding-alist))
149 (coding-command (if (null? override-coding)
150 (if (equal? input-encoding font-encoding)
152 (car override-coding))))
154 ;; FIXME: now feta stuff has feta* input-encoding (again?)
155 ;;(format (current-error-port) "FONT: ~S, ~S\n" name font-encoding)
156 ;;(format (current-error-port) "INPUT: ~S\n" input-encoding)
157 (if (and coding-command (equal? (substring coding-command 0 4) "feta"))
158 (set! coding-command #f))
161 "magfont" (string-encode-integer (hashq name 1000000))
162 "m" (string-encode-integer (inexact->exact (round (* 1000 magnify))))
163 (if (not coding-command) "" (string-append "e" coding-command)))))
165 (define (define-origin file line col) "")
167 (define (dot x y radius)
171 (list x y radius)) " draw_dot"))
173 (define (draw-line thick x1 y1 x2 y2)
175 "1 setlinecap 1 setlinejoin "
176 (ly:number->string thick) " setlinewidth "
177 (ly:number->string x1) " "
178 (ly:number->string y1) " moveto "
179 (ly:number->string x2) " "
180 (ly:number->string y2) " lineto stroke"))
183 "\nend-lilypond-output\n")
185 (define (ez-ball ch letter-col ball-col)
188 (ly:numbers->string (list letter-col ball-col))
189 " /Helvetica-Bold " ;; ugh
192 (define (filledbox breapth width depth height) ; FIXME : use draw_round_box
193 (string-append (ly:numbers->string (list breapth width depth height))
196 ;; WTF is this in every backend?
197 (define (horizontal-line x1 x2 th)
198 (draw-line th x1 0 x2 0))
200 (define (lily-def key val)
201 (let ((prefix "lilypondpaper"))
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 (no-origin) "")
212 (define (placebox x y s)
214 (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
216 (define (polygon points blotdiameter)
218 (ly:numbers->string points) " "
219 (ly:number->string (/ (length points) 2)) " "
220 (ly:number->string blotdiameter)
223 (define (repeat-slash wid slope thick)
225 (ly:numbers->string (list wid slope thick))
226 " draw_repeat_slash"))
228 (define (round-filled-box x y width height blotdiam)
231 (list x y width height blotdiam)) " draw_round_box"))
234 (define (stem breapth width depth height) ; FIXME: use draw_round_box.
236 (ly:numbers->string (list breapth width depth height))
239 (define (symmetric-x-triangle thick w h)
241 (ly:numbers->string (list h w thick))
242 " draw_symmetric_x_triangle"))
244 (define (text font s)
248 ;; ugh, we should find a better way to
249 ;; extract the hsbw for /space from the font.
251 (space-length (cdar (ly:text-dimension font "t")))
253 (add-command (lambda (x) (set! commands (cons x commands)))) )
257 "Translate space as into moveto, group the rest in words."
258 (if (and (< 0 (string-length word))
259 (equal? #\space chr))
261 (string-append "(" (ps-encoding word) ") show\n")))
263 (if (equal? #\space chr)
264 (add-command (string-append (number->string space-length) " 0.0 rmoveto ")) )
266 (if (equal? #\space chr)
268 (string-append word (make-string 1 chr))))
270 (string-append s " "))
273 (ps-font-command font) " setfont "
274 (string-join (reverse commands)))
280 (define (zigzag-line centre? zzw zzh thick dx dy)
282 (if centre? "true" "false") " "
283 (ly:number->string zzw) " "
284 (ly:number->string zzh) " "
285 (ly:number->string thick) " "
287 (ly:number->string dx) " "
288 (ly:number->string dy)
289 " draw_zigzag_line"))