From 80c25885fd7d91ee52a62ed6d54deea5d07e385b Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 19 Jun 2017 20:36:20 -0700 Subject: [PATCH] allow #f arg for encode --- pitfall/fontkit/head.rkt | 5 +---- pitfall/fontkit/loca.rkt | 10 ++-------- pitfall/fontkit/subset.rkt | 4 +--- pitfall/restructure/stream.rkt | 8 ++++++-- pitfall/restructure/struct.rkt | 4 +--- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/pitfall/fontkit/head.rkt b/pitfall/fontkit/head.rkt index fbbbf083..1fc96a6f 100644 --- a/pitfall/fontkit/head.rkt +++ b/pitfall/fontkit/head.rkt @@ -57,7 +57,4 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/head.js (italic . #t)))) (check-equal? (· table-data magicNumber) #x5F0F3CF5) (check-equal? (· table-data indexToLocFormat) 0) ; used in loca table - - (define es (+EncodeStream)) - (send head encode es table-data) - (check-equal? (send es dump) table-bytes)) \ No newline at end of file + (check-equal? (send head encode #f table-data) table-bytes)) \ No newline at end of file diff --git a/pitfall/fontkit/loca.rkt b/pitfall/fontkit/loca.rkt index cf1a7e44..afbde9d5 100644 --- a/pitfall/fontkit/loca.rkt +++ b/pitfall/fontkit/loca.rkt @@ -51,15 +51,9 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js (define ds (+DecodeStream (peek-bytes len offset ip))) (send loca force-version! 0) (check-equal? - (let () - (define es (+EncodeStream)) - (send loca encode es '#hash((version . 0) (offsets . (0 76 156)))) - (send es dump)) #"\0\0\0L\0\234") + (send loca encode #f '#hash((version . 0) (offsets . (0 76 156)))) #"\0\0\0L\0\234") (check-equal? - (let () - (define es (+EncodeStream)) - (send loca encode es '#hash((version . 1) (offsets . (0 76 156)))) - (send es dump)) #"\0\0\0\0\0\0\0L\0\0\0\234") + (send loca encode #f '#hash((version . 1) (offsets . (0 76 156)))) #"\0\0\0\0\0\0\0L\0\0\0\234") (define table-data (send loca decode ds)) (check-equal? (length (· table-data offsets)) 230) (check-equal? (· table-data offsets) '(0 0 0 136 296 500 864 1168 1548 1628 1716 1804 1944 2048 2128 2176 2256 2312 2500 2596 2788 3052 3168 3396 3624 3732 4056 4268 4424 4564 4640 4728 4804 5012 5384 5532 5808 6012 6212 6456 6672 6916 7204 7336 7496 7740 7892 8180 8432 8648 8892 9160 9496 9764 9936 10160 10312 10536 10780 10992 11148 11216 11272 11340 11404 11444 11524 11820 12044 12216 12488 12728 12932 13324 13584 13748 13924 14128 14232 14592 14852 15044 15336 15588 15776 16020 16164 16368 16520 16744 16984 17164 17320 17532 17576 17788 17896 18036 18284 18552 18616 18988 19228 19512 19712 19796 19976 20096 20160 20224 20536 20836 20876 21000 21200 21268 21368 21452 21532 21720 21908 22036 22244 22664 22872 22932 22992 23088 23220 23268 23372 23440 23600 23752 23868 23988 24084 24184 24224 24548 24788 25012 25292 25716 25884 26292 26396 26540 26796 27172 27488 27512 27536 27560 27584 27912 27936 27960 27984 28008 28032 28056 28080 28104 28128 28152 28176 28200 28224 28248 28272 28296 28320 28344 28368 28392 28416 28440 28464 28488 28512 28536 28560 28968 28992 29016 29040 29064 29088 29112 29136 29160 29184 29208 29232 29256 29280 29304 29328 29352 29376 29400 29424 29448 29472 29496 29520 29824 30164 30220 30652 30700 30956 31224 31248 31332 31488 31636 31916 32104 32176 32484 32744 32832 32956 33248 33664 33884 34048 34072))) diff --git a/pitfall/fontkit/subset.rkt b/pitfall/fontkit/subset.rkt index eae93f4c..f4851696 100644 --- a/pitfall/fontkit/subset.rkt +++ b/pitfall/fontkit/subset.rkt @@ -78,9 +78,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js (when (and glyf (negative? (· glyf numberOfContours))) (for ([component (in-list (· glyf components))]) (define gid (send this includeGlyph (· component glyphID))) - (define es (+EncodeStream)) - (send uint16be encode es gid) - (bytes-copy! buffer (· component pos) (send es dump)))) + (bytes-copy! buffer (· component pos) (send uint16be encode #f gid)))) ;; skip variation shit diff --git a/pitfall/restructure/stream.rkt b/pitfall/restructure/stream.rkt index f98e99b5..758cb3ba 100644 --- a/pitfall/restructure/stream.rkt +++ b/pitfall/restructure/stream.rkt @@ -121,10 +121,14 @@ https://github.com/mbutterick/restructure/blob/master/src/DecodeStream.coffee (inner (void) decode stream . args)) (define/overment (encode x . args) - (define stream (if (output-port? x) (+EncodeStream x) x)) + (define stream (cond + [(output-port? x) (+EncodeStream x)] + [(not x) (+EncodeStream)] + [else x])) (unless (EncodeStream? stream) (raise-argument-error 'Streamcoder:encode "output port or EncodeStream" x)) - (inner (void) encode stream . args))) + (inner (void) encode stream . args) + (when (not x) (send stream dump)))) (test-module (define-subclass Streamcoder (Dummy) diff --git a/pitfall/restructure/struct.rkt b/pitfall/restructure/struct.rkt index c2be8694..6e427304 100644 --- a/pitfall/restructure/struct.rkt +++ b/pitfall/restructure/struct.rkt @@ -156,6 +156,4 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee (send num-type size))) (define bs (apply bytes (for/list ([i (in-range struct-size)]) (random 256)))) - (define es (+EncodeStream)) - (send vs encode es (send vs decode bs)) - (check-equal? (send es dump) bs))) + (check-equal? (send vs encode #f (send vs decode bs)) bs)))