]> git.donarmstrong.com Git - lilypond.git/commitdiff
* scm/ps-to-png.scm (make-ps-images): cleanup multipage vs. single
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 19 Jun 2005 14:52:33 +0000 (14:52 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 19 Jun 2005 14:52:33 +0000 (14:52 +0000)
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).

ChangeLog
make/lilypond-vars.make
scm/backend-library.scm
scm/lily.scm
scm/ps-to-png.scm

index ff354c8011c2699c8f0b91687c8c7f2d23269c6d..683ea3c586ba34203f8466af15bfb3c89a5f07c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2005-06-19  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * 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/framework-ps.scm (write-preamble): downcase filename before
        string-matching. Should fix .TTF files (as opposed to ttf files)  
 
index b099a45d337b292e56fad0da3632292279831ea1..448515c619192b44f3727a9e620a9e33fd4637a6 100644 (file)
@@ -18,7 +18,7 @@ CONVERT_LY = $(script-dir)/convert-ly.py
 LILYPOND = $(builddir)/lily/$(outconfbase)/lilypond
 LILYPOND_BOOK = $(script-dir)/lilypond-book.py
 LILYPOND_BOOK_INCLUDES = -I $(pwd) -I $(outdir) -I$(input-dir) -I $(input-dir)/regression/ -I $(input-dir)/test/ -I $(input-dir)/tutorial/ -I $(builddir)/mf/$(outconfbase)/  -I $(builddir)/mf/out/
-LILYPOND_BOOK_FLAGS = --process="$(LILYPOND) --backend=eps --formats=ps,png --header=texidoc -I $(srcdir)/input/test -dinternal-type-checking"
+LILYPOND_BOOK_FLAGS = --process="$(LILYPOND) --backend=eps --formats=ps,png --header=texidoc -I $(srcdir)/input/test -dinternal-type-checking -danti-alias-factor=2 "
 
 
 #texi-html for www only:
index d7658ef23fc9b5c033f1a18d32345b0f56d764eb..6943b976105958171199746da36c3b6fcd4677a3 100644 (file)
@@ -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)
index f59bc6a61ed33c83988ec2632b7d1419be52f973..06e41889fcab969527384dcf206f0f81c5601648 100644 (file)
@@ -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.")
index 18462c724a184545b8b1d100e6ce7afa42869853..83f91603859b8c8c85554eb93e7c94c3ed314bdf 100644 (file)
         (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"))
          (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\
  -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)))