]> git.donarmstrong.com Git - lilypond.git/blob - scm/framework-eps.scm
Bump documentation license to v1.3+.
[lilypond.git] / scm / framework-eps.scm
1 ;;;; framework-eps.scm --
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;;
5 ;;;; (c) 2004--2009 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
23   ergonomic-simple-format)
24
25 (define framework-eps-module
26   (current-module))
27
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))
39
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))
47
48 (define (dump-stencils-as-EPSes stencils book basename)
49   (define do-pdf
50     (member  "pdf" (ly:output-formats)))
51
52   (define paper
53     (ly:paper-book-paper book))
54     
55   (define create-aux-files
56     (ly:get-option 'aux-files))
57
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)))
61
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")))
70
71   ;; main body
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))
77
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)))
85       (if do-pdf
86           ;; par-for-each: a bit faster ...
87           (for-each (lambda (y) (postscript->pdf 0 0 y))
88                     eps-files))))
89
90   ;; Now, write some aux files if requested: .texi, .tex and .count
91   ;; for direct inclusion into latex and texinfo
92   (if create-aux-files
93     (let* ((write-file (lambda (str-port ext)
94                          (if create-aux-files
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)
104                   (if (< 0 c)
105                       (display (format
106                                 "\\ifx\\betweenLilyPondSystem \\undefined
107   \\linebreak
108 \\else
109   \\expandafter\\betweenLilyPondSystem{~a}%
110 \\fi
111 " c)
112                                tex-system-port))
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"))))
126
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))
133                           book
134                           basename))
135
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))
142                           book
143                           basename))
144
145 ; redefine to imports from framework-ps
146 (define convert-to-pdf
147   convert-to-pdf)
148
149 (define convert-to-ps
150   convert-to-ps)
151
152 (define convert-to-png
153   convert-to-png)