Fix PLATFORM variable in lily.scm.
[lilypond.git] / scm / framework-eps.scm
blobfcd0779198792f6e0483c70a8a0b915c016d2b02
1 ;;;; framework-ps.scm --
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;;
5 ;;;; (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 (define-module (scm framework-eps))
9 ;;; this is still too big a mess.
11 (use-modules (ice-9 regex)
12              (ice-9 string-fun)
13              (guile)
14              (scm framework-ps)
15              (scm paper-system)
16              (scm page)
17              (scm output-ps)
18              (srfi srfi-1)
19              (srfi srfi-13)
20              (lily))
22 (define format ergonomic-simple-format)
24 (define framework-eps-module (current-module))
27 (define (widen-left-stencil-edges stencils)
28   "Change STENCILS to use the union for the left extents in every
29 stencil, so LaTeX includegraphics doesn't fuck up the alignment."
31   (define left
32     (if (pair? stencils)
34         (apply min
35                (map (lambda (stc)
36                       (interval-start (ly:stencil-extent stc X)))
37                     stencils))
38         0.0))
39     
40   (map (lambda (stil)
41          
42          (ly:make-stencil
43           (ly:stencil-expr stil)
44           (cons
45            left
46            (cdr (ly:stencil-extent stil X)))
47           (ly:stencil-extent stil Y)
48           ))
49        stencils))
51 (define (dump-stencils-as-EPSes stencils book basename)
52   (define do-pdf (member  "pdf" (ly:output-formats)))
53   (define paper (ly:paper-book-paper book))
54   (define (dump-infinite-stack-EPS stencils)
55     (let* ((dump-me (stack-stencils Y DOWN 2.0 stencils)))
56       (dump-stencil-as-EPS paper dump-me basename #t)))
58   (define (dump-counted-stencil stencil-count-pair)
59     "Return EPS filename" 
60     (let*
61         ((stencil (car stencil-count-pair))
62          (number (cdr stencil-count-pair))
63          (name (format "~a-~a" basename number)))
65       (dump-stencil-as-EPS
66        paper stencil name
67        (ly:get-option 'include-eps-fonts))
69       (string-append name ".eps")))
70   
71   (define (dump-stencils-as-separate-EPS stencils count)
72     (if (pair? stencils)
73         (let* ((line (car stencils))
74                (rest (cdr stencils))
75                (system-base-name (format "~a-~a" basename count))
76                )
78           (dump-stencil-as-EPS
79            paper line system-base-name)
81           (if do-pdf
82               (postscript->pdf  0 0  (string-append system-base-name ".eps")))
83           (dump-stencils-as-separate-EPS rest (1+ count)))))
85   ;; main body 
86   (let* ((write-file (lambda (str-port ext)
87                        (let*
88                            ((name (format "~a-systems.~a" basename ext))
89                             (port (open-output-file name)))
90                          (ly:message (_ "Writing ~a...") name)
91                          (display (get-output-string str-port) port)
92                          (close-output-port port)
93                          )))
94          
95          (tex-system-port (open-output-string))
96          (texi-system-port (open-output-string))
97          (count-system-port (open-output-string))
98          (widened-stencils (widen-left-stencil-edges stencils))
99          (counted-systems  (count-list widened-stencils))
100          (eps-files (map dump-counted-stencil  counted-systems))
101          )
102     
103     (if do-pdf
105         ;; par-for-each: a bit faster ...  
106         (for-each
107          (lambda (y)
108            (postscript->pdf 0 0 y))
109          eps-files))
111     (for-each (lambda (c)
112                 (if (< 0 c)
113                     (display (format "\\ifx\\betweenLilyPondSystem \\undefined
114   \\linebreak
115 \\else
116   \\betweenLilyPondSystem{~a}
117 \\fi
118 " c) tex-system-port))
119                 (display (format "\\includegraphics{~a-~a}\n"
120                                  basename (1+ c)) tex-system-port)
121                 (display (format "@image{~a-~a}\n"
122                                  basename (1+ c)) texi-system-port))
123               (iota (length stencils)))
124     
125     (display "@c eof." texi-system-port)
126     (display "% eof. " tex-system-port)
127     (display (format "~a" (length stencils)) count-system-port)
128     (dump-infinite-stack-EPS stencils)
129     (postprocess-output book framework-eps-module
130                         (format "~a.eps" basename) (ly:output-formats))
132     (write-file texi-system-port "texi")
133     (write-file tex-system-port "tex")
135     ;; do this as the last action so we know the rest is complete if
136     ;; this file is present.
137     (write-file count-system-port "count")
138     ))
142 (define-public (output-classic-framework basename book scopes fields)
143   (output-scopes scopes fields basename)
145   (if (ly:get-option 'dump-signatures)
146       (write-system-signatures basename (ly:paper-book-systems book) 1))
147   
148   (dump-stencils-as-EPSes
149    (map paper-system-stencil (ly:paper-book-systems book))
150    book
151    basename))
153 (define-public (output-framework basename book scopes fields)
154   (output-scopes scopes fields basename)
155   (if (ly:get-option 'clip-systems)
156       (clip-system-EPSes basename book))
158   (dump-stencils-as-EPSes
159    (map page-stencil (ly:paper-book-pages book)) book basename))
160   
162 ; redefine to imports from framework-ps
163 (define convert-to-pdf convert-to-pdf)
164 (define convert-to-ps convert-to-ps)
165 (define convert-to-png convert-to-png)
166 (define convert-to-tex convert-to-tex)
167 (define convert-to-dvi convert-to-dvi)