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 (COMMAND-NAME . VECTOR-OF-SYMBOLS)."
15 (let* ((raw (ly:kpathsea-gulp-file filename))
16 (string (regexp-substitute/global #f "%[^\n]*" raw 'pre "" 'post))
17 (command (match:substring
18 (string-match "/([^ \t\n\r]*)[ \t\n\r]+[[]" string) 1))
19 (encoding (match:substring (string-match "[[](.*)[]]" string) 1))
20 (ps-lst (string-tokenize encoding))
21 (lst (map (lambda (x) (string->symbol (substring x 1))) ps-lst))
22 (vector (list->vector lst)))
23 (cons command vector)))
25 (define (make-encoding-table encoding-vector)
26 "Return a hash table mapping names to chars. ENCODING-VECTOR is a
29 (let* ((h (make-hash-table 256)))
33 (hash-set! h (vector-ref encoding-vector i)
39 (define-public (reencode-string mapping str)
40 "Apply MAPPING, a vector of [0..256) -> char, to STR"
41 (string-map (lambda (chr)
42 (vector-ref mapping (char->integer chr)))
45 (define-public (make-encoding-mapping input-encoding output-encoding)
46 "Contruct a mapping by applying output-encoding after input-encoding "
50 (let ((new-char (hash-ref
51 output-encoding (vector-ref input-encoding byte) #f)))
52 ;;input-encoding (vector-ref output-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"
63 (let* ((coding (read-encoding-file filename))
66 (tab (make-encoding-table vec)))
69 ;; coding-alist maps NAME -> (list FILENAME COMMAND VECTOR TAB)
74 (cons (cdr x) (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" . "cmr.enc")
84 ("TeX-text-without-f-ligatures" . "0ef0afca.enc")
85 ("Extended-TeX-Font-Encoding---Latin" . "tex256.enc")
86 ("AdobeStandardEncoding" . "8a.enc")
91 ("latin1" . "cork.enc")
94 ("fetaBraces" . "feta-braces-a.enc")
95 ("fetaNumber" . "feta-nummer10.enc")
96 ("fetaMusic" . "feta20.enc")
97 ("parmesanMusic" . "parmesan20.enc"))
100 (define (get-coding coding-name)
101 (let ((entry (assoc-get coding-name coding-alist)))
102 (cons (car entry) (force (cdr entry)))))
104 (define-public (get-coding-filename coding-name)
105 (car (get-coding coding-name)))
107 (define-public (get-coding-command coding-name)
108 (cadr (get-coding coding-name)))
110 (define-public (get-coding-vector coding-name)
111 (caddr (get-coding coding-name)))
113 (define-public (get-coding-table coding-name)
114 (cadddr (get-coding coding-name)))