]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/output-ps.scm
(font-command): Fix, again.
[lilypond.git] / scm / output-ps.scm
index bf8056091038d8b8bcac0b7f204b6b791e51c18f..681db247763dafc8bcc85217104674a346676b03 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 . override-coding-command)
+(define (font-command font . override-coding)
   (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)
-                            (get-coding-command font-encoding))))
+        (coding-command (if (null? override-coding)
+                            (if (equal? input-encoding font-encoding)
+                                #f font-encoding)
+                            (car override-coding))))
+
+    ;; FIXME:  now feta stuff has feta* input-encoding (again?)
+    ;;(format (current-error-port) "FONT: ~S, ~S\n" name font-encoding)
+    ;;(format (current-error-port) "INPUT: ~S\n" input-encoding)
+    (if (and coding-command (equal? (substring coding-command 0 4) "feta"))
+       (set! coding-command #f))
 
     (string-append
      "magfont" (string-encode-integer (hashq  name 1000000))
      "m" (string-encode-integer (inexact->exact (round (* 1000 magnify))))
-     (if (equal? input-encoding font-encoding) ""
-        (string-append "e" coding-command)))))
+     (if (not coding-command) "" (string-append "e" coding-command)))))
 
 (define (define-fonts paper font-list)
   
           (coding-alist (ly:font-encoding-alist font))
           (input-encoding (assoc-get 'input-name coding-alist))
           (font-encoding (assoc-get 'output-name coding-alist))
-          (plain (font-command font (get-coding-command font-encoding)))
           (command (font-command font))
+          ;; FIXME -- see (font-command )
+          (plain (font-command font #f))
           (designsize (ly:font-design-size font))
           (magnification (* (ly:font-magnification font)))
           (ops (ly:paper-lookup paper 'outputscale))
                               (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
   (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")