|
|
|
@ -12,29 +12,33 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
|
|
|
|
|
(class x:base%
|
|
|
|
|
(super-new)
|
|
|
|
|
(init-field [(@ops ops)])
|
|
|
|
|
(define (op->key op)
|
|
|
|
|
(match (car op)
|
|
|
|
|
[(list* 0th 1st _) (bitwise-ior (arithmetic-shift 0th 8) 1st)]
|
|
|
|
|
[val val]))
|
|
|
|
|
(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 key (op->key field))
|
|
|
|
|
(values key field))])
|
|
|
|
|
|
|
|
|
|
(define (decodeOperands type stream ret operands)
|
|
|
|
|
(match type
|
|
|
|
|
[(? list?)
|
|
|
|
|
(for/list ([(op i) (in-indexed operands)])
|
|
|
|
|
(decodeOperands (list-ref type i) stream ret (list op)))]
|
|
|
|
|
(decodeOperands (list-ref type i) stream ret (list op)))]
|
|
|
|
|
[(? xenomorphic?) (decode type stream #:parent ret operands)]
|
|
|
|
|
[(or 'number 'offset 'sid) (car operands)]
|
|
|
|
|
['boolean (if (car operands) #t #f)]
|
|
|
|
|
[_ operands]))
|
|
|
|
|
|
|
|
|
|
(define (encodeOperands type stream ctx operands)
|
|
|
|
|
#R 'in-encode-operands
|
|
|
|
|
#R stream
|
|
|
|
|
(cond
|
|
|
|
|
[(list? type)
|
|
|
|
|
(for/list ([(op i) (in-indexed operands)])
|
|
|
|
|
(car (encodeOperands (list-ref type i) stream ctx op)))]
|
|
|
|
|
[(xenomorphic? type) (encode type operands stream #:parent ctx)]
|
|
|
|
|
(car (encodeOperands (list-ref type i) stream ctx op)))]
|
|
|
|
|
[(xenomorphic? type) #R type (send type encode operands #R stream ctx)]
|
|
|
|
|
[(number? operands) (list operands)]
|
|
|
|
|
[(boolean? operands) (list (if operands 1 0))]
|
|
|
|
|
[(list? operands) operands]
|
|
|
|
@ -55,7 +59,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
|
|
|
|
|
|
|
|
|
|
;; fill in defaults
|
|
|
|
|
(for ([(key field) (in-hash @fields)])
|
|
|
|
|
(hash-set! ret (second field) (fourth field)))
|
|
|
|
|
(hash-set! ret (second field) (fourth field)))
|
|
|
|
|
|
|
|
|
|
(let loop ()
|
|
|
|
|
(when (< (pos stream) end)
|
|
|
|
@ -82,6 +86,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
|
|
|
|
|
|
|
|
|
|
(augment [@size size])
|
|
|
|
|
(define (@size dict parent [includePointers #true])
|
|
|
|
|
#R 'in-cff-dict-size
|
|
|
|
|
|
|
|
|
|
(define ctx
|
|
|
|
|
(mhasheq x:parent-key parent
|
|
|
|
|
x:val-key dict
|
|
|
|
@ -90,26 +96,32 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
|
|
|
|
|
|
|
|
|
|
(define len 0)
|
|
|
|
|
|
|
|
|
|
(for* ([(k field) (in-hash @fields)]
|
|
|
|
|
(for* ([k (in-list (sort (hash-keys @fields) <))]
|
|
|
|
|
[field (in-value (hash-ref @fields k))]
|
|
|
|
|
[val (in-value (hash-ref dict (list-ref field 1)))]
|
|
|
|
|
#:unless (or (not val) (equal? val (list-ref field 3))))
|
|
|
|
|
(define operands (encodeOperands (list-ref field 2) #f ctx val))
|
|
|
|
|
(set! len (+ len
|
|
|
|
|
(for/sum ([op (in-list operands)])
|
|
|
|
|
(size CFFOperand op))))
|
|
|
|
|
|
|
|
|
|
(define key (if (list? (list-ref field 0))
|
|
|
|
|
(list-ref field 0)
|
|
|
|
|
(list (list-ref field 0))))
|
|
|
|
|
(set! len (+ len (length key))))
|
|
|
|
|
#:unless (let ([ res (or (not val) (equal? val (list-ref field 3)))])
|
|
|
|
|
(and res #R 'skipped #R k)))
|
|
|
|
|
#R k
|
|
|
|
|
#R len
|
|
|
|
|
(define operands (encodeOperands (list-ref field 2) #f ctx val))
|
|
|
|
|
#R operands
|
|
|
|
|
(set! len (+ len
|
|
|
|
|
(for/sum ([op (in-list operands)])
|
|
|
|
|
#R (size CFFOperand op))))
|
|
|
|
|
|
|
|
|
|
(define key (if (list? (list-ref field 0))
|
|
|
|
|
(list-ref field 0)
|
|
|
|
|
(list (list-ref field 0))))
|
|
|
|
|
(set! len (+ len #R (length key))))
|
|
|
|
|
|
|
|
|
|
(when includePointers
|
|
|
|
|
(set! len (+ len (hash-ref ctx x:pointer-size-key))))
|
|
|
|
|
|
|
|
|
|
len)
|
|
|
|
|
#R 'final-len
|
|
|
|
|
#R len)
|
|
|
|
|
|
|
|
|
|
(augment [@encode encode])
|
|
|
|
|
(define (@encode stream dict parent)
|
|
|
|
|
(define (@encode dict stream parent)
|
|
|
|
|
(error 'cff-dict-encode-undefined))))
|
|
|
|
|
|
|
|
|
|
(define (CFFDict [ops null]) (make-object CFFDict% ops))
|