]> git.donarmstrong.com Git - lilypond.git/blob - scm/ps.scm
''
[lilypond.git] / scm / ps.scm
1 ;;; ps.scm -- implement Scheme output routines for PostScript
2 ;;;
3 ;;;  source file of the GNU LilyPond music typesetter
4 ;;; 
5 ;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8
9
10 (define-module (scm ps)
11   )
12
13 (define this-module (current-module))
14
15 (debug-enable 'backtrace)
16
17 (if (or (equal? (minor-version) "4")
18         (equal? (minor-version) "3.4"))
19     (define-public (ps-output-expression expr port)
20       (display (eval-in-module expr this-module) port))
21
22     (define-public (ps-output-expression expr port)
23       (display (eval expr this-module) port)))
24
25  
26 (use-modules
27  (guile)
28 )
29
30
31
32 ;;;;;;;;
33 ;;;;;;;; DOCUMENT ME!
34 ;;;;;;;; 
35 (define (tex-encoded-fontswitch name-mag)
36   (let* ((iname-mag (car name-mag))
37          (ename-mag (cdr name-mag)))
38     (cons iname-mag
39           (cons ename-mag
40                 (string-append  "magfont"
41                           (string-encode-integer
42                            (hashq (car ename-mag) 1000000))
43                           "m"
44                           (string-encode-integer
45                            (inexact->exact (* 1000 (cdr ename-mag)))))))))
46
47 (define (fontify name-mag-pair exp)
48   (string-append (select-font name-mag-pair)
49                  exp))
50
51
52 (define (define-fonts internal-external-name-mag-pairs)
53   (set! font-name-alist (map tex-encoded-fontswitch
54                              internal-external-name-mag-pairs))
55   (apply string-append
56          (map (lambda (x)
57                 (font-load-command (car x) (cdr x)))
58               (map cdr font-name-alist))))
59
60
61
62 ;; alist containing fontname -> fontcommand assoc (both strings)
63 (define font-alist '())
64 (define font-count 0)
65 (define current-font "")
66
67 (define (select-font name-mag-pair)
68   (let*
69       (
70        (c (assoc name-mag-pair font-name-alist))
71        )
72
73     (if (eq? c #f)
74         (begin
75           (display "FAILED\n")
76           (display (object-type (car name-mag-pair)))
77           (display (object-type (caaar font-name-alist)))
78
79           (ly-warn (string-append
80                     "Programming error: No such font known "
81                     (car name-mag-pair) " "
82                     (ly-number->string (cdr name-mag-pair))
83                     ))
84           
85           "") ; issue no command          
86         (string-append " " (cddr c) " "))
87     ))
88
89 (define (font-load-command name-mag command)
90   (string-append
91    "/" command
92    " { /"
93    (capitalize-font-name (car name-mag))
94    " findfont "
95    "20 " (ly-number->string (cdr name-mag)) " mul "
96    "output-scale div scalefont setfont } bind def "
97    "\n"))
98
99 ;; Ugh, the Bluesky type1 fonts for computer modern use capitalized 
100 ;; postscript font names.
101 (define (capitalize-font-name name)
102   (if (equal? (substring name 0 2) "cm")
103       (string-upcase name)
104       name))
105
106 (define (beam width slope thick)
107   (string-append
108    (numbers->string (list slope width thick)) " draw_beam" ))
109
110 (define (comment s)
111   (string-append "% " s "\n"))
112
113 (define (bracket arch_angle arch_width arch_height  height arch_thick thick)
114   (string-append
115    (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
116
117 (define (char i)
118   (invoke-char " show" i))
119
120
121 (define (hairpin thick width starth endh )
122   (string-append 
123    (numbers->string (list width starth endh thick))
124    " draw_hairpin"))
125
126 ;; what the heck is this interface ?
127 (define (dashed-slur thick dash l)
128   (string-append 
129    (apply string-append (map control->string l)) 
130    (ly-number->string thick) 
131    " [ "
132    (ly-number->string dash)
133    " "
134    (ly-number->string (* 10 thick))     ;UGH.  10 ?
135    " ] 0 draw_dashed_slur"))
136
137 (define (dashed-line thick on off dx dy)
138   (string-append 
139    (ly-number->string dx)
140    " "
141    (ly-number->string dy)
142    " "
143    (ly-number->string thick)
144    " [ "
145    (ly-number->string on)
146    " "
147    (ly-number->string off)
148    " ] 0 draw_dashed_line"))
149
150 (define (draw-line thick x1 y1 x2 y2)
151
152   (string-append 
153   "     1 setlinecap
154         1 setlinejoin "
155   (ly-number->string thick)
156         " setlinewidth "
157    (ly-number->string x1)
158    " "
159    (ly-number->string y1)
160    " moveto"
161    (ly-number->string x2)
162    " "
163    (ly-number->string y2)
164    " lineto stroke"
165
166   ))
167
168 (define (repeat-slash wid slope thick)
169   (string-append (numbers->string (list wid slope thick))
170                  " draw_repeat_slash"))
171
172 (define (end-output)
173   "\nend-lilypond-output\n")
174
175 (define (experimental-on) "")
176
177 (define (filledbox breapth width depth height) 
178   (string-append (numbers->string (list breapth width depth height))
179                  " draw_box" ))
180
181 (define (roundfilledbox x width y height blotdiam)
182    (string-append " "
183       (numbers->string
184          (list x width y height blotdiam)) " draw_round_box"))
185
186 (define (dot x y radius)
187     (string-append " "
188      (numbers->string
189       (list x y radius)) " draw_dot"))
190
191 ;; obsolete?
192 (define (font-def i s)
193   (string-append
194    "\n/" (font i) " {/" 
195    (substring s 0 (- (string-length s) 4))
196    " findfont 12 scalefont setfont} bind def \n"))
197
198 (define (font-switch i)
199   (string-append (font i) " "))
200
201 (define (header-end)
202   (string-append
203    ;; URG: now we can't use scm output without Lily
204    (ly-gulp-file "lilyponddefs.ps")
205    " {exch pop //systemdict /run get exec} "
206    (ly-gulp-file "music-drawing-routines.ps")
207    "{ exch pop //systemdict /run get exec } "
208 ;; ps-testing is broken: global module
209    (if (defined? 'ps-testing) "\n /testing true def" "")
210 ;;   "\n /testing true def"
211    ))
212
213 (define (lily-def key val)
214
215   (if (string=? (substring key 0 (min (string-length "lilypondpaper") (string-length key))) "lilypondpaper")
216       (string-append "/" key " {" val "} bind def\n")
217       (string-append "/" key " (" val ") def\n")
218       )
219   )
220
221 (define (header creator generate) 
222   (string-append
223    "%!PS-Adobe-3.0\n"
224    "%%Creator: " creator generate "\n"))
225
226 (define (invoke-char s i)
227   (string-append 
228    "(\\" (inexact->string i 8) ") " s " " ))
229
230
231 (define (placebox x y s) 
232   (string-append 
233    (ly-number->string x) " " (ly-number->string y) " {" s "} place-box\n"))
234
235 (define (bezier-sandwich l thick)
236   (string-append 
237    (apply string-append (map control->string l))
238    (ly-number->string thick)
239    " draw_bezier_sandwich "
240    (bezier-ending (list-ref l 3) (list-ref l 0) (list-ref l 5))
241    (bezier-ending (list-ref l 7) (list-ref l 0) (list-ref l 5))))
242
243 (define (bezier-ending z0 z1 z2)
244   (let ((x0 (car z0))
245         (y0 (cdr z0))
246         (x1 (car z1))
247         (y1 (cdr z1))
248         (x2 (car z2))
249         (y2 (cdr z2)))
250     (string-append " "
251      (numbers->string
252       (list x0 y0
253             (/ (sqrt (+ (* (- x1 x2) (- x1 x2)) (* (- y1 y2) (- y1 y2)))) 2)))
254      " draw_dot")))
255
256                                         ; TODO: use HEIGHT argument
257
258   (define (start-system height)
259   (string-append
260    "\n"
261    (ly-number->string height)
262    " start-system {
263 set-ps-scale-to-lily-scale
264
265 "))
266
267 (define (stem breapth width depth height) 
268   (string-append (numbers->string (list breapth width depth height))
269                  " draw_box" ))
270
271 (define (stop-system)
272   "}\nstop-system\n")
273
274 (define (stop-last-system)
275   "}\nstop-system\n")
276
277 (define (text s)
278   (string-append "(" s ") show  "))
279
280
281 (define (volta h w thick vert_start vert_end)
282   (string-append 
283    (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
284    " draw_volta"))
285
286 (define (tuplet ht gap dx dy thick dir)
287   (string-append 
288    (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
289    " draw_tuplet"))
290
291
292 (define (unknown) 
293   "\n unknown\n")
294
295 (define (ez-ball ch letter-col ball-col)
296   (string-append
297    " (" ch ") "
298    (numbers->string (list letter-col ball-col))
299    " /Helvetica-Bold " ;; ugh
300    " draw_ez_ball"))
301
302 (define (define-origin a b c ) "")
303 (define (no-origin) "")
304   
305