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--2004 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 "Programming error: No such font known ~S ~S"
42 (ly:number->string (cdr name-mag-pair))
44 "") ; issue no command
45 (string-append "\\" (cddr c)))
50 (define (beam width slope thick blot)
51 (embedded-pdf (list 'beam width slope thick blot)))
53 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
54 (embedded-pdf (list 'bracket arch_angle arch_width arch_height height arch_thick thick)))
56 (define (dashed-slur thick dash l)
57 (embedded-pdf (list 'dashed-slur thick dash l)))
60 (string-append "\\char" (ly:inexact->string i 10) " "))
62 (define (dashed-line thick on off dx dy)
63 (embedded-pdf (list 'dashed-line thick on off dx dy)))
65 (define (font-load-command name-mag command)
67 "\\font\\" command "="
70 (ly:number->string (inexact->exact (* 1000 (cdr name-mag))))
73 (define (ez-ball c l b)
74 (embedded-pdf (list 'ez-ball c l b)))
76 (define (header-to-file fn key val)
77 (set! key (symbol->string key))
78 (if (not (equal? "-" fn))
79 (set! fn (string-append fn "." key))
82 (format "writing header field `~a' to `~a'..."
84 (if (equal? "-" fn) "<stdout>" fn)
89 (display val (open-file fn "w"))
91 (display "\n" (current-error-port))
95 (define (embedded-pdf expr)
97 ((os (open-output-string)))
98 (pdf-output-expression expr os)
99 (string-append "\\embeddedpdf{" (get-output-string os) "}")))
103 (define (experimental-on)
106 (define (repeat-slash w a t)
107 (embedded-pdf (list 'repeat-slash w a t)))
110 (define (tex-encoded-fontswitch name-mag)
111 (let* ((iname-mag (car name-mag))
112 (ename-mag (cdr name-mag)))
115 (string-append "magfont"
116 (string-encode-integer
117 (hashq (car ename-mag) 1000000))
119 (string-encode-integer
120 (inexact->exact (* 1000 (cdr ename-mag)))))))))
121 (define (define-fonts internal-external-name-mag-pairs)
122 (set! font-name-alist (map tex-encoded-fontswitch
123 internal-external-name-mag-pairs))
126 (font-load-command (car x) (cdr x)))
127 (map cdr font-name-alist))))
130 (define (font-switch i)
134 (define (font-def i s)
136 "\\font" (font-switch i) "=" s "\n"))
140 "\\def\\lilyoutputscalefactor{"
141 (number->string (cond
142 ((equal? (ly:unit) "mm") (/ 72.0 25.4))
143 ((equal? (ly:unit) "pt") (/ 72.0 72.27))
144 (else (error "unknown unit" (ly:unit)))
147 "\\ifx\\lilypondstart\\undefined\n"
148 " \\input lilyponddefs\n"
150 "\\outputscale=\\lilypondpaperoutputscale \\lilypondpaperunit\n"
151 "\\lilypondpostscript\n"
152 "\\pdfcompresslevel=0"))
154 ;; Note: this string must match the string in lilypond.py!!!
155 (define (header creator generate)
157 "% Generated automatically by: " creator generate "\n"))
159 (define (invoke-char s i)
161 "\n\\" s "{" (ly:inexact->string i 10) "}" ))
163 ;; FIXME: explain ploblem: need to do something to make this really safe.
164 (define (output-tex-string s)
165 (if (ly:get-option 'safe)
166 (regexp-substitute/global #f "\\\\"
167 (regexp-substitute/global #f "\\([{}]\\)" s 'pre "\\1" 'post)
168 'pre "$\\backslash$" 'post)
172 (define (lily-def key val)
174 (regexp-substitute/global
175 #f "_" (output-tex-string key) 'pre "X" 'post))
176 (tex-val (output-tex-string val)))
177 (if (equal? (sans-surrounding-whitespace tex-val) "")
178 (string-append "\\let\\" tex-key "\\undefined\n")
179 (string-append "\\def\\" tex-key "{" tex-val "}%\n"))))
181 (define (number->dim x)
183 ;;ugh ly:* in backend needs compatibility func for standalone output
184 (ly:number->string x) " \\outputscale "))
186 (define (placebox x y s)
187 (string-append "\\lyitem{"
188 (ly:number->string y) "}{"
189 (ly:number->string x) "}{"
192 (define (bezier-sandwich l thick)
193 (embedded-pdf (list 'bezier-sandwich `(quote ,l) thick)))
195 (define (start-system wd ht)
196 (string-append "\\leavevmode\n"
197 "\\scoreshift = " (number->dim (* ht 0.5)) "\n"
198 "\\lilypondifundefined{lilypondscoreshift}%\n"
200 " {\\advance\\scoreshift by -\\lilypondscoreshift}%\n"
202 (ly:number->string wd) "}{"
203 (ly:number->string ht) "}{%\n"))
205 (define (stop-system)
206 "}%\n%\n\\interscoreline\n%\n")
207 (define (stop-last-system)
210 (define (filledbox breapth width depth height)
211 (string-append "\\lyvrule{"
212 (ly:number->string (- breapth)) "}{"
213 (ly:number->string (+ breapth width)) "}{"
214 (ly:number->string depth) "}{"
215 (ly:number->string height) "}"))
217 (define (round-filled-box x y width height blotdiam)
218 (embedded-pdf (list 'round-filled-box x y width height blotdiam)))
221 (string-append "\\hbox{" (output-tex-string s) "}"))
223 (define (draw-line thick fx fy tx ty)
224 (embedded-pdf (list 'draw-line thick fx fy tx ty)))
226 (define (define-origin file line col)
227 (if (procedure? point-and-click)
228 (string-append "\\special{src:\\string:"
229 (point-and-click line col file)
234 ; no-origin not supported in PDFTeX
235 (define (no-origin) "")
240 (define-public (pdftex-output-expression expr port)
241 (display (eval expr this-module) port) )