1 ;;;; encoding.scm -- font encoding
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
9 ;; #(display (reencode-string "adobe" "latin1" "hellö fóebär"))
13 (define-public (read-encoding-file filename)
14 "Read .enc file, return as a vector of symbols."
15 (let* ((raw (ly:kpathsea-gulp-file filename))
16 (string (regexp-substitute/global #f "%[^\n]*" raw 'pre "" 'post))
17 (start (string-index string #\[))
18 (end (string-index string #\]))
19 (ps-lst (string-tokenize (substring string (+ start 1) end)))
20 (lst (map (lambda (x) (substring x 1)) ps-lst)))
23 (define (make-encoding-table encoding-vector)
24 "Return a hash table mapping names to chars. ENCODING-VECTOR is a
27 (let* ((h (make-hash-table 256)))
31 (hash-set! h (vector-ref encoding-vector i)
37 (define-public (reencode-string permutation str)
38 "Apply PERMUTATION, a vector of [0..256) -> char, to STR"
39 (string-map (lambda (chr)
40 (vector-ref permutation (char->integer chr)))
43 (define-public (make-encoding-permutation input-encoding
46 "Contruct a permutation by applying output-encoding after input-encoding "
51 ((new-char (hash-ref output-encoding
52 (vector-ref input-encoding byte) #f)))
54 ;; substitute space for unknown characters.
61 (define (get-coding-from-file filename)
62 "Read FILENAME, return a list containing encoding vector and table"
65 ((vec (read-encoding-file filename))
66 (tab (make-encoding-table vec)))
69 ;; coding-alist maps NAME -> (list VECTOR TAB)
74 (delay (get-coding-from-file (cdr x)))))
78 ("TeX typewriter text" . "09fbbfac.enc") ;; cmtt10
79 ("TeX math symbols" . "10037936.enc") ;; cmbsy
80 ("ASCII caps and digits" . "1b6d048e.enc") ;; cminch
81 ("TeX math italic" . "aae443f0.enc") ;; cmmi10
82 ("TeX extended ASCII" . "d9b29452.enc")
83 ("TeX text" . "f7b6d320.enc")
84 ("TeX text without f-ligatures" . "0ef0afca.enc")
85 ("Extended TeX Font Encoding - Latin" . "tex256.enc")
89 ;; FIXME: find full Adobe; for testing -- almost Adobe:
92 ("latin1" . "cork.enc")
95 ("feta braces" . "feta-braces-a.enc")
96 ("feta number" . "feta-nummer10.enc")
97 ("feta music" . "feta20.enc")
98 ("parmesan music" . "parmesan20.enc"))
101 (define (get-coding coding-name)
102 (force (assoc-get coding-name coding-alist )))
104 (define-public (get-coding-vector coding-name)
105 (car (get-coding coding-name)))
107 (define-public (get-coding-table coding-name)
108 (cadr (get-coding coding-name)))
112 ;;; what's this for? --hwn
113 ;; (define-public (encoded-index font-coding input-coding code)
114 ;; This was used by simplistic first incarnation of reencode-string --jcn