]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/framework-ps.scm
Run `make grand-replace'.
[lilypond.git] / scm / framework-ps.scm
index a119024a1dd0cb38c7636aae11f2bb80e7640de8..d6bf44eff2bde58008ce6ad70a2a64501e3f576e 100644 (file)
@@ -2,7 +2,7 @@
 ;;;;
 ;;;;  source file of the GNU LilyPond music typesetter
 ;;;;
-;;;; (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+;;;; (c) 2004--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
 (define-module (scm framework-ps))
 
             (scm clip-region)
             (lily))
 
-(define (format dest . rest)
-  (if (string? dest)
-      (apply simple-format (cons #f (cons dest rest)))
-      (apply simple-format (cons dest rest))))
+(define format ergonomic-simple-format)
 
 (define framework-ps-module (current-module))
 
     "set-ps-scale-to-lily-scale "
     "\n"))
   (ly:outputter-dump-stencil outputter page)
-  (ly:outputter-dump-string outputter "stroke grestore \nshowpage\n"))
+  (ly:outputter-dump-string outputter "stroke grestore\nshowpage\n"))
 
 (define (supplies-or-needs paper load-fonts?)
   (define (extract-names font)
 
 
 (define (write-preamble paper load-fonts? port)
-
-  (define (load-font-via-GS font-name-filename)
-    (define (ps-load-file name)
-      (format
-       (if (string? name)
-          "(~a) (r) file .loadfont\n"
-          "% cannot find font file: ~a\n")
-       name))
+  (define (internal-font? file-name)
+    (or (string-startswith file-name "Emmentaler")
+       (string-startswith file-name "emmentaler")
+       (string-startswith file-name "aybabtu")
+       (string-startswith file-name "Aybabtu")))
+  (define (load-font-via-GS font-name-filename)       
+    (define (ps-load-file file-name)
+      (if (string? file-name)
+         (if (string-contains file-name (ly:get-option 'datadir))
+             (begin
+               (set! file-name (ly:string-substitute (ly:get-option 'datadir) "" file-name))
+               (format "lilypond-datadir (~a) concatstrings (r) file .loadfont" file-name))
+             
+             (format "(~a) (r) file .loadfont\n" file-name))
+         (format "% cannot find font file: ~a\n" file-name)))
 
     (let* ((font (car font-name-filename))
           (name (cadr font-name-filename))
        (if (mac-font? bare-file-name)
           (handle-mac-font name bare-file-name)
           (cond
-           ((or (string-startswith file-name "Emmentaler")
-                (string-startswith file-name "emmentaler")
-                (string-startswith file-name "aybabtu")
-                (string-startswith file-name "Aybabtu"))
+           ((internal-font? file-name)
             (ps-load-file (ly:find-file
                            (format "~a.otf"  file-name))))
            ((string? bare-file-name)
 
       (if (not embed)
          (begin
-           (set! embed "% failed \n")
+           (set! embed "% failed\n")
            (ly:warning (_ "cannot extract file matching ~a from ~a") name filename)))
       embed))
 
 
   (define (load-fonts paper)
     (let* ((fonts (ly:paper-fonts paper))
+
+          ;; todo - doc format of list.
           (all-font-names
            (map
             (lambda (font)
             (sort (apply append all-font-names)
                   (lambda (x y) (string<? (cadr x) (cadr y))))))
 
-          (font-loader (if (ly:get-option 'gs-load-fonts)
-                           load-font-via-GS
-                           load-font))
+          ;; slightly spaghetti-ish: deciding what to load where
+          ;; is smeared out.
+          (font-loader (lambda (name)
+                         (cond
+                          ((ly:get-option 'gs-load-fonts) 
+                           (load-font-via-GS name))
+                          ((ly:get-option 'gs-load-lily-fonts)
+                           (if (or
+                                (string-contains (caddr name) (ly:get-option 'datadir))
+                                (internal-font? (caddr name)))
+
+                               (load-font-via-GS name)
+                               (load-font name)))
+                          (else (load-font name)))))
                         
           (pfas (map font-loader font-names)))
       pfas))
 
   (display "%%BeginProlog\n" port)
+
+  (format port
+           "/lilypond-datadir where {pop} {userdict /lilypond-datadir (~a) put } ifelse"
+           (ly:get-option 'datadir))
+  
   (if load-fonts?
       (for-each
        (lambda (f)
 (define-public (dump-stencil-as-EPS-with-bbox paper dump-me filename
                                              load-fonts
                                              bbox)
-  (define (to-bp-box mmbox)
+  "Create an EPS file from stencil DUMP-ME to FILENAME. BBOX has format
+   (left-x, lower-y, right x, up-y).  If LOAD-FONTS set, include fonts inline." 
+
+  (define (to-rounded-bp-box box)
+    "Convert box to 1/72 inch with rounding to enlarge the box."
     (let* ((scale (ly:output-def-lookup paper 'output-scale))
-          (box (map
-                (lambda (x)
-                  (if (or (nan? x) (inf? x))
-                      0
-                      (inexact->exact
-                       (round (/ (* x scale) (ly:bp 1)))))) mmbox)))
-      
-    (list (car box)
-         (cadr box)
-         (max (1+ (car box)) (caddr box))
-         (max (1+ (cadr box)) (cadddr box))
+          (strip-non-number (lambda (x)
+                              (if (or (nan? x) (inf? x)) 0.0 x)))
+          (directed-round (lambda (x rounder)
+                            (inexact->exact
+                             (rounder (/ (* (strip-non-number x) scale)
+                                         (ly:bp 1)))))))
+      (list (directed-round (car box) floor)
+           (directed-round (cadr box) floor)
+           (directed-round (max (1+ (car box)) (caddr box)) ceiling)
+           (directed-round (max (1+ (cadr box)) (cadddr box)) ceiling)
          )))
 
   (let* ((outputter (ly:make-paper-outputter
                     'ps))
 
         (port (ly:outputter-port outputter))
-        (rounded-bbox (to-bp-box bbox))
+        (rounded-bbox (to-rounded-bp-box bbox))
         (port (ly:outputter-port outputter))
         (header (eps-header paper rounded-bbox load-fonts)))
 
     (display header port)
     (write-preamble paper load-fonts port)
-    (display "gsave set-ps-scale-to-lily-scale \n" port)
+    (display "gsave set-ps-scale-to-lily-scale\n" port)
     (ly:outputter-dump-stencil outputter dump-me)
     (display "stroke grestore\n%%Trailer\n%%EOF\n" port)
     (ly:outputter-close outputter)))
           ((xext (car ext-system-pair))
            (paper-system (cdr ext-system-pair))
            (yext (paper-system-extent paper-system Y))
-           (bbox (list (car  xext) (car yext)
+           (bbox (list (car xext) (car yext)
                        (cdr xext) (cdr yext)))
            (filename (if (< 0 count)
                          (format "~a-~a" basename count)
   (ly:error (_ "\nThe PostScript backend does not support the system-by-system 
 output. For that, use the EPS backend instead,
 
-  lilypond -eps FILE
+  lilypond -dbackend=eps FILE
 
 If have cut & pasted a lilypond fragment from a webpage, be sure
 to only remove anything before