Nitpick: ly:spanner-bound grob name slur -> spanner.
[lilypond.git] / scm / framework-eps.scm
blob7383f3181cbef2111efabe0e0bc39c168b964369
1 ;;;; framework-ps.scm --
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;;
5 ;;;; (c) 2004--2009 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
23   ergonomic-simple-format)
25 (define framework-eps-module
26   (current-module))
28 (define (widen-left-stencil-edges stencils)
29   "Change STENCILS to use the union for the left extents in every
30 stencil so that LaTeX's \\includegraphics command doesn't modify the
31 alignment."
32   (define left
33     (if (pair? stencils)
34         (apply min
35                (map (lambda (stc)
36                       (interval-start (ly:stencil-extent stc X)))
37                     stencils))
38         0.0))
40   (map (lambda (stil)
41          (ly:make-stencil
42           (ly:stencil-expr stil)
43           (cons left
44                 (cdr (ly:stencil-extent stil X)))
45           (ly:stencil-extent stil Y)))
46        stencils))
48 (define (dump-stencils-as-EPSes stencils book basename)
49   (define do-pdf
50     (member  "pdf" (ly:output-formats)))
52   (define paper
53     (ly:paper-book-paper book))
55   (define (dump-infinite-stack-EPS stencils)
56     (let* ((dump-me (stack-stencils Y DOWN 2.0 stencils)))
57       (dump-stencil-as-EPS paper dump-me basename #t)))
59   (define (dump-counted-stencil stencil-count-pair)
60     "Return EPS filename."
61     (let* ((stencil (car stencil-count-pair))
62            (number (cdr stencil-count-pair))
63            (name (format "~a-~a" basename number)))
64       (dump-stencil-as-EPS paper stencil name
65                            (ly:get-option 'include-eps-fonts))
66       (string-append name ".eps")))
68   (define (dump-stencils-as-separate-EPS stencils count)
69     (if (pair? stencils)
70         (let* ((line (car stencils))
71                (rest (cdr stencils))
72                (system-base-name (format "~a-~a" basename count)))
73           (dump-stencil-as-EPS paper line system-base-name)
74           (if do-pdf
75               (postscript->pdf 0 0
76                                (string-append system-base-name ".eps")))
77           (dump-stencils-as-separate-EPS rest (1+ count)))))
79   ;; main body
80   (let* ((write-file (lambda (str-port ext)
81                        (let* ((name (format "~a-systems.~a" basename ext))
82                               (port (open-output-file name)))
83                          (ly:message (_ "Writing ~a...") name)
84                          (display (get-output-string str-port) port)
85                          (close-output-port port))))
86          (tex-system-port (open-output-string))
87          (texi-system-port (open-output-string))
88          (count-system-port (open-output-string))
89          (widened-stencils (widen-left-stencil-edges stencils))
90          (counted-systems  (count-list widened-stencils))
91          (eps-files (map dump-counted-stencil counted-systems)))
92     (if do-pdf
93         ;; par-for-each: a bit faster ...
94         (for-each (lambda (y)
95                     (postscript->pdf 0 0 y))
96                   eps-files))
97     (for-each (lambda (c)
98                 (if (< 0 c)
99                     (display (format
100                               "\\ifx\\betweenLilyPondSystem \\undefined
101   \\linebreak
102 \\else
103   \\expandafter\\betweenLilyPondSystem{~a}%
104 \\fi
105 " c)
106                              tex-system-port))
107                 (display (format "\\includegraphics{~a-~a}%\n"
108                                  basename (1+ c)) tex-system-port)
109                 (display (format "@image{~a-~a}\n"
110                                  basename (1+ c)) texi-system-port))
111               (iota (length stencils)))
112     (display "@c eof\n" texi-system-port)
113     (display "% eof\n" tex-system-port)
114     (display (format "~a" (length stencils)) count-system-port)
115     (dump-infinite-stack-EPS stencils)
116     (postprocess-output book framework-eps-module
117                         (format "~a.eps" basename) (ly:output-formats))
118     (write-file texi-system-port "texi")
119     (write-file tex-system-port "tex")
120     ;; do this as the last action so we know the rest is complete if
121     ;; this file is present.
122     (write-file count-system-port "count")))
124 (define-public (output-classic-framework basename book scopes fields)
125   (output-scopes scopes fields basename)
126   (if (ly:get-option 'dump-signatures)
127       (write-system-signatures basename (ly:paper-book-systems book) 1))
128   (dump-stencils-as-EPSes (map paper-system-stencil
129                                (ly:paper-book-systems book))
130                           book
131                           basename))
133 (define-public (output-framework basename book scopes fields)
134   (output-scopes scopes fields basename)
135   (if (ly:get-option 'clip-systems)
136       (clip-system-EPSes basename book))
137   (dump-stencils-as-EPSes (map page-stencil
138                                (ly:paper-book-pages book))
139                           book
140                           basename))
142 ; redefine to imports from framework-ps
143 (define convert-to-pdf
144   convert-to-pdf)
146 (define convert-to-ps
147   convert-to-ps)
149 (define convert-to-png
150   convert-to-png)