]> git.donarmstrong.com Git - lilypond.git/blob - scm/framework-eps.scm
(dump-stencils-as-EPSes): cleanup.
[lilypond.git] / scm / framework-eps.scm
1 ;;;; framework-ps.scm --
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;;
5 ;;;; (c) 2004--2005 Han-Wen Nienhuys <hanwen@cs.uu.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 output-ps)
17              (srfi srfi-1)
18              (srfi srfi-13)
19              (lily))
20
21 (define framework-eps-module (current-module))
22
23
24 (define (widen-left-stencil-edges stencils)
25   "Change STENCILS to use the union for the left extents in every
26 stencil, so LaTeX includegraphics doesn't fuck up the alignment."
27
28   (define left
29     (apply min
30            (map (lambda (stc)
31                   (interval-start (ly:stencil-extent stc X)))
32                 stencils)))
33
34   (map (lambda (stil)
35          
36          (ly:make-stencil
37           (ly:stencil-expr stil)
38           (cons
39            left
40            (cdr (ly:stencil-extent stil X)))
41           (ly:stencil-extent stil Y)
42           ))
43        stencils))
44
45 (define (dump-stencils-as-EPSes stencils book basename)
46   (define paper (ly:paper-book-paper book))
47   (define (dump-infinite-stack-EPS stencils)
48     (let* ((dump-me (stack-stencils Y DOWN 2.0 stencils)))
49       (dump-stencil-as-EPS paper dump-me basename #t)))
50
51   (define (dump-stencils-as-separate-EPS stencils count)
52     (if (pair? stencils)
53         (let* ((line (car stencils))
54                (rest (cdr stencils)))
55
56           (dump-stencil-as-EPS
57            paper
58            line (format "~a-~a" basename count)
59            (ly:output-def-lookup paper 'force-eps-font-include))
60           
61           (dump-stencils-as-separate-EPS rest (1+ count)))))
62
63
64   ;; main body 
65   (let* ((tex-system-name (format "~a-systems.tex" basename))
66          (texi-system-name (format "~a-systems.texi" basename))
67          (tex-system-port (open-output-file tex-system-name))
68          (texi-system-port (open-output-file texi-system-name)))
69     
70     (ly:message (_ "Writing ~a...") tex-system-name)
71     (ly:message (_ "Writing ~a...") texi-system-name)
72
73     (set! stencils (widen-left-stencil-edges stencils))
74     
75     (dump-stencils-as-separate-EPS stencils 1)
76     (for-each (lambda (c)
77                 (if (< 0 c)
78                     (display (format "\\ifx\\betweenLilyPondSystem \\undefined
79   \\linebreak
80 \\else
81   \\betweenLilyPondSystem{~a}
82 \\fi
83 " c) tex-system-port))
84                 (display (format "\\includegraphics{~a-~a.eps}\n"
85                                  basename (1+ c)) tex-system-port)
86                 (display (format "@image{~a-~a}\n"
87                                  basename (1+ c)) texi-system-port))
88               (iota (length stencils)))
89     
90     (display "@c eof - 'eof' is a Makefile marker; do not remove. " texi-system-port)
91     (display "% eof - 'eof' is Makefile marker; do not remove. " tex-system-port)
92     
93     (dump-infinite-stack-EPS stencils))
94     (postprocess-output book framework-eps-module
95                         (format "~a.eps" basename) (ly:output-formats)))
96
97 (define-public (output-classic-framework basename book scopes fields)
98   (output-scopes scopes fields basename)
99   
100   (dump-stencils-as-EPSes
101    (map ly:paper-system-stencil (ly:paper-book-systems book))
102    book
103    basename))
104
105 (define-public (output-framework basename book scopes fields)
106   (output-scopes scopes fields basename)
107   (dump-stencils-as-EPSes (ly:paper-book-pages book) book basename))
108   
109
110 ; redefine to imports from framework-ps
111 (define convert-to-pdf convert-to-pdf)
112 (define convert-to-ps convert-to-ps)
113 (define convert-to-png convert-to-png)
114 (define convert-to-tex convert-to-tex)
115 (define convert-to-dvi convert-to-dvi)
116