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