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