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