x/redo tests pass

main
Matthew Butterick 6 years ago
parent 28468ae781
commit 1b6004fa07

@ -41,7 +41,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
(mhash 'tag (unescape-tag tag)
'checkSum 0
'offset (+xvoid-pointer table-codec table)
'length (send table-codec size table))))
'length (size table-codec table))))
(define numTables (length tables))
(define searchRange (* (floor (log numTables 2)) 16))
(hash-set*! this-val

@ -32,7 +32,7 @@ https://github.com/devongovett/fontkit/blob/master/src/subset/Subset.js
(define (encode-to-port ss)
(define p (open-output-bytes))
(encode ss p)
(subset-encode ss p)
p)
(define (subset-add-glyph! ss glyph-or-gid)
@ -88,7 +88,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(for ([ttf-glyph-component (in-list (· ttf-glyf-data components))])
(define gid (subset-add-glyph! ss (ttf-glyph-component-glyph-id ttf-glyph-component)))
;; note: this (ttf-glyph-component-pos component) is correct. It's a field of a Component object, not a port
(bytes-copy! glyf-bytes (ttf-glyph-component-pos ttf-glyph-component) (send uint16be encode #f gid))))
(bytes-copy! glyf-bytes (ttf-glyph-component-pos ttf-glyph-component) (encode uint16be gid #f))))
(set-ttf-subset-glyf! ss (append (ttf-subset-glyf ss) (list glyf-bytes)))
(hash-update! (ttf-subset-loca ss) 'offsets
@ -108,7 +108,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(define (clone-deep val) (deserialize (serialize val)))
(define (encode ss port)
(define (subset-encode ss port)
(set-ttf-subset-glyf! ss empty)
(set-ttf-subset-offset! ss 0)
(set-ttf-subset-loca! ss (mhash 'offsets empty))
@ -122,17 +122,17 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(define gid (list-ref (subset-glyphs ss) idx))
(ttf-subset-add-glyph ss gid))
(define new-maxp-table (clone-deep (send (get-maxp-table (subset-font ss)) to-hash)))
(define new-maxp-table (clone-deep (dump-mutable (get-maxp-table (subset-font ss)))))
(dict-set! new-maxp-table 'numGlyphs (length (ttf-subset-glyf ss)))
;; populate the new loca table
(dict-update! (ttf-subset-loca ss) 'offsets (λ (vals) (append vals (list (ttf-subset-offset ss)))))
(loca-pre-encode (ttf-subset-loca ss))
(define new-head-table (clone-deep (send (get-head-table (subset-font ss)) to-hash)))
(define new-head-table (clone-deep (dump-mutable (get-head-table (subset-font ss)))))
(dict-set! new-head-table 'indexToLocFormat (dict-ref (ttf-subset-loca ss) 'version))
(define new-hhea-table (clone-deep (send (get-hhea-table (subset-font ss)) to-hash)))
(define new-hhea-table (clone-deep (dump-mutable (get-hhea-table (subset-font ss)))))
(dict-set! new-hhea-table 'numberOfMetrics (length (dict-ref (ttf-subset-hmtx ss) 'metrics)))
(define new-tables
@ -151,6 +151,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(error 'encode (format "missing value for ~a" k)))
(make-hasheq kvs)))
(encode Directory port (mhash 'tables new-tables))
(encode Directory (mhash 'tables new-tables) port)
(void))

@ -158,16 +158,16 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
(dict-set! glyph-data 'components
(for/list ([i (in-naturals)]
#:break (zero? (bitwise-and flags MORE_COMPONENTS)))
(set! flags (send uint16be decode port))
(set! flags (decode uint16be port))
(define gPos (- (pos port) offset))
(define glyphID (send uint16be decode port))
(define glyphID (decode uint16be port))
(unless haveInstructions
(set! haveInstructions (not (zero? (bitwise-and flags WE_HAVE_INSTRUCTIONS)))))
(match-define
(list dx dy)
(let ([decoder (if (not (zero? (bitwise-and flags ARG_1_AND_2_ARE_WORDS))) int16be int8)])
(list (send decoder decode port) (send decoder decode port))))
(list (decode decoder port) (decode decoder port))))
(define component (+ttf-glyph-component glyphID dx dy))
(set-ttf-glyph-component-pos! component gPos)
@ -193,6 +193,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
(/ (+ (* b1 (expt 2 8)) b2) (expt 2 14) 1.0))
(define (read-fixed14 stream)
(define b1 (send uint8 decode stream))
(define b2 (send uint8 decode stream))
(define b1 (decode uint8 stream))
(define b2 (decode uint8 stream))
(bytes->fixed14 b1 b2))
Loading…
Cancel
Save