]> git.donarmstrong.com Git - lilypond.git/blob - scm/framework-eps.scm
* The grand 2005-2006 replace.
[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@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 line (format "~a-~a" basename count)
58            (ly:output-def-lookup paper 'force-eps-font-include))
59           
60           (dump-stencils-as-separate-EPS rest (1+ count)))))
61
62
63   ;; main body 
64   (let* ((tex-system-name (format "~a-systems.tex" basename))
65          (texi-system-name (format "~a-systems.texi" basename))
66          (tex-system-port (open-output-file tex-system-name))
67          (texi-system-port (open-output-file texi-system-name)))
68     
69     (ly:message (_ "Writing ~a...") tex-system-name)
70     (ly:message (_ "Writing ~a...") texi-system-name)
71
72     (set! stencils (widen-left-stencil-edges stencils))
73     
74     (dump-stencils-as-separate-EPS stencils 1)
75     (for-each (lambda (c)
76                 (if (< 0 c)
77                     (display (format "\\ifx\\betweenLilyPondSystem \\undefined
78   \\linebreak
79 \\else
80   \\betweenLilyPondSystem{~a}
81 \\fi
82 " c) tex-system-port))
83                 (display (format "\\includegraphics{~a-~a.eps}\n"
84                                  basename (1+ c)) tex-system-port)
85                 (display (format "@image{~a-~a}\n"
86                                  basename (1+ c)) texi-system-port))
87               (iota (length stencils)))
88     
89     (display "@c eof - 'eof' is a Makefile marker; do not remove. " texi-system-port)
90     (display "% eof - 'eof' is Makefile marker; do not remove. " tex-system-port)
91     
92     (dump-infinite-stack-EPS stencils))
93     (postprocess-output book framework-eps-module
94                         (format "~a.eps" basename) (ly:output-formats)))
95
96 (define-public (output-classic-framework basename book scopes fields)
97   (output-scopes scopes fields basename)
98   
99   (dump-stencils-as-EPSes
100    (map paper-system-stencil (ly:paper-book-systems book))
101    book
102    basename))
103
104 (define-public (output-framework basename book scopes fields)
105   (output-scopes scopes fields basename)
106   (dump-stencils-as-EPSes (ly:paper-book-pages book) book basename))
107   
108
109 ; redefine to imports from framework-ps
110 (define convert-to-pdf convert-to-pdf)
111 (define convert-to-ps convert-to-ps)
112 (define convert-to-png convert-to-png)
113 (define convert-to-tex convert-to-tex)
114 (define convert-to-dvi convert-to-dvi)
115