resume in cffdict

main
Matthew Butterick 5 years ago
parent 6583b96498
commit 19584a1fbc

@ -1,5 +1,5 @@
#lang debug racket/base
(require racket/class xenomorph sugar/unstable/dict)
(require racket/class racket/match racket/list xenomorph sugar/unstable/dict)
(provide CFFDict)
#|
@ -11,25 +11,64 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
(class x:base%
(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))])
(field [(@fields fields)
(for/hash ([field (in-list @ops)])
(define key (match (car field)
[(list* 0th 1st _) (bitwise-ior (arithmetic-shift 0th 8) 1st)]
[val val]))
(values key field))])
(define (decodeOperands type stream ret operands)
(error 'decodeOperands-undefined))
(cond
[(list? type)
(for/list ([(op i) (in-indexed operands)])
(decodeOperands (list-ref type i) stream ret (list op)))]
[(hash-ref type 'decode #f) => (λ (proc) (proc stream ret operands))]
[else (case type
[(number offset sid) (car operands)]
[(boolean) (if (car operands) #t #f)]
[else operands])]))
(define (encodeOperands type stream ctx operands)
(error 'encodeOperands-undefined))
(error 'cff-dict-encodeOperands-undefined))
(define (decode stream parent)
(error 'decode-undefined))
(define/augment (decode stream parent)
(define end (+ (pos stream) (hash-ref parent 'length)))
(define ret (make-hash))
(define operands null)
(define (size dict parent [includePointers #true])
(error 'size-undefined))
;; define hidden properties
(hash-set! ret x:parent-key parent)
(hash-set! ret x:start-offset-key (pos stream))
(define (encode stream dict parent)
(error 'encode-undefined))))
;; fill in defaults
(for ([(key field) (in-hash @fields)])
(hash-set! ret (second field) (fourth field)))
(let loop ()
(when (< (pos stream) end)
(define b (read-byte stream))
(cond
[(< b 28)
(when (= b 12)
(set! b (bitwise-or (arithmetic-shift b 8) (read-byte stream))))
(define field (hash-ref @fields b #false))
(unless field
(error 'cff-dict-decode (format "unknown operator: ~a" b)))
(define val (decodeOperands (third field) stream ret operands))
(when val
(if (PropertyDescriptor? val)
(loop)))
)
(define/augment (size dict parent [includePointers #true])
(error 'cff-dict-size-undefined))
(define/augment (encode stream dict parent)
(error 'cff-dict-encode-undefined))))
(define (CFFDict [ops null]) (make-object CFFDict% ops))

@ -26,10 +26,10 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFFont.js
;; 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)))

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