From 4f33094e783e950681b78c9e5abbcd78c7f18ff9 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 4 Jul 2017 16:52:25 -0700 Subject: [PATCH] tests through 11 work --- pitfall/fontkit/GPOS-test.rkt | 2 +- pitfall/fontkit/OS2.rkt | 2 +- pitfall/fontkit/cvt_.rkt | 11 +- pitfall/fontkit/directory.rkt | 10 +- pitfall/fontkit/font.rkt | 22 +- pitfall/fontkit/fpgm.rkt | 375 +-------------------- pitfall/fontkit/glyf.rkt | 7 +- pitfall/fontkit/head.rkt | 18 +- pitfall/fontkit/hhea.rkt | 2 +- pitfall/fontkit/hmtx.rkt | 6 +- pitfall/fontkit/loca.rkt | 11 +- pitfall/fontkit/maxp.rkt | 2 +- pitfall/fontkit/post.rkt | 12 +- pitfall/fontkit/prep.rkt | 4 +- pitfall/fontkit/subset.rkt | 9 +- pitfall/fontkit/ttfglyph.rkt | 28 +- pitfall/pitfall/test/test12rkt.pdf | Bin 6345 -> 0 bytes pitfall/xenomorph/{stream.rkt => base.rkt} | 2 +- pitfall/xenomorph/main.rkt | 1 + pitfall/xenomorph/test/main.rkt | 1 - 20 files changed, 73 insertions(+), 452 deletions(-) rename pitfall/xenomorph/{stream.rkt => base.rkt} (66%) diff --git a/pitfall/fontkit/GPOS-test.rkt b/pitfall/fontkit/GPOS-test.rkt index 741ef9a4..b863cd09 100644 --- a/pitfall/fontkit/GPOS-test.rkt +++ b/pitfall/fontkit/GPOS-test.rkt @@ -6,4 +6,4 @@ (define gpos (· f GPOS)) (define gsub (· f GSUB)) -(send (· gpos lookupList) get 9) +(send (· gpos lookupList) get 1) diff --git a/pitfall/fontkit/OS2.rkt b/pitfall/fontkit/OS2.rkt index 65b6cedd..f26ca711 100644 --- a/pitfall/fontkit/OS2.rkt +++ b/pitfall/fontkit/OS2.rkt @@ -70,7 +70,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/OS2.js (define len (· dir tables OS/2 length)) (check-equal? offset 360) (check-equal? len 96) - (define ds (+DecodeStream (peek-bytes len offset ip))) + (define ds (open-input-bytes (peek-bytes len offset ip))) (define version (send uint16be decode ds)) (send OS/2 force-version! version) (define table-data (send OS/2 decode ds)) diff --git a/pitfall/fontkit/cvt_.rkt b/pitfall/fontkit/cvt_.rkt index 9f966a79..6e89c377 100644 --- a/pitfall/fontkit/cvt_.rkt +++ b/pitfall/fontkit/cvt_.rkt @@ -8,7 +8,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/cvt.js (define-subclass Struct (Rcvt_)) -(define cvt_ (make-object Rcvt_ +(define cvt_ (+Rcvt_ (dictify 'controlValues (+Array int16be)))) @@ -23,10 +23,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/cvt.js (set-port-position! ip 0) (define table-bytes #"\0\24\0+\0S\0\0\0\20\377&\0\0\1\341\0\v\2\237\0\22\2\340\0\b") (check-equal? table-bytes (peek-bytes len offset ip)) - (define ds (+DecodeStream (peek-bytes len offset ip))) + (define ds (open-input-bytes (peek-bytes len offset ip))) (define cvt-array '(20 43 83 0 16 -218 0 481 11 671 18 736 8)) - (check-equal? (hash-ref (send cvt_ decode ds) 'controlValues) cvt-array) - (define es (+EncodeStream)) - (send cvt_ encode es (mhash 'controlValues cvt-array)) - (check-equal? (send es dump) table-bytes) - ) + (check-equal? (dict-ref (decode cvt_ ds) 'controlValues) cvt-array) + (check-equal? (encode cvt_ (mhash 'controlValues cvt-array) #f) table-bytes)) diff --git a/pitfall/fontkit/directory.rkt b/pitfall/fontkit/directory.rkt index b1c8924c..8eef3bb1 100644 --- a/pitfall/fontkit/directory.rkt +++ b/pitfall/fontkit/directory.rkt @@ -20,14 +20,14 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js (define (unescape-tag tag) (symbol-replace tag "_" " ")) (define-subclass Struct (RDirectory) - (define/augride (process this-res stream ctx) + (define/augride (post-decode this-res stream ctx) (define new-tables-val (mhash)) (for ([table (in-list (· this-res tables))]) (hash-set! new-tables-val (escape-tag (· table tag)) table)) (dict-set! this-res 'tables new-tables-val) this-res) - (define/override (preEncode this-val stream) + (define/override (pre-encode this-val stream) (define tables (for/list ([(tag table) (in-hash (· this-val tables))]) (define table-codec (hash-ref table-codecs tag)) (mhash 'tag (unescape-tag tag) @@ -44,7 +44,9 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js 'tables tables 'searchRange searchRange 'entrySelector (floor (/ searchRange (log 2))) - 'rangeShift (- (* numTables 16) searchRange)))) + 'rangeShift (- (* numTables 16) searchRange)) + + this-val)) (define Directory (+RDirectory (dictify 'tag (+String 4) 'numTables uint16be @@ -55,7 +57,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js (define (directory-decode ip [options (mhash)]) - (send Directory decode (+DecodeStream (port->bytes ip)))) + (send Directory decode ip)) (define (file-directory-decode ps) (directory-decode (open-input-file ps))) diff --git a/pitfall/fontkit/font.rkt b/pitfall/fontkit/font.rkt index 6c0a1247..2c56ba5c 100644 --- a/pitfall/fontkit/font.rkt +++ b/pitfall/fontkit/font.rkt @@ -20,14 +20,14 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js ;; This is the base class for all SFNT-based font formats in fontkit. ;; It supports TrueType, and PostScript glyphs, and several color glyph formats. -(define-subclass object% (TTFFont stream [_src #f]) - (when stream (unless (DecodeStream? stream) - (raise-argument-error 'TTFFont "DecodeStream" stream))) - (unless (member (peek-bytes 4 0 (get-field _port stream)) (list #"true" #"OTTO" (bytes 0 1 0 0))) +(define-subclass object% (TTFFont port [_src #f]) + (when port (unless (input-port? port) + (raise-argument-error 'TTFFont "input port" port))) + (unless (member (peek-bytes 4 0 port) (list #"true" #"OTTO" (bytes 0 1 0 0))) (raise 'probe-fail)) ;; skip variationCoords - (field [_directoryPos (send stream pos)] + (field [_directoryPos (pos port)] [_tables (mhash)] ; holds decoded tables (loaded lazily) [_glyphs (mhash)] [_layoutEngine #f]) @@ -46,8 +46,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js (define table (hash-ref (· this directory tables) tag)) (cond [table - (send stream pos (· table offset)) - stream] + (pos port (· table offset)) + port] [else #f])) (define/public (_decodeTable table-tag) @@ -55,11 +55,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js (λ () (raise-argument-error '_decodeTable "decodable table" table-tag)))) (define offset (· (hash-ref (· directory tables) table-tag) offset)) (define len (· (hash-ref (· directory tables) table-tag) length)) - (send stream pos 0) - (send table-decoder decode (+DecodeStream (peek-bytes len offset (get-field _port stream))) this)) + (pos port 0) + (decode table-decoder (open-input-bytes (peek-bytes len offset port)) #:parent this)) (define/public (_decodeDirectory) - (set! directory (send Directory decode stream (mhash '_startOffset 0))) + (set! directory (decode Directory port #:parent (mhash '_startOffset 0))) directory) (field [ft-library (FT_Init_FreeType)] @@ -301,7 +301,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js ;; rather than use a `probe` function, ;; just try making a font with each format and see what happens [font (in-value (with-handlers ([(curry eq? 'probe-fail) (λ (exn) #f)]) - (make-object format (+DecodeStream buffer) filename)))] + (make-object format (open-input-bytes buffer) filename)))] #:when font) (if postscriptName (send font getFont postscriptName) ; used to select from collection files like TTC diff --git a/pitfall/fontkit/fpgm.rkt b/pitfall/fontkit/fpgm.rkt index b63d42a7..14ceaa15 100644 --- a/pitfall/fontkit/fpgm.rkt +++ b/pitfall/fontkit/fpgm.rkt @@ -25,377 +25,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/fpgm.js (define len (· dir tables fpgm length)) (check-equal? offset 4140) (check-equal? len 371) - (set-port-position! ip 0) - (define ds (+DecodeStream (peek-bytes len offset ip))) - (check-equal? (hash-ref (send fpgm decode ds) 'instructions) '(184 - 0 - 0 - 44 - 75 - 184 - 0 - 9 - 80 - 88 - 177 - 1 - 1 - 142 - 89 - 184 - 1 - 255 - 133 - 184 - 0 - 68 - 29 - 185 - 0 - 9 - 0 - 3 - 95 - 94 - 45 - 184 - 0 - 1 - 44 - 32 - 32 - 69 - 105 - 68 - 176 - 1 - 96 - 45 - 184 - 0 - 2 - 44 - 184 - 0 - 1 - 42 - 33 - 45 - 184 - 0 - 3 - 44 - 32 - 70 - 176 - 3 - 37 - 70 - 82 - 88 - 35 - 89 - 32 - 138 - 32 - 138 - 73 - 100 - 138 - 32 - 70 - 32 - 104 - 97 - 100 - 176 - 4 - 37 - 70 - 32 - 104 - 97 - 100 - 82 - 88 - 35 - 101 - 138 - 89 - 47 - 32 - 176 - 0 - 83 - 88 - 105 - 32 - 176 - 0 - 84 - 88 - 33 - 176 - 64 - 89 - 27 - 105 - 32 - 176 - 0 - 84 - 88 - 33 - 176 - 64 - 101 - 89 - 89 - 58 - 45 - 184 - 0 - 4 - 44 - 32 - 70 - 176 - 4 - 37 - 70 - 82 - 88 - 35 - 138 - 89 - 32 - 70 - 32 - 106 - 97 - 100 - 176 - 4 - 37 - 70 - 32 - 106 - 97 - 100 - 82 - 88 - 35 - 138 - 89 - 47 - 253 - 45 - 184 - 0 - 5 - 44 - 75 - 32 - 176 - 3 - 38 - 80 - 88 - 81 - 88 - 176 - 128 - 68 - 27 - 176 - 64 - 68 - 89 - 27 - 33 - 33 - 32 - 69 - 176 - 192 - 80 - 88 - 176 - 192 - 68 - 27 - 33 - 89 - 89 - 45 - 184 - 0 - 6 - 44 - 32 - 32 - 69 - 105 - 68 - 176 - 1 - 96 - 32 - 32 - 69 - 125 - 105 - 24 - 68 - 176 - 1 - 96 - 45 - 184 - 0 - 7 - 44 - 184 - 0 - 6 - 42 - 45 - 184 - 0 - 8 - 44 - 75 - 32 - 176 - 3 - 38 - 83 - 88 - 176 - 64 - 27 - 176 - 0 - 89 - 138 - 138 - 32 - 176 - 3 - 38 - 83 - 88 - 35 - 33 - 176 - 128 - 138 - 138 - 27 - 138 - 35 - 89 - 32 - 176 - 3 - 38 - 83 - 88 - 35 - 33 - 184 - 0 - 192 - 138 - 138 - 27 - 138 - 35 - 89 - 32 - 176 - 3 - 38 - 83 - 88 - 35 - 33 - 184 - 1 - 0 - 138 - 138 - 27 - 138 - 35 - 89 - 32 - 176 - 3 - 38 - 83 - 88 - 35 - 33 - 184 - 1 - 64 - 138 - 138 - 27 - 138 - 35 - 89 - 32 - 184 - 0 - 3 - 38 - 83 - 88 - 176 - 3 - 37 - 69 - 184 - 1 - 128 - 80 - 88 - 35 - 33 - 184 - 1 - 128 - 35 - 33 - 27 - 176 - 3 - 37 - 69 - 35 - 33 - 35 - 33 - 89 - 27 - 33 - 89 - 68 - 45 - 184 - 0 - 9 - 44 - 75 - 83 - 88 - 69 - 68 - 27 - 33 - 33 - 89 - 45))) + (check-equal? (pos ip 0) 0) + (check-equal? (dict-ref (send fpgm decode (peek-bytes len offset ip)) 'instructions) '(184 0 0 44 75 184 0 9 80 88 177 1 1 142 89 184 1 255 133 184 0 68 29 185 0 9 0 3 95 94 45 184 0 1 44 32 32 69 105 68 176 1 96 45 184 0 2 44 184 0 1 42 33 45 184 0 3 44 32 70 176 3 37 70 82 88 35 89 32 138 32 138 73 100 138 32 70 32 104 97 100 176 4 37 70 32 104 97 100 82 88 35 101 138 89 47 32 176 0 83 88 105 32 176 0 84 88 33 176 64 89 27 105 32 176 0 84 88 33 176 64 101 89 89 58 45 184 0 4 44 32 70 176 4 37 70 82 88 35 138 89 32 70 32 106 97 100 176 4 37 70 32 106 97 100 82 88 35 138 89 47 253 45 184 0 5 44 75 32 176 3 38 80 88 81 88 176 128 68 27 176 64 68 89 27 33 33 32 69 176 192 80 88 176 192 68 27 33 89 89 45 184 0 6 44 32 32 69 105 68 176 1 96 32 32 69 125 105 24 68 176 1 96 45 184 0 7 44 184 0 6 42 45 184 0 8 44 75 32 176 3 38 83 88 176 64 27 176 0 89 138 138 32 176 3 38 83 88 35 33 176 128 138 138 27 138 35 89 32 176 3 38 83 88 35 33 184 0 192 138 138 27 138 35 89 32 176 3 38 83 88 35 33 184 1 0 138 138 27 138 35 89 32 176 3 38 83 88 35 33 184 1 64 138 138 27 138 35 89 32 184 0 3 38 83 88 176 3 37 69 184 1 128 80 88 35 33 184 1 128 35 33 27 176 3 37 69 35 33 35 33 89 27 33 89 68 45 184 0 9 44 75 83 88 69 68 27 33 33 89 45))) diff --git a/pitfall/fontkit/glyf.rkt b/pitfall/fontkit/glyf.rkt index dd06cf46..157f79a8 100644 --- a/pitfall/fontkit/glyf.rkt +++ b/pitfall/fontkit/glyf.rkt @@ -18,9 +18,4 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/glyf.js (check-equal? offset 4620) (check-equal? len 34072) (set-port-position! ip 0) - (define table-bytes (peek-bytes len offset ip)) - (define ds (+DecodeStream table-bytes)) - (define es (+EncodeStream)) - (send glyf encode es empty) - #;(send es dump) - ) + (define table-bytes (peek-bytes len offset ip))) diff --git a/pitfall/fontkit/head.rkt b/pitfall/fontkit/head.rkt index 39687940..0bfa792b 100644 --- a/pitfall/fontkit/head.rkt +++ b/pitfall/fontkit/head.rkt @@ -42,19 +42,19 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/head.js (define table-bytes #"\0\1\0\0\0\2\0\0.\252t<_\17<\365\0\t\3\350\0\0\0\0\316\3\301\261\0\0\0\0\316\3\304\364\377\36\377\24\4\226\3\324\0\2\0\t\0\2\0\0\0\0") (set-port-position! ip 0) (check-equal? (peek-bytes length offset ip) table-bytes) - (define table-data (send head decode (+DecodeStream table-bytes))) + (define table-data (send head decode table-bytes)) (check-equal? (· table-data unitsPerEm) 1000) (check-equal? (· table-data yMin) -236) (check-equal? (· table-data yMax) 980) (check-equal? (· table-data xMax) 1174) (check-equal? (· table-data xMin) -226) - (check-equal? (· table-data macStyle) (make-hash '((shadow . #f) - (extended . #f) - (condensed . #f) - (underline . #f) - (outline . #f) - (bold . #f) - (italic . #t)))) + (check-equal? (· table-data macStyle) (make-hasheq '((shadow . #f) + (extended . #f) + (condensed . #f) + (underline . #f) + (outline . #f) + (bold . #f) + (italic . #t)))) (check-equal? (· table-data magicNumber) #x5F0F3CF5) (check-equal? (· table-data indexToLocFormat) 0) ; used in loca table - (check-equal? (send head encode #f table-data) table-bytes)) \ No newline at end of file + (check-equal? (encode head table-data #f) table-bytes)) \ No newline at end of file diff --git a/pitfall/fontkit/hhea.rkt b/pitfall/fontkit/hhea.rkt index cc584250..0138f6eb 100644 --- a/pitfall/fontkit/hhea.rkt +++ b/pitfall/fontkit/hhea.rkt @@ -32,7 +32,7 @@ (define table-bytes #"\0\1\0\0\3\324\377\22\0\0\4\311\377_\377`\4\251\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\345") (set-port-position! ip 0) (check-equal? (peek-bytes length offset ip) table-bytes) - (define table-data (send hhea decode (+DecodeStream table-bytes))) + (define table-data (decode hhea table-bytes)) (check-equal? (· table-data ascent) 980) (check-equal? (· table-data descent) -238) (check-equal? (· table-data numberOfMetrics) 229) diff --git a/pitfall/fontkit/hmtx.rkt b/pitfall/fontkit/hmtx.rkt index dda6e77a..5c2281f2 100644 --- a/pitfall/fontkit/hmtx.rkt +++ b/pitfall/fontkit/hmtx.rkt @@ -34,11 +34,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/hmtx.js (check-equal? hmtx-offset 456) (check-equal? hmtx-length 916) (define hmtx-bytes (peek-bytes hmtx-length hmtx-offset ip)) - (define hmtx-data (send hmtx-test decode (+DecodeStream hmtx-bytes))) + (define hmtx-data (decode hmtx-test hmtx-bytes)) (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? (dump (send (· hmtx-data metrics) get H-gid)) (mhasheq 'advance 738 'bearing 33)) + (check-equal? (dump (send (· hmtx-data metrics) get OE-gid)) (mhasheq 'advance 993 'bearing 43)) ) \ No newline at end of file diff --git a/pitfall/fontkit/loca.rkt b/pitfall/fontkit/loca.rkt index 8e8f7882..a843e1d1 100644 --- a/pitfall/fontkit/loca.rkt +++ b/pitfall/fontkit/loca.rkt @@ -12,7 +12,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js |# (define-subclass VersionedStruct (Rloca) - (define/augride (process res stream ctx) + (define/augride (post-decode res stream ctx) ;; in `xenomorph` `process` method, `res` is aliased as `this` ;; (when (= 16bit-style (· res version)) @@ -21,12 +21,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js (dict-update! res 'offsets (λ (offsets) (map (curry * 2) offsets)))) res) - (define/override (preEncode this-val stream) + (define/override (pre-encode this-val stream) ;; this = val to be encoded - (loca-preEncode this-val stream))) + (loca-pre-encode this-val stream) + this-val)) ;; make "static method" -(define (loca-preEncode this . args) +(define (loca-pre-encode this . args) ;; this = val to be encoded (unless (dict-has-key? this 'version) (dict-set! this 'version (if (> (last (· this offsets)) max-32-bit-value) @@ -49,7 +50,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js (define len (· dir tables loca length)) (check-equal? offset 38692) (check-equal? len 460) - (define ds (+DecodeStream (peek-bytes len offset ip))) + (define ds (peek-bytes len offset ip)) (check-equal? (send loca encode #f (mhash 'version 0 'offsets '(0 76 156))) #"\0\0\0L\0\234") (check-equal? diff --git a/pitfall/fontkit/maxp.rkt b/pitfall/fontkit/maxp.rkt index 6fbef939..da8501ae 100644 --- a/pitfall/fontkit/maxp.rkt +++ b/pitfall/fontkit/maxp.rkt @@ -33,6 +33,6 @@ (define maxp-bytes #"\0\1\0\0\0\345\0f\0\a\0O\0\4\0\1\0\0\0\0\0\n\0\0\2\0\1s\0\2\0\1") (set-port-position! ip 0) (check-equal? (peek-bytes maxp-length maxp-offset ip) maxp-bytes) - (define maxp-data (send maxp decode (+DecodeStream maxp-bytes))) + (define maxp-data (send maxp decode maxp-bytes)) (check-equal? (· maxp-data numGlyphs) 229) (check-equal? (· maxp-data version) 65536)) \ No newline at end of file diff --git a/pitfall/fontkit/post.rkt b/pitfall/fontkit/post.rkt index 557936ec..eb06270b 100644 --- a/pitfall/fontkit/post.rkt +++ b/pitfall/fontkit/post.rkt @@ -25,8 +25,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/post.js 1 null 2 (dictify 'numberOfGlyphs uint16be 'glyphNameIndex (+Array uint16be 'numberOfGlyphs) - ;; this field causes problems due to deficiency in String class - ;; 'names (+Array (+String uint8)) + 'names (+Array (+String uint8)) ) 2.5 (dictify 'numberOfGlyphs uint16be 'offsets (+Array uint8)) @@ -40,9 +39,10 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/post.js (define len (· dir tables post length)) (check-equal? offset 41520) (check-equal? len 514) - (define ds (+DecodeStream (peek-bytes len offset ip))) - (define version (send fixed32be decode ds)) ; version = 2 + (define ds (open-input-bytes (peek-bytes len offset ip))) + (define version (decode fixed32be ds)) ; version = 2 (send post force-version! version) - (define table-data (send post decode ds)) + (define table-data (decode post ds)) (check-equal? (· table-data underlineThickness) 58) - (check-equal? (· table-data underlinePosition) -178)) \ No newline at end of file + (check-equal? (· table-data underlinePosition) -178) + (check-equal? (· table-data names) '("periodcentered" "macron"))) \ No newline at end of file diff --git a/pitfall/fontkit/prep.rkt b/pitfall/fontkit/prep.rkt index 1edf6f28..c3d224b7 100644 --- a/pitfall/fontkit/prep.rkt +++ b/pitfall/fontkit/prep.rkt @@ -23,5 +23,5 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/prep.js (set-port-position! ip 0) (define table-bytes #"\270\0\0+\0\272\0\1\0\1\0\2+\1\272\0\2\0\1\0\2+\1\277\0\2\0C\0007\0+\0\37\0\23\0\0\0\b+\0\277\0\1\0\200\0i\0R\0;\0#\0\0\0\b+\0\272\0\3\0\5\0\a+\270\0\0 E}i\30D") (check-equal? table-bytes (peek-bytes len offset ip)) - (define ds (+DecodeStream (peek-bytes len offset ip))) - (check-equal? (hash-ref (send prep decode ds) 'controlValueProgram) '(184 0 0 43 0 186 0 1 0 1 0 2 43 1 186 0 2 0 1 0 2 43 1 191 0 2 0 67 0 55 0 43 0 31 0 19 0 0 0 8 43 0 191 0 1 0 128 0 105 0 82 0 59 0 35 0 0 0 8 43 0 186 0 3 0 5 0 7 43 184 0 0 32 69 125 105 24 68))) + (define ds (open-input-bytes (peek-bytes len offset ip))) + (check-equal? (dict-ref (decode prep ds) 'controlValueProgram) '(184 0 0 43 0 186 0 1 0 1 0 2 43 1 186 0 2 0 1 0 2 43 1 191 0 2 0 67 0 55 0 43 0 31 0 19 0 0 0 8 43 0 191 0 1 0 128 0 105 0 82 0 59 0 35 0 0 0 8 43 0 186 0 3 0 5 0 7 43 184 0 0 32 69 125 105 24 68))) diff --git a/pitfall/fontkit/subset.rkt b/pitfall/fontkit/subset.rkt index 1ca41ef2..b217e655 100644 --- a/pitfall/fontkit/subset.rkt +++ b/pitfall/fontkit/subset.rkt @@ -14,10 +14,7 @@ https://github.com/devongovett/fontkit/blob/master/src/subset/Subset.js (send this includeGlyph 0) ; always include the missing glyph in subset - (define/public (encodeStream) - (define s (+EncodeStream)) - (send this encode s) - s) + (as-methods includeGlyph)) @@ -97,7 +94,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js ;; name, cmap, OS/2, post (define/contract (encode this stream) - (EncodeStream? . ->m . void?) + (output-port? . ->m . void?) (set-field! glyf this empty) (set-field! offset this 0) (set-field! loca this (mhash 'offsets empty)) @@ -115,7 +112,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js (dict-set! maxp 'numGlyphs (length (· this glyf))) ;; populate the new loca table (dict-update! (· this loca) 'offsets (λ (vals) (append vals (list (· this offset))))) - (loca-preEncode (· this loca)) + (loca-pre-encode (· this loca)) (define head (cloneDeep (send (· this font head) dump))) diff --git a/pitfall/fontkit/ttfglyph.rkt b/pitfall/fontkit/ttfglyph.rkt index ad2f3f18..095becf6 100644 --- a/pitfall/fontkit/ttfglyph.rkt +++ b/pitfall/fontkit/ttfglyph.rkt @@ -65,16 +65,16 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js (unfinished)) ;; Parses a single glyph coordinate - (define/public (_parseGlyphCoord stream prev short same) - (unless (DecodeStream? stream) - (raise-argument-error '_parseGlyphCoord "DecodeStream" stream)) + (define/public (_parseGlyphCoord port prev short same) + (unless (input-port? port) + (raise-argument-error '_parseGlyphCoord "input port" port)) (unless (number? prev) (raise-argument-error '_parseGlyphCoord "number" prev)) (unless (and (boolean? short) (boolean? same)) (raise-argument-error '_parseGlyphCoord "booleans" (list short same))) (+ prev (if short - ((if (not same) - +) (send uint8 decode stream)) - (if same 0 (send int16be decode stream))))) + ((if (not same) - +) (decode uint8 port)) + (if same 0 (decode int16be port))))) ;; Decodes the glyph data into points for simple glyphs, @@ -95,26 +95,26 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js [(? negative?) (_decodeComposite glyph stream startPos)]) glyph))) - (define/public (_decodeSimple glyph stream) + (define/public (_decodeSimple glyph port) (unless (dict? glyph) (raise-argument-error 'TTFGlyph-_decodeSimple "decoded RGlyfHeader" glyph)) - (unless (DecodeStream? stream) - (raise-argument-error 'TTFGlyph-_decodeSimple "DecodeStream" stream)) + (unless (input-port? port) + (raise-argument-error 'TTFGlyph-_decodeSimple "input port" port)) ;; this is a simple glyph (dict-set! glyph 'points empty) - (define endPtsOfContours (send (+Array uint16be (· glyph numberOfContours)) decode stream)) - (dict-set! glyph 'instructions (send (+Array uint8be uint16be) decode stream)) + (define endPtsOfContours (decode (+Array uint16be (· glyph numberOfContours)) port)) + (dict-set! glyph 'instructions (decode (+Array uint8be uint16be) port)) (define numCoords (add1 (last endPtsOfContours))) (define flags (for*/lists (flags) ([i (in-naturals)] #:break (= (length flags) numCoords) - [flag (in-value (send uint8 decode stream))] + [flag (in-value (decode uint8 port))] [count (in-range (add1 (if (not (zero? (bitwise-and flag REPEAT))) - (send uint8 decode stream) + (decode uint8 port) 0)))]) flag)) @@ -123,8 +123,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js (for/fold ([points empty] [px 0] [py 0]) ([(flag i) (in-indexed flags)]) (define point (+Point (zero? (bitwise-and flag ON_CURVE)) (and (index-of endPtsOfContours i) #t) 0 0)) - (define next-px (_parseGlyphCoord stream px (not (zero? (bitwise-and flag X_SHORT_VECTOR))) (not (zero? (bitwise-and flag SAME_X))))) - (define next-py (_parseGlyphCoord stream py (not (zero? (bitwise-and flag Y_SHORT_VECTOR))) (not (zero? (bitwise-and flag SAME_Y))))) + (define next-px (_parseGlyphCoord port px (not (zero? (bitwise-and flag X_SHORT_VECTOR))) (not (zero? (bitwise-and flag SAME_X))))) + (define next-py (_parseGlyphCoord port py (not (zero? (bitwise-and flag Y_SHORT_VECTOR))) (not (zero? (bitwise-and flag SAME_Y))))) (set-field! x point next-px) (set-field! y point next-py) (values (cons point points) next-px next-py))) diff --git a/pitfall/pitfall/test/test12rkt.pdf b/pitfall/pitfall/test/test12rkt.pdf index 4f208f6094af53f09393de72ccf9aae499e9e5e9..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 GIT binary patch literal 0 HcmV?d00001 literal 6345 zcmZ`;ZA@d?c|P~r7-L|t4d%<(9ODnZ%=r4+*TxgZ!+>FzWriWZ%t9D4Yp?-t2TYA8 zn%OAPG|6ryvTf6LD@Ey6$)70Q_D5N@s#qp%Cd#T(|Fo+pX{1JqvVYQzqW)>N-Bi^= zpZDBrV}=c*%Q@%0=bZaK&--x>?*!*F(<9N#FmLBcpIX2tM z+tO)Uem6(^(;k)YOk*QXADmWsLhOZkk@-?_V=-Ums}X3(BTM;*WgeN?!8Q{{J885t zYc(5_GL?;QsDXZbW5@QppCFr9GK5hcRe&auysYu1 z9igL&-llDJOi>iPQ&c=LJaIf4o`lg)8hw(D;z=3fELxJS1=>=)8EWGDW8M*g8`!t{o@-TYT|;kq|1 z0m}iC*x2cZ(y!&eW^wl535GHjnTMaSFnU(>j+qk@$>B^LF=ynMxgiaUkvsAZ>t^zY zklWv3edw_x#-^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U_JIPG3D@8IQQF-}~&y5tG84PZctU(n}b~VF-qN=$XQN`p^`dURd_8@B@A@lRMzk zd^?*vGzUeC7x{yg2tQ|>^VumsZ&R==f`-_*m> zF?kMkzK6~vOX6KGPIShs!|Z!_^OzOb0{ax*gh+G@=f_0n$pB#Ilps< zE4Ik;^ZCNocA3XVqbT2?)-;#hK|$)ph3VPl8^e>^*-|-QvPG`%Z&0->HHsyZ**#-X zB8f$M1&fwu^7|X5!d|(E1=Ob%BWi3E8{f}vp)_WT%#^eD3meyWx9;cZ>$GY@RK-T3 zi6~7@@Mts@xBVX$h{yQhYQXNV zbR(sSK2?W$#vdnJp{#huZ7p`H&Q-8iYD`*fi7A4;XLbu9q*5o`EbQh=MvaoM1NE*A zCCFT1qil?XY-1<82m3xt8s`^@g6xc{+mnlfHb~Bqn@;mweiPf>%(%*_;+_rn#s_Drp*O zG0`L-#VC=}8%;E-J|!6!qvWXGB=spNz0rk=V?jA_cJmje(}4CmH;{D*CNTH0)Jknp`dv|rY351DVMUyfhF<3 r4kC|H{Tj((p;#<)G64FEg;(GMD)F^nM$Q&&B@{Jj3kIidP22t-TBgJG diff --git a/pitfall/xenomorph/stream.rkt b/pitfall/xenomorph/base.rkt similarity index 66% rename from pitfall/xenomorph/stream.rkt rename to pitfall/xenomorph/base.rkt index 85dccc2b..b9cdd7be 100644 --- a/pitfall/xenomorph/stream.rkt +++ b/pitfall/xenomorph/base.rkt @@ -1,3 +1,3 @@ #lang reader (submod "private/racket.rkt" reader) -(r+p "private/stream.rkt") \ No newline at end of file +(r+p "private/base.rkt") \ No newline at end of file diff --git a/pitfall/xenomorph/main.rkt b/pitfall/xenomorph/main.rkt index 233099b2..a484b07c 100644 --- a/pitfall/xenomorph/main.rkt +++ b/pitfall/xenomorph/main.rkt @@ -1,6 +1,7 @@ #lang reader (submod "private/racket.rkt" reader) (r+p "array.rkt" + "base.rkt" "bitfield.rkt" "buffer.rkt" "enum.rkt" diff --git a/pitfall/xenomorph/test/main.rkt b/pitfall/xenomorph/test/main.rkt index d9dba3e8..6e723183 100644 --- a/pitfall/xenomorph/test/main.rkt +++ b/pitfall/xenomorph/test/main.rkt @@ -9,7 +9,6 @@ "optional-test.rkt" "pointer-test.rkt" "reserved-test.rkt" - "stream-test.rkt" "string-test.rkt" "struct-test.rkt" "versioned-struct-test.rkt")