]> git.donarmstrong.com Git - lilypond.git/blob - scm/backend-library.scm
* lily/kpath.cc:
[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          (silenced
14           (string-append command (if (ly:get-option 'verbose)
15                                      ""
16                                      " > /dev/null 2>&1 "))))
17
18     (if (ly:get-option 'verbose)
19         (format (current-error-port) (_ "Invoking `~a'...") command))
20     
21     (set! status (system silenced))
22     (if (> status 0)
23         (begin
24           (format (current-error-port) (_ "`~a' failed (~a)") command status)
25           (newline (current-error-port))))))
26
27 (define-public (sanitize-command-option str)
28   (string-append
29    "\""
30    (regexp-substitute/global #f "[^- 0-9,.a-zA-Z'\"\\]" str 'pre 'post)
31    "\""))
32
33 (define-public (postscript->pdf papersizename name)
34   (let* ((cmd (string-append "ps2pdf "
35                              (string-append
36                               " -sPAPERSIZE="
37                               (sanitize-command-option papersizename)
38                               " "
39                               name)))
40          (pdf-name (string-append (basename name ".ps") ".pdf" )))
41
42     (if (access? pdf-name W_OK)
43         (delete-file pdf-name))
44
45     (format (current-error-port) (_ "Converting to `~a'...") pdf-name)
46     (ly:system cmd)))
47
48 (define-public (postscript->png resolution name)
49   (let ((cmd (string-append
50               "ps2png --resolution="
51               (if (number? resolution)
52                   (number->string resolution)
53                   "90 ")
54               (if (ly:get-option 'verbose)
55                   " --verbose "
56                   " ")
57               name)))
58
59     (ly:system cmd)))
60
61 (define-public (postprocess-output paper-book module filename formats)
62   (for-each
63    (lambda (f)
64      ((eval (string->symbol (string-append "convert-to-" f))
65             module)
66       paper-book filename))
67    
68    formats))
69
70 (define-public (completize-formats formats)
71   (define new-fmts '())
72
73   (if (member "png" formats)
74       (set! formats (cons "ps" formats)))
75   (if (member "pdf" formats)
76       (set! formats (cons "ps" formats)))
77
78   (for-each
79    (lambda (x)
80      (if (member x formats) (set! new-fmts (cons x new-fmts))))
81    '("tex" "dvi" "ps" "pdf" "png"))
82
83   new-fmts)
84