1 ;;;; framework-ps.scm --
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2004--2008 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)
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."
36 (interval-start (ly:stencil-extent stc X)))
43 (ly:stencil-expr stil)
46 (cdr (ly:stencil-extent stil X)))
47 (ly:stencil-extent stil Y)
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)
61 ((stencil (car stencil-count-pair))
62 (number (cdr stencil-count-pair))
63 (name (format "~a-~a" basename number)))
67 (ly:get-option 'include-eps-fonts))
69 (string-append name ".eps")))
71 (define (dump-stencils-as-separate-EPS stencils count)
73 (let* ((line (car stencils))
75 (system-base-name (format "~a-~a" basename count))
79 paper line system-base-name)
82 (postscript->pdf 0 0 (string-append system-base-name ".eps")))
83 (dump-stencils-as-separate-EPS rest (1+ count)))))
86 (let* ((write-file (lambda (str-port ext)
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)
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))
105 ;; par-for-each: a bit faster ...
108 (postscript->pdf 0 0 y))
111 (for-each (lambda (c)
113 (display (format "\\ifx\\betweenLilyPondSystem \\undefined
116 \\betweenLilyPondSystem{~a}
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)))
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")
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))
148 (dump-stencils-as-EPSes
149 (map paper-system-stencil (ly:paper-book-systems book))
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))
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)