]> git.donarmstrong.com Git - lilypond.git/blob - scm/pdftex.scm
* scm/grob-property-description.scm (beamed-minimum-free-lengths):
[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 (use-modules (scm pdf)
16              (guile)
17              (ice-9 regex)
18              (ice-9 string-fun)   
19              )
20
21 (define this-module (current-module))
22 (define (unknown) 
23   "%\n\\unknown%\n")
24
25
26 (define (select-font name-mag-pair)
27   (let*
28       (
29        (c (assoc name-mag-pair font-name-alist))
30        )
31
32     (if (eq? c #f)
33         (begin
34           (display "FAILED\n")
35           (display (object-type (car name-mag-pair)))
36           (display (object-type (caaar font-name-alist)))
37
38           (ly-warn (string-append
39                     "Programming error: No such font known "
40                     (car name-mag-pair) " "
41                     (ly-number->string (cdr name-mag-pair))
42                     ))
43           "") ; issue no command
44         (string-append "\\" (cddr c)))
45     
46     
47     ))
48
49 (define (beam width slope thick)
50   (embedded-pdf (list 'beam  width slope thick)))
51
52 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
53   (embedded-pdf (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
54
55 (define (dashed-slur thick dash l)
56   (embedded-pdf (list 'dashed-slur   thick dash l)))
57
58 (define (char i)
59   (string-append "\\char" (inexact->string i 10) " "))
60
61 (define (dashed-line thick on off dx dy)
62   (embedded-pdf (list 'dashed-line  thick on off dx dy)))
63
64 (define (font-load-command name-mag command)
65   (string-append
66    "\\font\\" command "="
67    (car name-mag)
68    " scaled "
69    (ly-number->string (inexact->exact (* 1000  (cdr name-mag))))
70    "\n"))
71
72 (define (ez-ball c l b)
73   (embedded-pdf (list 'ez-ball  c  l b)))
74
75
76
77 (if (or (equal? (minor-version) "4.1")
78         (equal? (minor-version) "4")
79         (equal? (minor-version) "3.4"))
80     (define (embedded-pdf expr)
81       (let ((ps-string
82              (with-output-to-string
83                (lambda () (pdf-output-expression expr (current-output-port))))))
84         (string-append "\\embeddedpdf{" ps-string "}")))
85     (define (embedded-pdf expr)
86       (let
87           ((os (open-output-string)))
88         (pdf-output-expression expr os)
89         (string-append "\\embeddedpdf{" (get-output-string os) "}"))))
90
91
92 (define (comment s)
93   (simple-format #f "% ~a\n" s))
94
95 (define (end-output) 
96   (begin
97                                         ; uncomment for some stats about lily memory      
98                                         ;               (display (gc-stats))
99     (string-append "\n\\EndLilyPondOutput"
100                                         ; Put GC stats here.
101                    )))
102
103 (define (experimental-on)
104   "")
105
106 (define (repeat-slash w a t)
107   (embedded-pdf (list 'repeat-slash w a t)))
108 (define (fontify name-mag-pair exp)
109   (string-append (select-font name-mag-pair)
110                  exp))
111
112
113 (define (tex-encoded-fontswitch name-mag)
114   (let* ((iname-mag (car name-mag))
115          (ename-mag (cdr name-mag)))
116     (cons iname-mag
117           (cons ename-mag
118                 (string-append  "magfont"
119                           (string-encode-integer
120                            (hashq (car ename-mag) 1000000))
121                           "m"
122                           (string-encode-integer
123                            (inexact->exact (* 1000 (cdr ename-mag)))))))))
124 (define (define-fonts internal-external-name-mag-pairs)
125   (set! font-name-alist (map tex-encoded-fontswitch
126                              internal-external-name-mag-pairs))
127   (apply string-append
128          (map (lambda (x)
129                 (font-load-command (car x) (cdr x)))
130               (map cdr font-name-alist))))
131
132
133 (define (font-switch i)
134   (string-append
135    "\\" (font i) "\n"))
136
137 (define (font-def i s)
138   (string-append
139    "\\font" (font-switch i) "=" s "\n"))
140
141 (define (header-end)
142   (string-append
143    "\\input lilyponddefs\\newdimen\\outputscale \\outputscale=\\lilypondpaperoutputscale pt"
144    "\\turnOnPostScript"
145    "\\pdfcompresslevel=0"))
146
147 ;; Note: this string must match the string in ly2dvi.py!!!
148 (define (header creator generate) 
149   (string-append
150    "% Generated automatically by: " creator generate "\n"))
151
152 (define (invoke-char s i)
153   (string-append 
154    "\n\\" s "{" (inexact->string i 10) "}" ))
155
156 ;;
157 ;; need to do something to make this really safe.
158 ;;
159 (define (output-tex-string s)
160   (if security-paranoia
161       (if use-regex
162           (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
163           (begin (display "warning: not paranoid") (newline) s))
164       s))
165
166 (define (lily-def key val)
167   (let ((tex-key
168          (if use-regex
169              (regexp-substitute/global 
170               #f "_" (output-tex-string key) 'pre "X" 'post)      
171              (output-tex-string key)))
172         (tex-val (output-tex-string val)))
173     (if (equal? (sans-surrounding-whitespace tex-val) "")
174         (string-append "\\let\\" tex-key "\\undefined\n")
175         (string-append "\\def\\" tex-key "{" tex-val "}\n"))))
176
177 (define (number->dim x)
178   (string-append
179    ;;ugh ly-* in backend needs compatibility func for standalone output
180    (ly-number->string x) " \\outputscale "))
181
182 (define (placebox x y s) 
183   (string-append 
184    "\\placebox{"
185    (number->dim y) "}{" (number->dim x) "}{" s "}\n"))
186
187 (define (bezier-bow l thick)
188   (embedded-pdf (list 'bezier-bow  `(quote ,l) thick)))
189
190 (define (bezier-sandwich l thick)
191   (embedded-pdf (list 'bezier-sandwich  `(quote ,l) thick)))
192
193 (define (start-system ht)
194   (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
195
196 (define (stop-system) 
197   "}\\vss}\\interscoreline\n")
198 (define (stop-last-system)
199   "}\\vss}")
200 (define (filledbox breapth width depth height) 
201   (string-append 
202    "\\kern" (number->dim (- breapth))
203    "\\vrule width " (number->dim (+ breapth width))
204    "depth " (number->dim depth)
205    "height " (number->dim height) " "))
206
207 (define (roundfilledbox x y width height blotdiam)
208   (embedded-pdf (list 'roundfilledbox  x y width height blotdiam)))
209
210 (define (text s)
211   (string-append "\\hbox{" (output-tex-string s) "}"))
212
213
214 (define (define-origin file line col)
215   (if (procedure? point-and-click)
216       (string-append "\\special{src:\\string:"
217                      (point-and-click line col file)
218                      "}" )
219       "")
220   )
221
222                                         ; no-origin not supported in PDFTeX
223 (define (no-origin) "")
224
225
226
227 (define my-eval-in-module eval)
228
229 (if (or (equal? (minor-version) "4.1")
230         (equal? (minor-version) "4")
231         (equal? (minor-version) "3.4"))
232     (set! my-eval-in-module eval-in-module))
233
234 (define-public (pdftex-output-expression expr port)
235   (display (my-eval-in-module expr this-module) port) )