]> git.donarmstrong.com Git - lilypond.git/blob - scm/pdftex.scm
release: 1.5.48
[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
11 ;; TODO: port this  to the new module framework.
12
13 (define (pdftex-scm action-name)
14   (define (unknown) 
15     "%\n\\unknown%\n")
16
17
18   (define (select-font name-mag-pair)
19     (let*
20         (
21          (c (assoc name-mag-pair font-name-alist))
22          )
23
24       (if (eq? c #f)
25           (begin
26             (display "FAILED\n")
27             (display (object-type (car name-mag-pair)))
28             (display (object-type (caaar font-name-alist)))
29
30             (ly-warn (string-append
31                       "Programming error: No such font known "
32                       (car name-mag-pair) " "
33                       (ly-number->string (cdr name-mag-pair))
34                       ))
35             "") ; issue no command
36           (string-append "\\" (cddr c)))
37       
38       
39       ))
40   
41   (define (beam width slope thick)
42     (embedded-pdf ((pdf-scm 'beam) width slope thick)))
43
44   (define (bracket arch_angle arch_width arch_height height arch_thick thick)
45     (embedded-pdf ((pdf-scm 'bracket) arch_angle arch_width arch_height height arch_thick thick)))
46
47   (define (dashed-slur thick dash l)
48     (embedded-pdf ((pdf-scm 'dashed-slur)  thick dash l)))
49
50   (define (hairpin thick w sh eh)
51     (embedded-pdf ((pdf-scm 'hairpin) thick w sh eh)))
52
53   (define (char i)
54     (string-append "\\char" (inexact->string i 10) " "))
55   
56   (define (dashed-line thick on off dx dy)
57     (embedded-pdf ((pdf-scm 'dashed-line) thick on off dx dy)))
58
59   (define (font-load-command name-mag command)
60     (string-append
61      "\\font\\" command "="
62      (car name-mag)
63      " scaled "
64      (ly-number->string (inexact->exact (* 1000  (cdr name-mag))))
65      "\n"))
66
67   (define (ez-ball c l b)
68     (embedded-pdf ((pdf-scm 'ez-ball) c  l b)))
69
70   (define (embedded-pdf s)
71     (string-append "\\embeddedpdf{ " s "}"))
72
73   (define (comment s)
74     (string-append "% " s))
75   
76   (define (end-output) 
77         (begin
78 ; uncomment for some stats about lily memory      
79 ;               (display (gc-stats))
80     (string-append "\n\\EndLilyPondOutput"
81                    ; Put GC stats here.
82                    )))
83   
84   (define (experimental-on)
85     "")
86
87   (define (repeat-slash w a t)
88     (embedded-pdf ((pdf-scm 'repeat-slash) w a t)))
89   
90   (define (font-switch i)
91     (string-append
92      "\\" (font i) "\n"))
93
94   (define (font-def i s)
95     (string-append
96      "\\font" (font-switch i) "=" s "\n"))
97
98   (define (header-end)
99     (string-append
100      "\\input lilyponddefs\\newdimen\\outputscale \\outputscale=\\lilypondpaperoutputscale pt"
101      "\\turnOnPostScript"
102      "\\pdfcompresslevel=0"))
103
104   ;; Note: this string must match the string in ly2dvi.py!!!
105   (define (header creator generate) 
106     (string-append
107      "% Generated automatically by: " creator generate "\n"))
108
109   (define (invoke-char s i)
110     (string-append 
111      "\n\\" s "{" (inexact->string i 10) "}" ))
112
113   ;;
114   ;; need to do something to make this really safe.
115   ;;
116   (define (output-tex-string s)
117       (if security-paranoia
118           (if use-regex
119               (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
120               (begin (display "warning: not paranoid") (newline) s))
121           s))
122       
123   (define (lily-def key val)
124     (let ((tex-key
125            (if use-regex
126                (regexp-substitute/global 
127                 #f "_" (output-tex-string key) 'pre "X" 'post)      
128                (output-tex-string key)))
129           (tex-val (output-tex-string val)))
130       (if (equal? (sans-surrounding-whitespace tex-val) "")
131           (string-append "\\let\\" tex-key "\\undefined\n")
132           (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
133
134   (define (number->dim x)
135     (string-append
136      ;;ugh ly-* in backend needs compatibility func for standalone output
137      (ly-number->string x) " \\outputscale "))
138
139   (define (placebox x y s) 
140     (string-append 
141      "\\placebox{"
142      (number->dim y) "}{" (number->dim x) "}{" s "}\n"))
143
144   (define (bezier-sandwich l thick)
145     (embedded-pdf ((pdf-scm 'bezier-sandwich) l thick)))
146
147   (define (start-line ht)
148       (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
149
150   (define (stop-line) 
151     "}\\vss}\\interscoreline\n")
152   (define (stop-last-line)
153     "}\\vss}")
154   (define (filledbox breapth width depth height) 
155     (string-append 
156      "\\kern" (number->dim (- breapth))
157      "\\vrule width " (number->dim (+ breapth width))
158      "depth " (number->dim depth)
159      "height " (number->dim height) " "))
160
161   (define (roundfilledbox x width y height blotdiam)
162     (embedded-pdf ((pdf-scm 'roundfilledbox) x width y height blotdiam)))
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
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
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)))