]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
color patch by EA
[lilypond.git] / scm / output-tex.scm
1 ;;;; tex.scm -- implement Scheme output routines for TeX
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;;                 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8
9 ;; (debug-enable 'backtrace)
10
11 ;; The public interface is tight.
12 ;; It has to be, because user-code is evalled with this module.
13
14 ;; ***It should also be clean, well defined, documented and reviewed***
15
16 ;; To be reasonably safe, you probably do not want to use the TeX
17 ;; backend anyway, but rather the PostScript backend.  You may want
18 ;; to run gs in a uml sandbox too.
19
20
21 (define-module (scm output-tex)
22   #:re-export (quote)
23
24   ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
25   #:export (unknown
26             blank
27             circle
28             dot
29             white-dot
30             beam
31             bracket
32             dashed-slur
33             named-glyph
34             dashed-line
35             zigzag-line
36             ez-ball
37             comment
38             repeat-slash
39             placebox
40             bezier-sandwich
41             horizontal-line
42             filledbox
43             round-filled-box
44             text
45             white-text
46             setcolor
47             resetcolor
48             polygon
49             draw-line
50             no-origin
51             grob-cause))
52
53 (use-modules (ice-9 regex)
54              (ice-9 string-fun)
55              (ice-9 format)
56              (guile)
57              (srfi srfi-13)
58              (scm framework-tex)
59              (lily))
60
61
62
63 ;;;;;;;;
64 ;;;;;;;; DOCUMENT ME!
65 ;;;;;;;;
66
67
68 (define (char font i)
69   (string-append "\\" (tex-font-command font)
70                  "\\char" (ly:inexact->string i 10) " "))
71
72 (define (unknown) 
73   "%\n\\unknown\n")
74
75 (define (url-link url x y)
76   "")
77
78 (define (blank)
79   "")
80
81 (define (circle radius thick)
82   (embedded-ps (list 'circle radius thick)))
83
84 (define (dot x y radius)
85   (embedded-ps (list 'dot x y radius)))
86
87 (define (embedded-ps string)
88   (embedded-ps (list 'embedded-ps string)))
89
90 (define (white-dot x y radius)
91   (embedded-ps (list 'white-dot x y radius)))
92
93 (define (beam width slope thick blot)
94   (embedded-ps (list 'beam  width slope thick blot)))
95
96 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
97   (embedded-ps (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
98
99 (define (dashed-slur thick on off lst)
100   (embedded-ps (list 'dashed-slur thick on off `(quote ,lst))))
101
102 (define (named-glyph font name)
103   (let* ((info (ly:otf-font-glyph-info font name))
104          (subfont (assoc-get 'subfont info))
105          (subidx  (assoc-get 'subfont-index info)))
106     
107     ;;(stderr "INFO: ~S\n" info)
108     ;;(stderr "FONT: ~S\n" font)
109     (if (and subfont subidx)
110         (string-append "\\" (tex-font-command-raw
111                              subfont
112                              (ly:font-magnification font))
113                        "\\char" (number->string subidx))
114
115         (begin
116           (ly:warn "Can't find ~a in ~a" name font)
117           ""))))
118
119 (define (dashed-line thick on off dx dy)
120   (embedded-ps (list 'dashed-line  thick on off dx dy)))
121
122 (define (zigzag-line centre? zzw zzh thick dx dy)
123   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
124
125 (define (ez-ball c lst b)
126   (embedded-ps (list 'ez-ball c lst b)))
127
128 (define (embedded-ps expr)
129   (let ((ps-string
130          (with-output-to-string
131            (lambda () (ps-output-expression expr (current-output-port))))))
132     (string-append "\\embeddedps{" ps-string "}")))
133
134 (define (repeat-slash w a t)
135   (embedded-ps (list 'repeat-slash  w a t)))
136
137 (define (number->dim x)
138   (string-append
139    ;;ugh ly:* in backend needs compatibility func for standalone output
140    (ly:number->string x) " \\outputscale "))
141
142 (define (placebox x y s) 
143   (string-append
144    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
145
146 (define (bezier-sandwich lst thick)
147   (embedded-ps (list 'bezier-sandwich `(quote ,lst) thick)))
148
149 ;; WTF is this in every backend?
150 (define (horizontal-line x1 x2 th)
151   (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
152
153 (define (filledbox breapth width depth height)
154   (if (and #f (defined? 'ps-testing))
155       (embedded-ps
156        (string-append (ly:numbers->string (list breapth width depth height))
157                       " draw_box" ))
158       (string-append "\\lyvrule{"
159                      (ly:number->string (- breapth)) "}{"
160                      (ly:number->string (+ breapth width)) "}{"
161                      (ly:number->string depth) "}{"
162                      (ly:number->string height) "}")))
163
164 (define (round-filled-box x y width height blotdiam)
165   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
166
167 (define (text font s)
168   (format
169    "\\hbox{\\~a{}~a}" (tex-font-command font)
170    (sanitize-tex-string s)))
171
172 (define (white-text scale s)
173   (embedded-ps (list 'white-text scale s)))
174
175 (define (setcolor r g b)
176   (string-append "\\color[rgb]{"
177   (number->string r) ", "
178   (number->string g) ", "
179   (number->string b) "}"))
180
181 ;; FIXME
182 ;; The PostScript backend saves the current color
183 ;; during setcolor and restores it during resetcolor.
184 ;; We don't do that here.
185 (define (resetcolor)
186   (string-append "\\color[rgb]{0,0,0}"))
187
188 (define (polygon points blotdiameter)
189   (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
190
191 (define (draw-line thick fx fy tx ty)
192   (embedded-ps (list 'draw-line thick fx fy tx ty)))
193
194 ;; no-origin not yet supported by Xdvi
195 (define (no-origin) "")
196
197 (define (grob-cause offset grob)
198   (if (procedure? point-and-click)
199       (let* ((cause (ly:grob-property grob 'cause))
200              (music-origin (if (ly:music? cause)
201                                (ly:music-property cause 'origin)))
202              (location (if (ly:input-location? music-origin)
203                            (ly:input-file-line-column music-origin))))
204         (if (pair? location)
205              ;;; \\string ? 
206             (string-append "\\special{src:"
207                            (apply point-and-click location) "}")
208             ""))
209       ""))