1 ;;; pdftex.scm -- implement Scheme output routines for PDFTeX
3 ;;; source file of the GNU LilyPond music typesetter
4 ;;; modified from the existing tex.scm
6 ;;; (c) 1998--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 ;;; Stephen Peters <portnoy@portnoy.org>
11 ;; TODO: port this to the new module framework.
13 (define-module (scm output-pdftex))
15 (use-modules (scm output-pdf)
21 (define font-name-alist '())
23 (define this-module (current-module))
28 (define (select-font name-mag-pair)
31 (c (assoc name-mag-pair font-name-alist))
37 (display (object-type (car name-mag-pair)))
38 (display (object-type (caaar font-name-alist)))
40 (ly:warn (string-append
41 "Programming error: No such font known "
42 (car name-mag-pair) " "
43 (ly:number->string (cdr name-mag-pair))
45 "") ; issue no command
46 (string-append "\\" (cddr c)))
51 (define (beam width slope thick)
52 (embedded-pdf (list 'beam width slope thick)))
54 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
55 (embedded-pdf (list 'bracket arch_angle arch_width arch_height height arch_thick thick)))
57 (define (dashed-slur thick dash l)
58 (embedded-pdf (list 'dashed-slur thick dash l)))
61 (string-append "\\char" (inexact->string i 10) " "))
63 (define (dashed-line thick on off dx dy)
64 (embedded-pdf (list 'dashed-line thick on off dx dy)))
66 (define (font-load-command name-mag command)
68 "\\font\\" command "="
71 (ly:number->string (inexact->exact (* 1000 (cdr name-mag))))
74 (define (ez-ball c l b)
75 (embedded-pdf (list 'ez-ball c l b)))
77 (define (header-to-file fn key val)
78 (set! key (symbol->string key))
79 (if (not (equal? "-" fn))
80 (set! fn (string-append fn "." key))
83 (format "writing header field `~a' to `~a'..."
85 (if (equal? "-" fn) "<stdout>" fn)
90 (display val (open-file fn "w"))
92 (display "\n" (current-error-port))
96 (define (embedded-pdf expr)
98 ((os (open-output-string)))
99 (pdf-output-expression expr os)
100 (string-append "\\embeddedpdf{" (get-output-string os) "}")))
104 (simple-format #f "% ~a\n" s))
108 ; uncomment for some stats about lily memory
109 ; (display (gc-stats))
110 (string-append "%\n\\lilypondend\n"
114 (define (experimental-on)
117 (define (repeat-slash w a t)
118 (embedded-pdf (list 'repeat-slash w a t)))
119 (define (fontify name-mag-pair exp)
120 (string-append (select-font name-mag-pair)
124 (define (tex-encoded-fontswitch name-mag)
125 (let* ((iname-mag (car name-mag))
126 (ename-mag (cdr name-mag)))
129 (string-append "magfont"
130 (string-encode-integer
131 (hashq (car ename-mag) 1000000))
133 (string-encode-integer
134 (inexact->exact (* 1000 (cdr ename-mag)))))))))
135 (define (define-fonts internal-external-name-mag-pairs)
136 (set! font-name-alist (map tex-encoded-fontswitch
137 internal-external-name-mag-pairs))
140 (font-load-command (car x) (cdr x)))
141 (map cdr font-name-alist))))
144 (define (font-switch i)
148 (define (font-def i s)
150 "\\font" (font-switch i) "=" s "\n"))
154 "\\def\\lilyoutputscalefactor{"
155 (number->string (cond
156 ((equal? (ly:unit) "mm") (/ 72.0 25.4))
157 ((equal? (ly:unit) "pt") (/ 72.0 72.27))
158 (else (error "unknown unit" (ly:unit)))
161 "\\ifx\\lilypondstart\\undefined\n"
162 " \\input lilyponddefs\n"
164 "\\outputscale=\\lilypondpaperoutputscale \\lilypondpaperunit\n"
165 "\\lilypondpostscript\n"
166 "\\pdfcompresslevel=0"))
168 ;; Note: this string must match the string in ly2dvi.py!!!
169 (define (header creator generate)
171 "% Generated automatically by: " creator generate "\n"))
173 (define (invoke-char s i)
175 "\n\\" s "{" (inexact->string i 10) "}" ))
178 ;; need to do something to make this really safe.
180 (define (output-tex-string s)
181 (if security-paranoia
182 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
185 (define (lily-def key val)
187 (regexp-substitute/global
188 #f "_" (output-tex-string key) 'pre "X" 'post))
189 (tex-val (output-tex-string val)))
190 (if (equal? (sans-surrounding-whitespace tex-val) "")
191 (string-append "\\let\\" tex-key "\\undefined\n")
192 (string-append "\\def\\" tex-key "{" tex-val "}%\n"))))
194 (define (number->dim x)
196 ;;ugh ly:* in backend needs compatibility func for standalone output
197 (ly:number->string x) " \\outputscale "))
199 (define (placebox x y s)
200 (string-append "\\lyitem{"
201 (ly:number->string y) "}{"
202 (ly:number->string x) "}{"
205 (define (bezier-sandwich l thick)
206 (embedded-pdf (list 'bezier-sandwich `(quote ,l) thick)))
208 (define (start-system wd ht)
209 (string-append "\\leavevmode\n"
210 "\\scoreshift = " (number->dim (* ht 0.5)) "\n"
211 "\\lilypondifundefined{lilypondscoreshift}%\n"
213 " {\\advance\\scoreshift by -\\lilypondscoreshift}%\n"
215 (ly:number->string wd) "}{"
216 (ly:number->string ht) "}{%\n"))
218 (define (stop-system)
219 "}%\n%\n\\interscoreline\n%\n")
220 (define (stop-last-system)
223 (define (filledbox breapth width depth height)
224 (string-append "\\lyvrule{"
225 (ly:number->string (- breapth)) "}{"
226 (ly:number->string (+ breapth width)) "}{"
227 (ly:number->string depth) "}{"
228 (ly:number->string height) "}"))
230 (define (round-filled-box x y width height blotdiam)
231 (embedded-pdf (list 'round-filled-box x y width height blotdiam)))
234 (string-append "\\hbox{" (output-tex-string s) "}"))
236 (define (draw-line thick fx fy tx ty)
237 (embedded-pdf (list 'draw-line thick fx fy tx ty)))
239 (define (define-origin file line col)
240 (if (procedure? point-and-click)
241 (string-append "\\special{src:\\string:"
242 (point-and-click line col file)
247 ; no-origin not supported in PDFTeX
248 (define (no-origin) "")
253 (define-public (pdftex-output-expression expr port)
254 (display (eval expr this-module) port) )