diff --git a/fontland/fontland/table/CFF_.rkt b/fontland/fontland/table/CFF_.rkt index 974e8ee1..53fee4fc 100644 --- a/fontland/fontland/table/CFF_.rkt +++ b/fontland/fontland/table/CFF_.rkt @@ -1,5 +1,5 @@ #lang debug racket/base -(require racket/class xenomorph "cff-top.rkt") +(require racket/class racket/list xenomorph "cff-top.rkt") (provide (rename-out (CFFFont CFF_))) #| @@ -8,19 +8,32 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFFont.js |# ;; the CFFFont object acts as the decoder for the `CFF ` table. +;; so it should return a hash. -(struct $CFFFont (stream) #:transparent #:mutable) (define CFFFont (make-object (class xenobase% (super-new) - (define/augride (:decode port parent [len 0]) - (define stream port) - (define start (pos stream)) - (define top (decode CFFTop stream)) - top)))) + (define/augride (:decode stream parent) + (define cff-font (make-hasheq)) + + (hash-set! cff-font 'stream stream) + + (for ([(k v) (in-hash (decode CFFTop stream))]) + (hash-set! cff-font k v)) + + ;; because fontkit depends on overloading 'version key, and we don't + (hash-set! cff-font 'version (hash-ref cff-font 'x:version)) + + #;(when (and (hash-has-key? cff-font 'version) (< (hash-ref cff-font 'version) 2)) + (match (hash-ref cff-font 'topDictIndex) + [(list dict) (hash-set! cff-font 'topDict dict)] + [_ (error 'only-single-font-allowed-in-cff)])) + + #;(hash-set! cff-font 'isCIDFont (hash-ref (hash-ref cff-font 'topDict) 'ROS)) + cff-font)))) (module+ test @@ -33,11 +46,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFFont.js (check-equal? cff-length 164604) (define ip (open-input-file fira-otf-path)) (define cff-bytes (peek-bytes cff-length cff-offset ip)) - (define cff-data (decode CFFFont cff-bytes)) - (check-equal? (hash-ref cff-data 'length) 13) - (check-equal? (hash-ref cff-data 'hdrSize) 4) - (check-equal? (hash-ref cff-data 'offSize) 3) - (check-equal? (hash-ref cff-data 'nameIndex) '("FiraSans-Book")) - (check-equal? (hash-ref cff-data 'length) (string-length (car (hash-ref cff-data 'nameIndex)))) - cff-data + (define cff-font (decode CFFFont cff-bytes)) + (check-equal? (hash-ref cff-font 'length) 13) + (check-equal? (hash-ref cff-font 'hdrSize) 4) + (check-equal? (hash-ref cff-font 'offSize) 3) + (check-equal? (hash-ref cff-font 'nameIndex) '("FiraSans-Book")) + (check-equal? (hash-ref cff-font 'length) (string-length (car (hash-ref cff-font 'nameIndex)))) + cff-font ) \ No newline at end of file diff --git a/fontland/fontland/table/cff-dict.rkt b/fontland/fontland/table/cff-dict.rkt new file mode 100644 index 00000000..4ddeb96c --- /dev/null +++ b/fontland/fontland/table/cff-dict.rkt @@ -0,0 +1,12 @@ +#lang debug racket/base +(require racket/class xenomorph sugar/unstable/dict) +(provide CFFDict) + +#| +approximates +https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js +|# + +(define CFFDict + (class xenobase% + (super-new))) \ No newline at end of file diff --git a/fontland/fontland/table/cff-top.rkt b/fontland/fontland/table/cff-top.rkt index c87b98c0..7b700569 100644 --- a/fontland/fontland/table/cff-top.rkt +++ b/fontland/fontland/table/cff-top.rkt @@ -1,5 +1,7 @@ #lang debug racket/base -(require xenomorph sugar/unstable/dict "cff-index.rkt") +(require xenomorph sugar/unstable/dict + "cff-index.rkt" + "cff-dict.rkt") (provide CFFTop) #| @@ -14,7 +16,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFTop.js 1 (dictify 'hdrSize uint8 'offSize uint8 'nameIndex (CFFIndex (x:string #:length 'length)) - ;;'topDictIndex (CFFIndex CFFTopDict) + ;'topDictIndex (CFFIndex CFFTopDict) ;;'stringIndex (CFFIndex (x:string #:length 'length)) ;;'globalSubrIndex (CFFIndex) )