stub out decode

main
Matthew Butterick 6 years ago
parent 6417107299
commit 333c231f09

@ -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
)

@ -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)))

@ -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)
)

Loading…
Cancel
Save