]> git.donarmstrong.com Git - lilypond.git/blob - scm/framework-eps.scm
for lp-book, output empty *-systems.tex* for an empty file.
[lilypond.git] / scm / framework-eps.scm
1 ;;;; framework-ps.scm --
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;;
5 ;;;; (c) 2004--2006 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              (ice-9 format)
14              (guile)
15              (scm framework-ps)
16              (scm paper-system)
17              (scm page)
18              (scm output-ps)
19              (srfi srfi-1)
20              (srfi srfi-13)
21              (lily))
22
23 (define framework-eps-module (current-module))
24
25
26 (define (widen-left-stencil-edges stencils)
27   "Change STENCILS to use the union for the left extents in every
28 stencil, so LaTeX includegraphics doesn't fuck up the alignment."
29
30   (define left
31     (if (pair? stencils)
32
33         (apply min
34                (map (lambda (stc)
35                       (interval-start (ly:stencil-extent stc X)))
36                     stencils))
37         0.0))
38     
39   (map (lambda (stil)
40          
41          (ly:make-stencil
42           (ly:stencil-expr stil)
43           (cons
44            left
45            (cdr (ly:stencil-extent stil X)))
46           (ly:stencil-extent stil Y)
47           ))
48        stencils))
49
50 (define (dump-stencils-as-EPSes stencils book basename)
51   (define do-pdf (member  "pdf" (ly:output-formats)))
52   (define paper (ly:paper-book-paper book))
53   (define (dump-infinite-stack-EPS stencils)
54     (let* ((dump-me (stack-stencils Y DOWN 2.0 stencils)))
55       (dump-stencil-as-EPS paper dump-me basename #t)))
56
57   (define (dump-counted-stencil stencil-count-pair)
58     "Return EPS filename" 
59     (let*
60         ((stencil (car stencil-count-pair))
61          (number (cdr stencil-count-pair))
62          (name (format "~a-~a" basename number)))
63
64       (dump-stencil-as-EPS
65        paper stencil name
66        (ly:get-option 'include-eps-fonts))
67
68       (string-append name ".eps")))
69   
70   (define (dump-stencils-as-separate-EPS stencils count)
71     (if (pair? stencils)
72         (let* ((line (car stencils))
73                (rest (cdr stencils))
74                (system-base-name (format "~a-~a" basename count))
75                )
76
77           (dump-stencil-as-EPS
78            paper line system-base-name)
79
80           (if do-pdf
81               (postscript->pdf  0 0  (string-append system-base-name ".eps")))
82           (dump-stencils-as-separate-EPS rest (1+ count)))))
83
84   ;; main body 
85   (let* ((tex-system-name (format "~a-systems.tex" basename))
86          (texi-system-name (format "~a-systems.texi" basename))
87          (tex-system-port (open-output-file tex-system-name))
88          (texi-system-port (open-output-file texi-system-name))
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          )
93     
94     (ly:message (_ "Writing ~a...") tex-system-name)
95     (ly:message (_ "Writing ~a...") texi-system-name)
96
97     (if do-pdf
98
99         ;; par-for-each: a bit faster ...  
100         (for-each
101          (lambda (y)
102            (postscript->pdf 0 0 y))
103          eps-files))
104
105     (for-each (lambda (c)
106                 (if (< 0 c)
107                     (display (format "\\ifx\\betweenLilyPondSystem \\undefined
108   \\linebreak
109 \\else
110   \\betweenLilyPondSystem{~a}
111 \\fi
112 " c) 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     
119     (display "@c eof - 'eof' is a Makefile marker; do not remove. " texi-system-port)
120     (display "% eof - 'eof' is Makefile marker; do not remove. " tex-system-port)
121     
122     (close-output-port texi-system-port)
123     (close-output-port tex-system-port)
124     
125     (dump-infinite-stack-EPS stencils)
126     (postprocess-output book framework-eps-module
127                         (format "~a.eps" basename) (ly:output-formats))))
128
129
130
131 (define-public (output-classic-framework basename book scopes fields)
132   (output-scopes scopes fields basename)
133
134   (if (ly:get-option 'dump-signatures)
135       (write-system-signatures basename (ly:paper-book-systems book) 1))
136   
137   (dump-stencils-as-EPSes
138    (map paper-system-stencil (ly:paper-book-systems book))
139    book
140    basename))
141
142 (define-public (output-framework basename book scopes fields)
143   (output-scopes scopes fields basename)
144   (dump-stencils-as-EPSes
145    (map page-stencil (ly:paper-book-pages book)) book basename))
146   
147
148 ; redefine to imports from framework-ps
149 (define convert-to-pdf convert-to-pdf)
150 (define convert-to-ps convert-to-ps)
151 (define convert-to-png convert-to-png)
152 (define convert-to-tex convert-to-tex)
153 (define convert-to-dvi convert-to-dvi)
154
155