1 ;;;; framework-ps.scm --
3 ;;;; source file of the GNU LilyPond music typesetter
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)
23 ergonomic-simple-format)
25 (define framework-eps-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
36 (interval-start (ly:stencil-extent stc X)))
42 (ly:stencil-expr stil)
44 (cdr (ly:stencil-extent stil X)))
45 (ly:stencil-extent stil Y)))
48 (define (dump-stencils-as-EPSes stencils book basename)
50 (member "pdf" (ly:output-formats)))
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)
70 (let* ((line (car stencils))
72 (system-base-name (format "~a-~a" basename count)))
73 (dump-stencil-as-EPS paper line system-base-name)
76 (string-append system-base-name ".eps")))
77 (dump-stencils-as-separate-EPS rest (1+ count)))))
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)))
93 ;; par-for-each: a bit faster ...
95 (postscript->pdf 0 0 y))
100 "\\ifx\\betweenLilyPondSystem \\undefined
103 \\expandafter\\betweenLilyPondSystem{~a}%
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))
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))
142 ; redefine to imports from framework-ps
143 (define convert-to-pdf
146 (define convert-to-ps
149 (define convert-to-png