]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/output-ps.scm
* scm/output-ps.scm (header): Papersize from paper.
[lilypond.git] / scm / output-ps.scm
index a2ef3d9512dff979b8b72276dbe54b592b0b8f1b..3635daf6b0ab4a012bb46b92ff4a2cdfb2b58cef 100644 (file)
@@ -1,4 +1,4 @@
-;;;; output-ps.scm -- implement Scheme output routines for PostScript
+;;;; output-ps.scm -- implement Scheme output interface for PostScript
 ;;;;
 ;;;;  source file of the GNU LilyPond music typesetter
 ;;;; 
@@ -9,11 +9,7 @@
 ;;;;       input/test/title-markup.ly
 ;;;; 
 ;;;; TODO:
-;;;;   * papersize in header
-;;;;   * special characters, encoding.
-;;;;     + implement encoding switch (switches?  input/output??),
-;;;;     + move encoding definitions to ENCODING.ps files, or
-;;;;     + find out which program's PS(?) encoding code we can use?
+;;;;   * %% Papersize in (header ...)
 ;;;;   * text setting, kerning.
 ;;;;   * document output-interface
 
             tuplet
             polygon
             draw-line
-            between-system-string
             define-origin
             no-origin
             start-page
             stop-page
-            )
-)
+            ))
+
 (use-modules (guile)
             (ice-9 regex)
+            (srfi srfi-1)
             (srfi srfi-13)
             (lily))
 
 ;;; Global vars
-;; alist containing fontname -> fontcommand assoc (both strings)
 (define page-count 0)
 (define page-number 0)
 
-;; /lilypondpaperoutputscale 1.75729901757299 def
-;;/lily-output-units 2.83464  def  %% milimeter
-;;/output-scale lilypondpaperoutputscale lily-output-units mul def
-;;
-;; output-scale = 1.75729901757299 * 2.83464 = 4.9813100871731003736
-
-(define OUTPUT-SCALE 4.98)
-(define TOP-MARGIN 0)
-
 ;;; helper functions, not part of output interface
 (define (escape-parentheses s)
   (regexp-substitute/global #f "(^|[^\\])([\\(\\)])" s 'pre 1 "\\" 2 'post))
@@ -88,8 +74,6 @@
   (cons (+ (car a) (car b))
        (+ (cdr a) (cdr b))))
 
-;;    ("ecmb12" . "ISOLatin1Encoding")))
-                
 (define (ps-encoding text)
   (escape-parentheses text))
 
    (ly:number->string (* 10 thick))
    " ] 0 draw_dashed_slur"))
 
