new size regime

main
Matthew Butterick 6 years ago
parent 5b9c2e7d0b
commit e1b237fb53

@ -2,6 +2,7 @@
(require xenomorph
"tables.rkt"
racket/dict
racket/class
racket/match
sugar/unstable/dict
racket/string)
@ -40,7 +41,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
(mhash 'tag (unescape-tag tag)
'checkSum 0
'offset (x:void-pointer table-codec table)
'length (size table-codec table))))
'length (send table-codec x:size table))))
(define numTables (length tables))
;; patch from https://github.com/foliojs/fontkit/pull/178
(define max-exponent-for-2 (floor (log numTables 2)))

@ -99,7 +99,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFDict.js
#:when (and val (not (equal? val (fourth field)))))
(define operands (encode-operands (third field) #false ctx val))
(define operand-size (for/sum ([op (in-list operands)])
(size CFFOperand op)))
(send CFFOperand x:size op)))
(define key (if (list? (first field)) (first field) (list (first field))))
(+ operand-size (length key)))
(if include-pointers (hash-ref ctx x:pointer-size-key) 0)))

@ -101,7 +101,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFIndex.js
[else (error 'cff-index-encode-bad-offset!)]))
;; write offset size
(send uint8 x:encode (size offsetType) stream)
(send uint8 x:encode (send offsetType x:size) stream)
;; write elements
(for/fold ([offset 1])

@ -16,7 +16,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/hmtx.js
(hash-ref (hash-ref (hash-ref arr 'parent) 'hhea) 'numberOfMetrics))))))
(module+ test
(require rackunit racket/serialize racket/stream "../helper.rkt")
(require rackunit racket/serialize racket/stream racket/class "../helper.rkt")
;; same as hmtx but doesn't require resolution of function to get length
(define hmtx-test (x:struct
'metrics (x:lazy-array hmtx-entry (λ (t) 229))
@ -29,7 +29,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/hmtx.js
(check-equal? hmtx-length 916)
(define hmtx-bytes (peek-bytes hmtx-length hmtx-offset ip))
(define hmtx-data (decode hmtx-test hmtx-bytes))
(check-equal? (size hmtx-test) (* 229 (size hmtx-entry)))
(check-equal? (send hmtx-test x:size) (* 229 (send hmtx-entry x:size)))
(define H-gid 41) (define OE-gid 142)
(check-equal? (stream-ref (hash-ref hmtx-data 'metrics) H-gid) (make-hasheq '((bearing . 33) (advance . 738))))
(check-equal? (stream-ref (hash-ref hmtx-data 'metrics) OE-gid) (make-hasheq '((bearing . 43) (advance . 993)))))
Loading…
Cancel
Save