1 ;;;; framework-eps.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 create-aux-files
56 (ly:get-option 'aux-files))
58 (define (dump-infinite-stack-EPS stencils)
59 (let* ((dump-me (stack-stencils Y DOWN 2.0 stencils)))
60 (dump-stencil-as-EPS paper dump-me basename #t)))
62 (define (dump-counted-stencil stencil-count-pair)
63 "Return EPS filename."
64 (let* ((stencil (car stencil-count-pair))
65 (number (cdr stencil-count-pair))
66 (name (format "~a-~a" basename number)))
67 (dump-stencil-as-EPS paper stencil name
68 (ly:get-option 'include-eps-fonts))
69 (string-append name ".eps")))
72 ;; First, create the output, then if necessary, individual staves and
73 ;; finally write some auxiliary files if desired
74 (dump-infinite-stack-EPS stencils)
75 (postprocess-output book framework-eps-module
76 (format "~a.eps" basename) (ly:output-formats))
78 ;; individual staves (*-1.eps etc.); only print if more than one stencil
79 ;; Otherwise the .eps and the -1.eps file will be identical and waste space
80 ;; Also always create if aux-files=##t
81 (if (or create-aux-files (< 1 (length stencils)))
82 (let* ((widened-stencils (widen-left-stencil-edges stencils))
83 (counted-systems (count-list widened-stencils))
84 (eps-files (map dump-counted-stencil counted-systems)))
86 ;; par-for-each: a bit faster ...
87 (for-each (lambda (y) (postscript->pdf 0 0 y))
90 ;; Now, write some aux files if requested: .texi, .tex and .count
91 ;; for direct inclusion into latex and texinfo
93 (let* ((write-file (lambda (str-port ext)
95 (let* ((name (format "~a-systems.~a" basename ext))
96 (port (open-output-file name)))
97 (ly:message (_ "Writing ~a...") name)
98 (display (get-output-string str-port) port)
99 (close-output-port port)))))
100 (tex-system-port (open-output-string))
101 (texi-system-port (open-output-string))
102 (count-system-port (open-output-string)))
103 (for-each (lambda (c)
106 "\\ifx\\betweenLilyPondSystem \\undefined
109 \\expandafter\\betweenLilyPondSystem{~a}%
113 (display (format "\\includegraphics{~a-~a}%\n"
114 basename (1+ c)) tex-system-port)
115 (display (format "@image{~a-~a}\n"
116 basename (1+ c)) texi-system-port))
117 (iota (length stencils)))
118 (display "@c eof\n" texi-system-port)
119 (display "% eof\n" tex-system-port)
120 (display (format "~a" (length stencils)) count-system-port)
121 (write-file texi-system-port "texi")
122 (write-file tex-system-port "tex")
123 ;; do this as the last action so we know the rest is complete if
124 ;; this file is present.
125 (write-file count-system-port "count"))))
127 (define-public (output-classic-framework basename book scopes fields)
128 (output-scopes scopes fields basename)
129 (if (ly:get-option 'dump-signatures)
130 (write-system-signatures basename (ly:paper-book-systems book) 1))
131 (dump-stencils-as-EPSes (map paper-system-stencil
132 (ly:paper-book-systems book))
136 (define-public (output-framework basename book scopes fields)
137 (output-scopes scopes fields basename)
138 (if (ly:get-option 'clip-systems)
139 (clip-system-EPSes basename book))
140 (dump-stencils-as-EPSes (map page-stencil
141 (ly:paper-book-pages book))
145 ; redefine to imports from framework-ps
146 (define convert-to-pdf
149 (define convert-to-ps
152 (define convert-to-png