main
Matthew Butterick 5 years ago
parent c636451b9a
commit b443c6768d

@ -1,5 +1,5 @@
#lang debug racket/base
(require racket/class xenomorph sugar/unstable/dict)
(require racket/class xenomorph sugar/unstable/dict)
(provide CFFDict)
#|
@ -7,6 +7,29 @@ approximates
https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
|#
(define CFFDict
(define CFFDict%
(class xenobase%
(super-new)))
(super-new)
(init-field [(@ops ops)])
(field [fields (for/hash ([field (in-list @ops)])
(define key (if (list? (car field))
(bitwise-ior (arithmetic-shift (caar field) 8) (cadar field))
(car field)))
(values key field))])
(define (decodeOperands type stream ret operands)
(error 'decodeOperands-undefined))
(define (encodeOperands type stream ctx operands)
(error 'encodeOperands-undefined))
(define (decode stream parent)
(error 'decode-undefined))
(define (size dict parent [includePointers #true])
(error 'size-undefined))
(define (encode stream dict parent)
(error 'encode-undefined))))
(define (CFFDict [ops null]) (make-object CFFDict% ops))

@ -10,34 +10,34 @@ 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.
(define CFFFont%
(class xenobase%
(super-new)
(define CFFFont
(make-object
(class xenobase%
(super-new)
(define/augride (:decode stream parent)
(define cff-font (make-hasheq))
(define/augride (decode stream parent)
(define cff-font (make-hasheq))
(hash-set! cff-font 'stream stream)
(hash-set! cff-font 'stream stream)
(for ([(k v) (in-hash (decode CFFTop stream))])
(hash-set! cff-font k v))
(for ([(k v) (in-hash (send CFFTop decode 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))
;; 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)]))
#;(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)))
#;(hash-set! cff-font 'isCIDFont (hash-ref (hash-ref cff-font 'topDict) 'ROS))
cff-font))))
(define CFFFont (make-object CFFFont%))
(module+ test
(require rackunit racket/serialize racket/stream "../helper.rkt")
(require rackunit racket/serialize racket/stream fontland/helper)
(define dir (deserialize (read (open-input-file fira-otf-directory-path))))
(define cff (hash-ref (hash-ref dir 'tables) 'CFF_))
(define cff-offset (hash-ref cff 'offset))
@ -47,10 +47,10 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFFont.js
(define ip (open-input-file fira-otf-path))
(define cff-bytes (peek-bytes cff-length cff-offset ip))
(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
#;(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
)

@ -9,7 +9,10 @@
(define (getCFFVersion ctx)
(let loop ([ctx ctx])
(if (and ctx (not (hash-ref ctx 'hdrSize)))
(if (and ctx
(hash? ctx)
(hash-has-key? ctx 'hdrSize)
(not (hash-ref ctx 'hdrSize)))
(loop (hash-ref ctx 'parent))
(if ctx (hash-ref ctx 'x:version) -1))))

@ -173,7 +173,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