summaryrefslogtreecommitdiff
path: root/scm
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@xs4all.nl>2005-06-19 14:52:33 +0000
committerHan-Wen Nienhuys <hanwen@xs4all.nl>2005-06-19 14:52:33 +0000
commit2c12af09be46d47b03987d2296f76eb173ebc009 (patch)
tree4d5431824c63ea31b772ae67b8d8bc9f6776698f /scm
parent6cc1535539a6cc5b637173a0581ddff3c09de0bc (diff)
* scm/ps-to-png.scm (make-ps-images): cleanup multipage vs. single
page switch. * make/lilypond-vars.make (LILYPOND_BOOK_FLAGS): set anti-alias-factor for lilypond-book runs. * scm/ps-to-png.scm (scale-down-image): new function. (my-system): new function. (make-ps-images): blow up GS resolution by anti-alias-factor, scale down image by anti-alias-factor. This improves appearance of (make-ps-images): remove showpage. Fixes spurious empty png at end. * scm/lily.scm (lambda): default resolution 116 (8 pixels per space).
Diffstat (limited to 'scm')
-rw-r--r--scm/backend-library.scm4
-rw-r--r--scm/lily.scm3
-rw-r--r--scm/ps-to-png.scm118
3 files changed, 82 insertions, 43 deletions
diff --git a/scm/backend-library.scm b/scm/backend-library.scm
index d7658ef23f..6943b97610 100644
--- a/scm/backend-library.scm
+++ b/scm/backend-library.scm
@@ -85,6 +85,7 @@
))
(use-modules (scm ps-to-png))
+
(define-public (postscript->png resolution paper-size-name name)
;; Do not try to guess the name of the png file,
;; GS produces PNG files like BASE-page%d.png.
@@ -94,7 +95,8 @@
(verbose (ly:get-option 'verbose))
(rename-page-1 #f))
(ly:message (_ "Converting to ~a...") "PNG")
- (make-ps-images name resolution paper-size rename-page-1 verbose)
+ (make-ps-images name resolution paper-size rename-page-1 verbose
+ (ly:get-option 'anti-alias-factor))
(ly:progress "\n")))
(define-public (postprocess-output paper-book module filename formats)
diff --git a/scm/lily.scm b/scm/lily.scm
index f59bc6a61e..06e41889fc 100644
--- a/scm/lily.scm
+++ b/scm/lily.scm
@@ -22,7 +22,8 @@ similar to chord syntax")
;; at 101.178, a staff space is exactly 7 pixels.
;; 115.63 = 8 pixels
;; 86 = 6 pixels
- (resolution 116 "resolution for generating bitmaps")
+ (resolution 90 "resolution for generating bitmaps")
+ (anti-alias-factor 1 "blow up resolution and scale to prevent jaggies in PNG")
(preview-include-book-title #t "include book-titles in preview images.")
(gs-font-load #f
"load fonts via Ghostscript.")
diff --git a/scm/ps-to-png.scm b/scm/ps-to-png.scm
index 18462c724a..83f9160385 100644
--- a/scm/ps-to-png.scm
+++ b/scm/ps-to-png.scm
@@ -78,12 +78,48 @@
(map (lambda (x) (string->number (car x))) (vector->list m)))
#f)))
+
+;; copy of ly:system. ly:* not available via lilypond-ps2png.scm
+(define (my-system be-verbose exit-on-error cmd)
+ (define status 0)
+ (if be-verbose
+ (begin
+ (format (current-error-port) (_ "Invoking `~a'...") cmd)
+ (newline (current-error-port))))
+
+
+ (set! status (system cmd))
+
+ (if (not (= status 0))
+ (begin
+ (format (current-error-port)
+ (format #f (_ "~a exited with status: ~S") "GS" status))
+ (if exit-on-error
+ (exit 1))))
+
+ status)
+
+(define (scale-down-image be-verbose factor file)
+ (let* ((status 0)
+ (percentage (* 100 (/ 1.0 factor)))
+ (old (string-append file ".old")))
+
+ (rename-file file old)
+ (my-system be-verbose
+ #t
+ (format #f "convert -scale '~a%' ~a ~a" percentage old file))
+ (delete-file old)
+ ))
+
(define-public (make-ps-images ps-name . rest)
(let-optional
rest ((resolution 90)
(paper-size "a4")
(rename-page-1? #f)
- (verbose? #f))
+ (verbose? #f)
+ (aa-factor 1)
+ )
+
(let* ((base (basename (re-sub "[.]e?ps" "" ps-name)))
(header (gulp-port (open-file ps-name "r") 10240))
(png1 (string-append base ".png"))
@@ -94,29 +130,16 @@
(output-file (if multi-page? pngn png1))
;;png16m is because Lily produces color nowadays.
- (cmd (if multi-page?
- (format #f "~a\
+ (gs-variable-options
+ (if multi-page?
+ (format #f "-sPAPERSIZE=~a" paper-size)
+ "-dEPSCrop"))
+ (cmd (format #f "~a\
~a\
- -dGraphicsAlphaBits=4\
- -dNOPAUSE\
- -dTextAlphaBits=4\
- -sDEVICE=png16m\
- -sOutputFile=~S\
- -sPAPERSIZE=~a\
- -r~S\
- ~S\
- -c showpage\
- -c quit"
- (search-gs)
- (if verbose? "" "-q")
- output-file paper-size resolution ps-name)
- (format #f "~a\
~a\
- -s\
-dGraphicsAlphaBits=4\
- -dEPSCrop\
- -dNOPAUSE\
-dTextAlphaBits=4\
+ -dNOPAUSE\
-sDEVICE=png16m\
-sOutputFile=~S\
-r~S\
@@ -124,28 +147,41 @@
-c quit"
(search-gs)
(if verbose? "" "-q")
- output-file resolution ps-name)))
- (foo (for-each delete-file (append (dir-re "." png1)
- (dir-re "." pngn-re))))
- (bar (if verbose?
- (begin
- (format (current-error-port) (_ "Invoking `~a'...") cmd)
- (newline (current-error-port)))))
- (baz
- ;; The wrapper on windows cannot handle `=' signs,
- ;; gs has a workaround with #.
- (if (eq? PLATFORM 'windows)
- (begin
- (set! cmd (re-sub "=" "#" cmd))
- (set! cmd (re-sub "-dSAFER " "" cmd)))))
- (status (system cmd)))
- (if (not (= status 0))
+ gs-variable-options
+ output-file
+ (* aa-factor resolution) ps-name))
+ (status 0)
+ (files '()))
+
+ (for-each delete-file (append (dir-re "." png1)
+ (dir-re "." pngn-re)))
+
+ ;; The wrapper on windows cannot handle `=' signs,
+ ;; gs has a workaround with #.
+ (if (eq? PLATFORM 'windows)
(begin
- (map delete-file
- (append (dir-re "." png1) (dir-re "." pngn-re)))
- (format (current-error-port)
- (format #f (_ "~a exited with status: ~S") "GS" status))
+ (set! cmd (re-sub "=" "#" cmd))
+ (set! cmd (re-sub "-dSAFER " "" cmd))))
+
+ (set! status (my-system verbose? #f cmd))
+
+ (set! files
+ (append (dir-re "." png1) (dir-re "." pngn-re)))
+
+ (if (not (= 0 status))
+ (begin
+ (map delete-file files)
(exit 1)))
+
(if (and rename-page-1? multi-page?)
(rename-file (re-sub "%d" "1" pngn) png1))
- (append (dir-re "." png1) (dir-re "." pngn-re)))))
+
+ (set! files
+ (append (dir-re "." png1) (dir-re "." pngn-re)))
+
+
+ (if (not (= 1 aa-factor))
+ (for-each (lambda (f) (scale-down-image verbose? aa-factor f))
+ files))
+
+ files)))