Matthew Butterick 8 years ago
parent b313511db8
commit 461ea0bd53

@ -22,7 +22,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
(hash-set! this-res 'tables new-tables-val))
(define/override (preEncode this-val stream)
(report 'start-directory-preEncode)
(define tables empty)
(for ([(tag table) (in-hash (· this-val tables))])
(when table
@ -32,7 +32,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
'checkSum 0
'offset #xdeadbeef ; todo
'length (let ([tag (hash-ref table-decoders tag (λ () (raise-argument-error 'directory:preEncode "valid table tag" tag)))])
(report* tag table (send tag size table)))))))
(send tag size table))))))
(define numTables (length tables))
(define searchRange (* (floor (log (/ numTables (log 2)))) 16))
(define entrySelector (floor (/ searchRange (log 2))))
@ -45,7 +45,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
'searchRange searchRange
'entrySelector rangeShift
'rangeShift rangeShift)
(report 'end-directory-preEncode)))
))
(define Directory (make-object RDirectory

@ -15,9 +15,9 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/hmtx.js
(define hmtx (+Rhmtx
(dictify
'metrics (+LazyArray HmtxEntry (λ (t) (· (send (· t parent) _getTable 'hhea) numberOfMetrics)))
'bearing (+LazyArray int16be (λ (t) (- (· (send (· t parent) _getTable 'maxp) numGlyphs)
(· (send (· t parent) _getTable 'hhea) numberOfMetrics)))))))
'metrics (+LazyArray HmtxEntry (λ (this-array) (· (send (· this-array parent) _getTable 'hhea) numberOfMetrics)))
'bearings (+LazyArray int16be (λ (this-array) (- (· (send (· this-array parent) _getTable 'maxp) numGlyphs)
(· (send (· this-array parent) _getTable 'hhea) numberOfMetrics)))))))
@ -38,4 +38,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/hmtx.js
(check-equal? (send hmtx-test size) (* 229 (send HmtxEntry size)))
(define H-gid 41) (define OE-gid 142)
(check-equal? (send (· hmtx-data metrics) get H-gid) (mhasheq 'advance 738 'bearing 33))
(check-equal? (send (· hmtx-data metrics) get OE-gid) (mhasheq 'advance 993 'bearing 43)))
(check-equal? (send (· hmtx-data metrics) get OE-gid) (mhasheq 'advance 993 'bearing 43))
)

@ -93,7 +93,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
;; todo: cvt
'prep (send (· this font) _getTable 'prep)
;; 'glyf (· this glyf)
;; 'hmtx (· this hmtx)
'hmtx (· this hmtx)
'fpgm (send (· this font) _getTable 'fpgm)
)))

@ -25,7 +25,6 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
(send type decode stream this))])))
(define/override (size [array #f])
(report* _length array)
(when (and array (not (list? array)))
(raise-argument-error 'Array:size "list" array))
(cond
@ -88,9 +87,9 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
val)))
(define/override (encode stream val)
(super encode (if (InnerLazyArray? val)
(send val toArray)
val))))
(super encode stream (if (InnerLazyArray? val)
(send val toArray)
val))))
(test-module
(define bstr #"ABCD1234")
@ -101,4 +100,14 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
(check-equal? (send ila get 1) 66)
(check-equal? (send ila get 3) 68)
(check-equal? (send ds pos) 4)
(check-equal? (send ila toArray) '(65 66 67 68)))
(check-equal? (send ila toArray) '(65 66 67 68))
(define la2 (+LazyArray int16be (λ (t) 4)))
(define es (+EncodeStream))
(send la2 encode es '(1 2 3 4))
(check-equal? (send es dump) #"\0\1\0\2\0\3\0\4")
(check-equal? (send (send la2 decode (+DecodeStream #"\0\1\0\2\0\3\0\4")) toArray) '(1 2 3 4))
)

@ -3,7 +3,6 @@
(require "number.rkt")
(define (resolveLength len stream parent)
(report* len stream parent)
(cond
[(number? len) len]
[(procedure? len) (len parent)]

Loading…
Cancel
Save