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