-(define (font-command font)
-  (string-append
-   "magfont"
-   (string-encode-integer
-    (hashq (ly:font-name font) 1000000))
-   "m"
-   (string-encode-integer
-    (inexact->exact (round (* 1000 (ly:font-magnification font)))))))
+;; FIXME -- now that we can have ENCODING == #f, this can be
+;; simplified, esp OVERRIDE-CODING-COMMAND
+(define (font-command font . override-coding-command)
+  (let* ((name (ly:font-filename font))
+        (magnify (ly:font-magnification font))
+        (coding-alist (ly:font-encoding-alist font))
+        (input-encoding (assoc-get 'input-name coding-alist))
+        (font-encoding (assoc-get 'output-name coding-alist))
+        (coding-command (if (not (null? override-coding-command))
+                            (car override-coding-command)
+                            (if font-encoding
+                                (get-coding-command font-encoding)
+                                #f))))
+
+    (string-append
+     "magfont" (string-encode-integer (hashq  name 1000000))
+     "m" (string-encode-integer (inexact->exact (round (* 1000 magnify))))
+     (if (or (not font-encoding) (equal? input-encoding font-encoding)) ""
+        (string-append "e" coding-command)))))
 
 (define (define-fonts paper font-list)
+  
   (define (define-font command fontname scaling)
     (string-append
      "/" command " { /" fontname " findfont "
-     ;; FIXME
      (ly:number->string scaling) " output-scale div scalefont } bind def\n"))
-     ;;(ly:number->string scaling) " scalefont } bind def\n"))
 
-  (define (reencode-font raw encoding command)
-    (string-append
-     raw " " encoding " /" command " reencode-font\n"
-     "/" command "{ /" command " findfont 1 scalefont } bind def\n"))
-         
-  ;; frobnicate NAME to jibe with external definitions.
-  (define (possibly-mangle-fontname fontname)
+  (define (reencode-font plain encoding command)
+    (let ((coding-vector (get-coding-command encoding)))
+      (string-append
+       plain " " coding-vector " /" command " reencode-font\n"
+       "/" command "{ /" command " findfont 1 scalefont } bind def\n")))
+  
+  (define (guess-ps-fontname basename)
+    "We do not have the FontName, try to guess is from basename."
     (cond
-     ((tex-font? fontname)
-      ;; FIXME: we need proper Fontmap for CM fonts, like so:
-      ;; /CMR10 (cmr10.pfb); 
-      ;; (string-upcase fontname)
-      (string-append fontname ".pfb"))
-     ((or (equal? (substring fontname 0 4) "feta")
-         (equal? (substring fontname 0 4) "parm"))
-      (regexp-substitute/global
-       #f "(feta|parmesan)([a-z-]*)([0-9]+)"
-       fontname 'pre "GNU-LilyPond-" 1 2 "-" 3 'post))
-     (else fontname)))
-                        
+     ((tex-font? basename)
+      ;; FIXME: we need proper Fontmap for the bluesky CM*, EC* fonts.
+      ;; Only the fonts that we trace in mf/ are in our own FontMap.
+      (string-append basename ".pfb"))
+     (else (string-append basename ".pfa"))
+     ))
+
   (define (font-load-command paper font)
-    (let* ((command (font-command font))
-          (fontname (ly:font-name font))
-          (mangled (possibly-mangle-fontname fontname))
+    (let* ((specced-font-name (ly:font-name font))
+          (fontname (if specced-font-name
+                        specced-font-name
+                        (guess-ps-fontname (ly:font-filename font))))
+          
           (coding-alist (ly:font-encoding-alist font))
-          (encoding (assoc-get 'input-name coding-alist))
+          (input-encoding (assoc-get 'input-name coding-alist))
+          (font-encoding (assoc-get 'output-name coding-alist))
+          (command (font-command font))
+          ;; FIXME -- see (font-command )
+          (plain (if font-encoding
+                     (font-command font . (get-coding-command font-encoding))
+                     command))
           (designsize (ly:font-design-size font))
           (magnification (* (ly:font-magnification font)))
           (ops (ly:paper-lookup paper 'outputscale))
           (scaling (* ops magnification designsize)))
 
-      (if
-       #f
-       (begin
-        (newline)
-        (format (current-error-port) "fontname ~S\n" fontname)
-        (format (current-error-port) "command ~S\n" command)
-        (format (current-error-port) "encoding name ~S\n" encoding)
-        (format (current-error-port) "mangled ~S\n" mangled)
-        (format (current-error-port) "designsize ~S\n" designsize)
-        (format (current-error-port) "magnification ~S\n" magnification)
-        (format (current-error-port) "ops ~S\n" ops)
-        (format (current-error-port) "scaling ~S\n" scaling)))
-      
-      (if (equal? encoding "AdobeStandardEncoding")
-         (define-font command mangled scaling)
-         ;; FIXME: should rather tag encoded font
-         (let ((raw (string-append command "-raw"))
-               (vector (get-coding-command encoding)))
-           (string-append
-            (define-font raw mangled scaling)
-            (reencode-font raw vector command))))))
+      (string-append
+       (define-font plain fontname scaling)
+       (if (or (equal? input-encoding font-encoding)
+              ;; guh
+              (equal? font-encoding "fetaBraces")
+              (equal? font-encoding "fetaNumber")
+              (equal? font-encoding "fetaMusic")
+              (equal? font-encoding "parmesanMusic"))
+              ""
+          (reencode-font plain input-encoding command)))))
   
   (define (font-load-encoding encoding)
     (let ((filename (get-coding-filename encoding)))
                               (assoc-get 'input-name
                                          (ly:font-encoding-alist x)))
                             font-list))
-        (encodings (uniq-list (sort-list encoding-list string<?))))
-    
+        (encodings (uniq-list (sort-list (filter string? encoding-list)
+                                         string<?))))
+
     (string-append
      (apply string-append (map font-load-encoding encodings))
      (apply string-append
-           (map (lambda (x) (font-load-command paper x)) fonts)))))
+           (map (lambda (x) (font-load-command paper x)) font-list)))))
 
 (define (define-origin file line col) "")
 
   (string-append (ly:numbers->string (list breapth width depth height))
                 " draw_box"))
 
-(define (header creator time-stamp page-count-)
+(define (header creator time-stamp paper page-count- classic?)
   (set! page-count page-count-)
   (set! page-number 0)
   (string-append
    "%%Creator: " creator " " time-stamp "\n"
    "%%Pages: " (number->string page-count) "\n"
    "%%PageOrder: Ascend\n"
-   ;; FIXME: TODO get from paper
-   ;; "%%DocumentPaperSizes: a6\n"
+   "%%DocumentPaperSizes: " (ly:paper-lookup paper 'papersize) "\n"
    ;;(string-append "GNU LilyPond (" (lilypond-version) "), ")
    ;;     (strftime "%c" (localtime (current-time))))
    ;; FIXME: duplicated in every backend
     (ly:numbers->string
      (list x y width height blotdiam)) " draw_round_box"))
 
-(define (new-start-system origin dim)
+(define (start-system origin dim)
   (string-append
    "\n" (ly:number-pair->string origin) " start-system\n"
    "{\n"
    (ly:numbers->string (list breapth width depth height))
    " draw_box" ))
 
-(define (stop-system)
+(define (stop-system last?)
   "} stop-system\n")
 
-(define stop-last-system stop-system)
-
 (define (symmetric-x-triangle thick w h)
   (string-append
    (ly:numbers->string (list h w thick))
    " draw_symmetric_x_triangle"))
 
 (define (text font s)
-  
-;;  (string-append "(" (escape-parentheses s) ") show "))
-  (string-append
-
-   (font-command font) " setfont " 
-   "(" (ps-encoding s) ") show"))
+  (let*
+      
+      (
+       ;; ugh, we should find a better way to
+       ;; extract the hsbw for /space from the font.
+       
+       (space-length (cdar (ly:text-dimension font "t"))) 
+       (commands '())
+       (add-command (lambda (x) (set! commands (cons x commands)))) )
+
+    (string-fold
+     (lambda (chr word)
+       "Translate space as into moveto, group the rest in words."
+       (if (and (< 0 (string-length word))
+               (equal? #\space  chr))
+          (add-command 
+           (string-append "(" (ps-encoding word) ") show\n")))
+
+       (if (equal? #\space  chr)
+          (add-command  (string-append (number->string space-length) " 0.0 rmoveto ")) )
+       
+       (if (equal? #\space  chr)
+          ""
+          (string-append word (make-string 1 chr))))
+     ""
+     (string-append  s " "))
 
+    (string-append
+     (font-command font) " setfont "
+     (string-join (reverse commands)))
+    ))
+  
 (define (unknown) 
   "\n unknown\n")