]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-ps.scm
* buildscripts/guile-gnome.sh: Build without gcc libtool version
[lilypond.git] / scm / output-ps.scm
1 ;;;; output-ps.scm -- implement Scheme output interface for PostScript
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c)  1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;;                 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8 ;;;; Note: currently misused as testbed for titles with markup, see
9 ;;;;       input/test/title-markup.ly
10 ;;;; 
11 ;;;; TODO:
12 ;;;;   * %% Papersize in (header ...)
13 ;;;;   * text setting, kerning.
14 ;;;;   * document output-interface
15
16 (debug-enable 'backtrace)
17
18 (define-module (scm output-ps)
19   #:re-export (quote)
20
21   ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
22   #:export (unknown
23              blank
24              dot
25              white-dot
26              beam
27              bracket
28              dashed-slur
29              char
30              dashed-line
31              zigzag-line
32              symmetric-x-triangle
33              ez-ball
34              comment
35              repeat-slash
36              placebox
37              bezier-sandwich
38              horizontal-line
39              filledbox
40              round-filled-box
41              text
42              tuplet
43              polygon
44              draw-line
45              no-origin
46              ))
47
48
49 (use-modules (guile)
50              (ice-9 regex)
51              (srfi srfi-1)
52              (srfi srfi-13)
53              (scm framework-ps)
54              (lily))
55
56
57 ;;(map export
58 ;;   (append (ly:all-stencil-expressions) (ly:all-output-backend-commands)))
59
60 ;; huh?
61 ;;(write (ly:all-output-backend-commands))
62 ;;(write (ly:all-stencil-expressions))
63
64
65 ;;; helper functions, not part of output interface
66 (define (escape-parentheses s)
67   (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
68
69 (define (offset-add a b)
70   (cons (+ (car a) (car b))
71         (+ (cdr a) (cdr b))))
72
73 (define (ps-encoding text)
74   (escape-parentheses text))
75
76 ;; FIXME: lily-def
77 (define-public (ps-string-def prefix key val)
78   (string-append "/" prefix (symbol->string key) " ("
79                  (escape-parentheses val)
80                  ") def\n"))
81
82 (define (ps-number-def prefix key val)
83   (let ((s (if (integer? val)
84                (ly:number->string val)
85                (ly:number->string (exact->inexact val)))))
86     (string-append "/" prefix (symbol->string key) " " s " def\n")))
87
88
89 ;;;
90 ;;; Lily output interface, PostScript implementation --- cleanup and docme
91 ;;;
92
93 ;;; Output-interface functions
94 (define (beam width slope thick blot)
95   (string-append
96    (ly:numbers->string (list slope width thick blot)) " draw_beam" ))
97
98 ;; two beziers
99 (define (bezier-sandwich l thick)
100   (string-append 
101    (string-join (map ly:number-pair->string l) " ")
102    " "
103    (ly:number->string thick)
104    " draw_bezier_sandwich"))
105
106 (define (bracket arch_angle arch_width arch_height  height arch_thick thick)
107   (string-append
108    (ly:numbers->string
109     (list arch_angle arch_width arch_height height arch_thick thick))
110    " draw_bracket"))
111
112 (define (char font i)
113   (string-append 
114     (ps-font-command font) " setfont " 
115    "(\\" (ly:inexact->string i 8) ") show" ))
116
117 (define (dashed-line thick on off dx dy)
118   (string-append 
119    (ly:number->string dx) " "
120    (ly:number->string dy) " "
121    (ly:number->string thick)
122    " [ "
123    (ly:number->string on) " "
124    (ly:number->string off)
125    " ] 0 draw_dashed_line"))
126
127 ;; what the heck is this interface ?
128 (define (dashed-slur thick dash l)
129   (string-append 
130    (string-join (map ly:number-pair->string l) " ")
131    " "
132    (ly:number->string thick) 
133    " [ "
134    (ly:number->string dash)
135    " "
136    ;;UGH.  10 ?
137    (ly:number->string (* 10 thick))
138    " ] 0 draw_dashed_slur"))
139
140 ; todo: merge with tex-font-command?
141
142
143
144 (define (dot x y radius)
145   (string-append
146    " "
147    (ly:numbers->string
148     (list x y radius)) " draw_dot"))
149
150 (define (white-dot x y radius)
151   (string-append
152    " "
153    (ly:numbers->string
154     (list x y radius)) " draw_white_dot"))
155
156 (define (draw-line thick x1 y1 x2 y2)
157   (string-append 
158    "1 setlinecap 1 setlinejoin "
159    (ly:number->string thick) " setlinewidth "
160    (ly:number->string x1) " "
161    (ly:number->string y1) " moveto "
162    (ly:number->string x2) " "
163    (ly:number->string y2) " lineto stroke"))
164
165 (define (ez-ball ch letter-col ball-col)
166   (string-append
167    " (" ch ") "
168    (ly:numbers->string (list letter-col ball-col))
169    " /Helvetica-Bold " ;; ugh
170    " draw_ez_ball"))
171
172 (define (filledbox breapth width depth height) ; FIXME : use draw_round_box
173   (string-append (ly:numbers->string (list breapth width depth height))
174                  " draw_box"))
175
176 ;; WTF is this in every backend?
177 (define (horizontal-line x1 x2 th)
178   (draw-line th x1 0 x2 0))
179
180 (define (lily-def key val)
181   (let ((prefix "lilypondpaper"))
182     (if (string=?
183          (substring key 0 (min (string-length prefix) (string-length key)))
184          prefix)
185         (string-append "/" key " {" val "} bind def\n")
186         (string-append "/" key " (" val ") def\n"))))
187
188
189 (define (placebox x y s) 
190   (string-append 
191    (ly:number->string x) " " (ly:number->string y) " { " s " } place-box\n"))
192
193 (define (polygon points blotdiameter)
194   (string-append
195    (ly:numbers->string points) " "
196    (ly:number->string (/ (length points) 2)) " "
197    (ly:number->string blotdiameter)
198    " draw_polygon"))
199
200 (define (repeat-slash wid slope thick)
201   (string-append
202    (ly:numbers->string (list wid slope thick))
203    " draw_repeat_slash"))
204
205 (define (round-filled-box x y width height blotdiam)
206    (string-append
207     (ly:numbers->string
208      (list x y width height blotdiam)) " draw_round_box"))
209
210
211 (define (stem breapth width depth height) ; FIXME: use draw_round_box.
212   (string-append
213    (ly:numbers->string (list breapth width depth height))
214    " draw_box" ))
215
216 (define (symmetric-x-triangle thick w h)
217   (string-append
218    (ly:numbers->string (list h w thick))
219    " draw_symmetric_x_triangle"))
220
221 (define (text font s)
222   (let*
223       
224       (
225        ;; ugh, we should find a better way to
226        ;; extract the hsbw for /space from the font.
227        
228        (space-length (cdar (ly:text-dimension font "t"))) 
229        (commands '())
230        (add-command (lambda (x) (set! commands (cons x commands)))) )
231
232     (string-fold
233      (lambda (chr word)
234        "Translate space as into moveto, group the rest in words."
235        (if (and (< 0 (string-length word))
236                 (equal? #\space  chr))
237            (add-command 
238             (string-append "(" (ps-encoding word) ") show\n")))
239
240        (if (equal? #\space  chr)
241            (add-command  (string-append (number->string space-length) " 0.0 rmoveto ")) )
242        
243        (if (equal? #\space  chr)
244            ""
245            (string-append word (make-string 1 chr))))
246      ""
247      (string-append  s " "))
248
249     (string-append
250      (ps-font-command font) " setfont "
251      (string-join (reverse commands)))
252     ))
253   
254 (define (unknown) 
255   "\n unknown\n")
256
257 (define (zigzag-line centre? zzw zzh thick dx dy)
258   (string-append
259     (if centre? "true" "false") " "
260     (ly:number->string zzw) " "
261     (ly:number->string zzh) " "
262     (ly:number->string thick) " "
263     "0 0 "
264     (ly:number->string dx) " "
265     (ly:number->string dy)
266     " draw_zigzag_line"))
267
268
269 (define (grob-cause grob)
270   "")
271
272 (define (no-origin)
273   "")