]> git.donarmstrong.com Git - lilypond.git/blob - scm/framework-eps.scm
Further lilypond-book cleanup:
[lilypond.git] / scm / framework-eps.scm
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>
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              (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))
21
22 (define format ergonomic-simple-format)
23
24 (define framework-eps-module (current-module))
25
26
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."
30
31   (define left
32     (if (pair? stencils)
33
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))
50
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)))
57
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)))
64
65       (dump-stencil-as-EPS
66        paper stencil name
67        (ly:get-option 'include-eps-fonts))
68
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                )
77
78           (dump-stencil-as-EPS
79            paper line system-base-name)
80
81           (if do-pdf
82               (postscript->pdf  0 0  (string-append system-base-name ".eps")))
83           (dump-stencils-as-separate-EPS rest (1+ count)))))
84
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
104
105         ;; par-for-each: a bit faster ...  
106         (for-each
107          (lambda (y)
108            (postscript->pdf 0 0 y))
109          eps-files))
110
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))
131
132     (write-file texi-system-port "texi")
133     (write-file tex-system-port "tex")
134     (write-file count-system-port "count")
135     ))
136
137
138
139 (define-public (output-classic-framework basename book scopes fields)
140   (output-scopes scopes fields basename)
141
142   (if (ly:get-option 'dump-signatures)
143       (write-system-signatures basename (ly:paper-book-systems book) 1))
144   
145   (dump-stencils-as-EPSes
146    (map paper-system-stencil (ly:paper-book-systems book))
147    book
148    basename))
149
150 (define-public (output-framework basename book scopes fields)
151   (output-scopes scopes fields basename)
152   (if (ly:get-option 'clip-systems)
153       (clip-system-EPSes basename book))
154
155   (dump-stencils-as-EPSes
156    (map page-stencil (ly:paper-book-pages book)) book basename))
157   
158
159 ; redefine to imports from framework-ps
160 (define convert-to-pdf convert-to-pdf)
161 (define convert-to-ps convert-to-ps)
162 (define convert-to-png convert-to-png)
163 (define convert-to-tex convert-to-tex)
164 (define convert-to-dvi convert-to-dvi)
165
166