main
Matthew Butterick 5 years ago
parent d05f4a1ed1
commit 04632ba102

@ -74,13 +74,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/CFFGlyph.js
(define open #false)
(define gsubrs (match (hash-ref cff 'globalSubrIndex (vector))
[(? list? vals) (list->vector vals)]
[(list) (vector)]
[vec vec]))
(define gsubrsBias (bias this gsubrs))
(define privateDict (or (privateDictForGlyph cff (glyph-id this)) (make-hash)))
(define subrs (match (hash-ref privateDict 'Subrs (vector))
[(? list? vals) (list->vector vals)]
[(list) (vector)]
[vec vec]))
(define subrsBias (bias this subrs))

@ -1,4 +1,4 @@
#lang racket/base
#lang debug racket/base
(require racket/class
racket/match
racket/list
@ -25,13 +25,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
(field [(@fields fields)
(for/hash ([field (in-list @ops)])
(values (op->key field) field))])
(values (op->key field) field))])
(define (decode-operands type stream ret operands)
(match type
[(? list?) (for/list ([op (in-list operands)]
[subtype (in-list type)])
(decode-operands subtype stream ret (list op)))]
(decode-operands subtype stream ret (list op)))]
[(? xenomorphic?) (send type x:decode stream ret operands)]
[(or 'number 'offset 'sid) (car operands)]
['boolean (if (car operands) #t #f)]
@ -42,7 +42,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
[(? list?)
(for/list ([op (in-list operands)]
[subtype (in-list type)])
(car (encode-operands subtype stream ctx op)))]
(car (encode-operands subtype stream ctx op)))]
[(? xenomorphic?) type (send type x:encode operands stream ctx)]
[_ (match operands
[(? number?) (list operands)]
@ -63,7 +63,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 ([operands null])
(when (< (pos stream) end)
@ -98,11 +98,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
[field (in-value (dict-ref @fields k))]
[val (in-value (dict-ref dict (list-ref field 1) #false))]
#:unless (or (not val) (equal? val (list-ref field 3))))
(define operands (encode-operands (list-ref field 2) #false ctx val))
(define operand-size (for/sum ([op (in-list operands)])
(size CFFOperand op)))
(define key (if (list? (car field)) (car field) (list (car field))))
(+ operand-size (length key)))
(define operands (encode-operands (list-ref field 2) #false ctx val))
(define operand-size (for/sum ([op (in-list operands)])
(size CFFOperand op)))
(define key (if (list? (car field)) (car field) (list (car field))))
(+ operand-size (length key)))
(if include-pointers (hash-ref ctx x:pointer-size-key) 0)))
(define/augment (x:encode dict stream parent)
@ -116,16 +116,16 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
(hash-set! ctx x:pointer-offset-key (+ (pos stream) (x:size dict ctx #false)))
(for ([field (in-list @ops)])
(define val (dict-ref dict (list-ref field 1) #false))
(cond
[(or (not val) (equal? val (list-ref field 3)))]
[else
(define operands (encode-operands (list-ref field 2) stream ctx val))
(for ([op (in-list operands)])
(send CFFOperand x:encode op stream))
(define key (if (list? (car field)) (car field) (list (car field))))
(for ([op (in-list key)])
(encode uint8 op stream))]))
(match-define (list f0 f1 f2 f3) field)
(match (dict-ref dict f1 #false)
[(or #false (== f3)) (void)]
[val
(define operands (encode-operands f2 stream ctx val))
(for ([op (in-list operands)])
(send CFFOperand x:encode op stream))
(define key (if (list? f0) f0 (list f0)))
(for ([op (in-list key)])
(encode uint8 op stream))]))
(let loop ([i 0])
(when (< i (length (hash-ref ctx x:pointers-key)))

@ -44,4 +44,5 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFPrivateDict.js
(21 nominalWidthX number 0)
(22 vsindex number 0)
(23 blend ,CFFBlendOp #false)
(19 Subrs ,(CFFPointer (CFFIndex) #:relative-to 'local) ,null))))
(19 Subrs ,(CFFPointer (CFFIndex) #:relative-to 'local) ,null))))
;; todo: why can't the subrs default value be `(vector)`?
Loading…
Cancel
Save