]> git.donarmstrong.com Git - lilypond.git/blob - scm/backend-library.scm
(postscript->png): space before
[lilypond.git] / scm / backend-library.scm
1 ;;;; backend-library.scm -- helpers for the backends.
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c)  2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
9 ;; backend helpers.
10
11 (define-public (ly:system command)
12   (let* ((status 0)
13
14          (silenced
15           (string-append command (if (ly:get-option 'verbose)
16                                      ""
17                                      " > /dev/null 2>&1 "))))
18     
19     (if (ly:get-option 'verbose)
20         (format  (current-error-port) (_ "Invoking `~a'...\n") command))
21     
22     (set! status (system silenced))
23     (if (> status 0)
24         (begin
25           (format (current-error-port)
26                   (_ "Error invoking `~a'. Return value ~a") silenced status)
27           (newline (current-error-port))))))
28
29 (define-public (sanitize-command-option str)
30   (string-append
31    "\""
32    (regexp-substitute/global #f "[^- 0-9,.a-zA-Z'\"\\]" str 'pre 'post)
33    "\""))
34
35 (define-public (postscript->pdf papersizename name)
36   (let* ((cmd (string-append "ps2pdf "
37                              (string-append
38                               " -sPAPERSIZE="
39                               (sanitize-command-option papersizename)
40                               " "
41                               name)))
42          (pdf-name (string-append (basename name ".ps") ".pdf" )))
43
44     (if (access? pdf-name W_OK)
45         (delete-file pdf-name))
46
47     (format (current-error-port) (_ "Converting to `~a'...") pdf-name)
48     (ly:system cmd)))
49
50 (define-public (postscript->png resolution name)
51   (let ((cmd (string-append
52               "ps2png --resolution="
53               (if (number? resolution)
54                   (number->string resolution)
55                   "90 ")
56               (if (ly:get-option 'verbose)
57                   " --verbose "
58                   " ")
59               name)))
60
61     (ly:system cmd)))
62
63 (define-public (postprocess-output paper-book module filename formats)
64   (for-each
65    (lambda (f)
66      ((eval (string->symbol (string-append "convert-to-" f))
67             module)
68       paper-book filename))
69    
70    formats))
71
72 (define-public (completize-formats formats)
73   (define new-fmts '())
74
75   (if (member "png" formats)
76       (set! formats (cons "ps" formats)))
77   (if (member "pdf" formats)
78       (set! formats (cons "ps" formats)))
79
80   (for-each
81    (lambda (x)
82      (if (member x formats) (set! new-fmts (cons x new-fmts))))
83    '("tex" "dvi" "ps" "pdf" "png"))
84
85   new-fmts)
86