]> git.donarmstrong.com Git - lilypond.git/blob - scm/pdftex.scm
736cf9bcbfe36b6fdc61fe6bd04e9a23b5221061
[lilypond.git] / scm / pdftex.scm
1 ;;; pdftex.scm -- implement Scheme output routines for PDFTeX
2 ;;;
3 ;;;  source file of the GNU LilyPond music typesetter
4 ;;;  modified from the existing tex.scm
5 ;;; 
6 ;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 ;;; Stephen Peters <portnoy@portnoy.org>
9
10 (define (pdftex-scm action-name)
11   (define (unknown) 
12     "%\n\\unknown%\n")
13
14
15   (define (select-font name-mag-pair)
16     (let*
17         (
18          (c (assoc name-mag-pair font-name-alist))
19          )
20
21       (if (eq? c #f)
22           (begin
23             (display "FAILED\n")
24             (display (object-type (car name-mag-pair)))
25             (display (object-type (caaar font-name-alist)))
26
27             (ly-warn (string-append
28                       "Programming error: No such font known "
29                       (car name-mag-pair) " "
30                       (ly-number->string (cdr name-mag-pair))
31                       ))
32             "") ; issue no command
33           (string-append "\\" (cddr c)))
34       
35       
36       ))
37   
38   (define (beam width slope thick)
39     (embedded-pdf ((pdf-scm 'beam) width slope thick)))
40
41   (define (bracket arch_angle arch_width arch_height height arch_thick thick)
42     (embedded-pdf ((pdf-scm 'bracket) arch_angle arch_width arch_height height arch_thick thick)))
43
44   (define (dashed-slur thick dash l)
45     (embedded-pdf ((pdf-scm 'dashed-slur)  thick dash l)))
46
47   (define (hairpin thick w sh eh)
48     (embedded-pdf ((pdf-scm 'hairpin) thick w sh eh)))
49
50   (define (char i)
51     (string-append "\\char" (inexact->string i 10) " "))
52   
53   (define (dashed-line thick on off dx dy)
54     (embedded-pdf ((pdf-scm 'dashed-line) thick on off dx dy)))
55
56   (define (font-load-command name-mag command)
57     (string-append
58      "\\font\\" command "="
59      (car name-mag)
60      " scaled "
61      (ly-number->string (inexact->exact (* 1000  (cdr name-mag))))
62      "\n"))
63
64   (define (ez-ball c l b)
65     (embedded-pdf ((pdf-scm 'ez-ball) c  l b)))
66
67   (define (embedded-pdf s)
68     (string-append "\\embeddedpdf{ " s "}"))
69
70   (define (comment s)
71     (string-append "% " s))
72   
73   (define (end-output) 
74         (begin
75 ; uncomment for some stats about lily memory      
76 ;               (display (gc-stats))
77     (string-append "\n\\EndLilyPondOutput"
78                    ; Put GC stats here.
79                    )))
80   
81   (define (experimental-on)
82     "")
83
84   (define (repeat-slash w a t)
85     (embedded-pdf ((pdf-scm 'repeat-slash) w a t)))
86   
87   (define (font-switch i)
88     (string-append
89      "\\" (font i) "\n"))
90
91   (define (font-def i s)
92     (string-append
93      "\\font" (font-switch i) "=" s "\n"))
94
95   (define (header-end)
96     (string-append
97      "\\input lilyponddefs\\newdimen\\outputscale \\outputscale=\\lilypondpaperoutputscale pt"
98      "\\turnOnPostScript"
99      "\\pdfcompresslevel=0"))
100
101   ;; Note: this string must match the string in ly2dvi.py!!!
102   (define (header creator generate) 
103     (string-append
104      "% Generated automatically by: " creator generate "\n"))
105
106   (define (invoke-char s i)
107     (string-append 
108      "\n\\" s "{" (inexact->string i 10) "}" ))
109
110   (define (invoke-dim1 s d)
111     (string-append
112      "\n\\" s "{" (number->dim d) "}"))
113   (define (pt->sp x)
114     (* 65536 x))
115   
116   ;;
117   ;; need to do something to make this really safe.
118   ;;
119   (define (output-tex-string s)
120       (if security-paranoia
121           (if use-regex
122               (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
123               (begin (display "warning: not paranoid") (newline) s))
124           s))
125       
126   (define (lily-def key val)
127     (let ((tex-key
128            (if use-regex
129                (regexp-substitute/global 
130                 #f "_" (output-tex-string key) 'pre "X" 'post)      
131                (output-tex-string key)))
132           (tex-val (output-tex-string val)))
133       (if (equal? (sans-surrounding-whitespace tex-val) "")
134           (string-append "\\let\\" tex-key "\\undefined\n")
135           (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
136
137   (define (number->dim x)
138     (string-append
139      ;;ugh ly-* in backend needs compatibility func for standalone output
140      (ly-number->string x) " \\outputscale "))
141
142   (define (placebox x y s) 
143     (string-append 
144      "\\placebox{"
145      (number->dim y) "}{" (number->dim x) "}{" s "}\n"))
146
147   (define (bezier-sandwich l thick)
148     (embedded-pdf ((pdf-scm 'bezier-sandwich) l thick)))
149
150   (define (start-line ht)
151       (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
152
153   (define (stop-line) 
154     "}\\vss}\\interscoreline\n")
155   (define (stop-last-line)
156     "}\\vss}")
157   (define (filledbox breapth width depth height) 
158     (string-append 
159      "\\kern" (number->dim (- breapth))
160      "\\vrule width " (number->dim (+ breapth width))
161      "depth " (number->dim depth)
162      "height " (number->dim height) " "))
163
164   (define (text s)
165     (string-append "\\hbox{" (output-tex-string s) "}"))
166   
167   (define (tuplet ht gapx dx dy thick dir)
168     (embedded-pdf ((pdf-scm 'tuplet) ht gapx dx dy thick dir)))
169
170   (define (volta h w thick vert_start vert_end)
171     (embedded-pdf ((pdf-scm 'volta) h w thick vert_start vert_end)))
172
173   (define (define-origin file line col)
174     (if (procedure? point-and-click)
175         (string-append "\\special{src:\\string:"
176                        (point-and-click line col file)
177                        "}" )
178         "")
179     )
180
181   ; no-origin not supported in PDFTeX
182   (define (no-origin) "")
183
184   ;; The procedures listed below form the public interface of
185   ;; PDFTeX-scm.  (should merge the 2 lists)
186   (cond ((eq? action-name 'all-definitions)
187          `(begin
188             (define font-load-command ,font-load-command)
189             (define beam ,beam)
190             (define bezier-sandwich ,bezier-sandwich)
191             (define bracket ,bracket)
192             (define char ,char)
193             (define dashed-line ,dashed-line) 
194             (define dashed-slur ,dashed-slur) 
195             (define hairpin ,hairpin)
196             (define end-output ,end-output)
197             (define experimental-on ,experimental-on)
198             (define filledbox ,filledbox)
199             (define font-def ,font-def)
200             (define font-switch ,font-switch)
201             (define header-end ,header-end)
202             (define lily-def ,lily-def)
203             (define ez-ball ,ez-ball)
204             (define header ,header) 
205             (define invoke-char ,invoke-char) 
206             (define invoke-dim1 ,invoke-dim1)
207             (define placebox ,placebox)
208             (define select-font ,select-font)
209             (define start-line ,start-line)
210             (define stop-line ,stop-line)
211             (define stop-last-line ,stop-last-line)
212             (define text ,text)
213             (define tuplet ,tuplet)
214             (define volta ,volta)
215             (define define-origin ,define-origin)
216             (define no-origin ,no-origin)
217             (define repeat-slash ,repeat-slash)
218             ))
219
220         ((eq? action-name 'beam) beam)
221         ((eq? action-name 'tuplet) tuplet)
222         ((eq? action-name 'bracket) bracket)
223         ((eq? action-name 'hairpin) hairpin)
224         ((eq? action-name 'dashed-line) dashed-line) 
225         ((eq? action-name 'dashed-slur) dashed-slur) 
226         ((eq? action-name 'end-output) end-output)
227         ((eq? action-name 'experimental-on) experimental-on)
228         ((eq? action-name 'font-def) font-def)
229         ((eq? action-name 'font-switch) font-switch)
230         ((eq? action-name 'header-end) header-end)
231         ((eq? action-name 'lily-def) lily-def)
232         ((eq? action-name 'header) header) 
233         ((eq? action-name 'invoke-char) invoke-char) 
234         ((eq? action-name 'invoke-dim1) invoke-dim1)
235         ((eq? action-name 'placebox) placebox)
236         ((eq? action-name 'bezier-sandwich) bezier-sandwich)
237         ((eq? action-name 'start-line) start-line)
238         ((eq? action-name 'stem) stem)
239         ((eq? action-name 'stop-line) stop-line)
240         ((eq? action-name 'stop-last-line) stop-last-line)
241         ((eq? action-name 'volta) volta)
242         ((eq? action-name 'repeat-slash) repeat-slash)
243         (else (error "unknown tag -- PDFTEX " action-name))
244         )
245   )
246
247 (define (scm-pdftex-output)
248   (primitive-eval (pdftex-scm 'all-definitions)))