From 2d050f561910d173fb333a5417ea64ba0db0bcd6 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 28 Dec 2018 15:44:19 -0800 Subject: [PATCH] cleanup --- fontland/fontland/table/CFF_.rkt | 3 +-- fontland/fontland/table/OS2.rkt | 27 ++++++++---------------- fontland/fontland/table/cvt_.rkt | 22 +++++++------------ fontland/fontland/table/fpgm.rkt | 16 ++++++-------- fontland/fontland/table/glyf.rkt | 17 +++++++-------- fontland/fontland/table/head.rkt | 36 +++++++++++++------------------- fontland/fontland/table/hhea.rkt | 25 +++++++++------------- fontland/fontland/table/hmtx.rkt | 23 +++++++++----------- fontland/fontland/table/loca.rkt | 28 ++++++++++--------------- fontland/fontland/table/maxp.rkt | 22 +++++++------------ fontland/fontland/table/post.rkt | 27 +++++++----------------- fontland/fontland/table/prep.rkt | 16 +++++++------- 12 files changed, 99 insertions(+), 163 deletions(-) diff --git a/fontland/fontland/table/CFF_.rkt b/fontland/fontland/table/CFF_.rkt index 69917645..1b8fd067 100644 --- a/fontland/fontland/table/CFF_.rkt +++ b/fontland/fontland/table/CFF_.rkt @@ -1,6 +1,5 @@ #lang racket/base -(require sugar/unstable/class - xenomorph) +(require xenomorph) (provide CFF_) #| diff --git a/fontland/fontland/table/OS2.rkt b/fontland/fontland/table/OS2.rkt index 23582bb6..baa644c8 100644 --- a/fontland/fontland/table/OS2.rkt +++ b/fontland/fontland/table/OS2.rkt @@ -1,9 +1,6 @@ #lang racket/base -(require xenomorph - sugar/unstable/class - sugar/unstable/dict - "../helper.rkt") -(provide (all-defined-out)) +(require xenomorph sugar/unstable/dict) +(provide OS/2) #| approximates @@ -67,16 +64,10 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/OS2.js 5 (append type-1 type-2 type-5))))) (module+ test - (require rackunit racket/serialize sugar/unstable/js) - (define ip (open-input-file charter-path)) - (define dir (deserialize (read (open-input-file charter-directory-path)))) - (define offset (· dir tables OS/2 offset)) - (define len (· dir tables OS/2 length)) - (check-equal? offset 360) - (check-equal? len 96) - (define ds (open-input-bytes (peek-bytes len offset ip))) - (define version (decode uint16be ds)) - #;(send OS/2 force-version! version) - #;(define table-data (send OS/2 decode ds)) - #;(check-equal? (· table-data panose) '(2 0 5 3 6 0 0 2 0 4)) - #;(check-equal? (· table-data sFamilyClass) 0)) + (require rackunit racket/serialize "../helper.rkt") + (define ip (open-input-file charter-path)) + (define dir (deserialize (read (open-input-file charter-directory-path)))) + (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'OS/2) 'offset)) + (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'OS/2) 'length)) + (check-equal? offset 360) + (check-equal? len 96)) \ No newline at end of file diff --git a/fontland/fontland/table/cvt_.rkt b/fontland/fontland/table/cvt_.rkt index 3a90b88a..85ae4dcc 100644 --- a/fontland/fontland/table/cvt_.rkt +++ b/fontland/fontland/table/cvt_.rkt @@ -1,10 +1,6 @@ #lang racket/base -(require sugar/unstable/class - sugar/unstable/dict - "../helper.rkt" - racket/dict - xenomorph) -(provide (all-defined-out)) +(require xenomorph) +(provide cvt_) #| approximates @@ -14,19 +10,17 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/cvt.js (define cvt_ (x:struct 'controlValues (x:array #:type int16be))) (module+ test - (require rackunit racket/serialize - sugar/unstable/js - sugar/unstable/port) + (require rackunit racket/serialize "../helper.rkt") (define ip (open-input-file charter-path)) (define dir (deserialize (read (open-input-file charter-directory-path)))) - (define offset (· dir tables cvt_ offset)) - (define len (· dir tables cvt_ length)) + (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'cvt_) 'offset)) + (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'cvt_) 'length)) (check-equal? offset 4592) (check-equal? len 26) - (set-port-position! ip 0) + (file-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 (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? (dict-ref (decode cvt_ ds) 'controlValues) cvt-array) - (check-equal? (encode cvt_ (mhash 'controlValues cvt-array) #f) table-bytes)) + (check-equal? (hash-ref (decode cvt_ ds) 'controlValues) cvt-array) + (check-equal? (encode cvt_ (make-hash (list (cons 'controlValues cvt-array))) #f) table-bytes)) diff --git a/fontland/fontland/table/fpgm.rkt b/fontland/fontland/table/fpgm.rkt index 03ae406d..f4b22967 100644 --- a/fontland/fontland/table/fpgm.rkt +++ b/fontland/fontland/table/fpgm.rkt @@ -1,8 +1,6 @@ #lang racket/base -(require sugar/unstable/dict - "../helper.rkt" - xenomorph) -(provide (all-defined-out)) +(require xenomorph) +(provide fpgm) #| approximates https://github.com/mbutterick/fontkit/blob/master/src/tables/fpgm.js @@ -15,15 +13,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/fpgm.js (define fpgm (x:struct 'instructions (x:array #:type uint8))) (module+ test - (require rackunit racket/serialize racket/dict - sugar/unstable/js - racket/class) + (require rackunit racket/serialize "../helper.rkt") (define ip (open-input-file charter-path)) (define dir (deserialize (read (open-input-file charter-directory-path)))) - (define offset (· dir tables fpgm offset)) - (define len (· dir tables fpgm length)) + (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'fpgm) 'offset)) + (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'fpgm) 'length)) (check-equal? offset 4140) (check-equal? len 371) (check-equal? (pos ip 0) 0) - (check-equal? (dict-ref (decode fpgm (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))) + (check-equal? (hash-ref (decode fpgm (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/fontland/fontland/table/glyf.rkt b/fontland/fontland/table/glyf.rkt index 5dc5db76..68be4b04 100644 --- a/fontland/fontland/table/glyf.rkt +++ b/fontland/fontland/table/glyf.rkt @@ -1,8 +1,6 @@ #lang racket/base -(require sugar/unstable/class - "../helper.rkt" - xenomorph) -(provide (all-defined-out)) +(require xenomorph) +(provide glyf) #| approximates https://github.com/mbutterick/fontkit/blob/master/src/tables/glyf.js @@ -10,14 +8,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/glyf.js (define glyf (x:array #:type (x:buffer))) -(test-module - (require sugar/unstable/js - sugar/unstable/port) +(module+ test + (require rackunit racket/serialize "../helper.rkt") (define ip (open-input-file charter-path)) (define dir (deserialize (read (open-input-file charter-directory-path)))) - (define offset (· dir tables glyf offset)) - (define len (· dir tables glyf length)) + (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'glyf) 'offset)) + (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'glyf) 'length)) (check-equal? offset 4620) (check-equal? len 34072) - (set-port-position! ip 0) + (file-position ip 0) (define table-bytes (peek-bytes len offset ip))) diff --git a/fontland/fontland/table/head.rkt b/fontland/fontland/table/head.rkt index 148e0b0a..2f49232e 100644 --- a/fontland/fontland/table/head.rkt +++ b/fontland/fontland/table/head.rkt @@ -1,16 +1,12 @@ #lang racket/base -(require "../helper.rkt" - sugar/unstable/class - sugar/unstable/dict - xenomorph) -(provide (all-defined-out)) +(require xenomorph) +(provide head) #| approximates https://github.com/mbutterick/fontkit/blob/master/src/tables/head.js |# - (define head (x:struct 'version int32be ;; 0x00010000 (version 1.0) 'revision int32be ;; set by font manufacturer @@ -34,32 +30,30 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/head.js (module+ test - (require rackunit - racket/serialize - sugar/unstable/js - sugar/unstable/port) + (require rackunit "../helper.rkt" + racket/serialize) (define ip (open-input-file charter-italic-path)) (define dir (deserialize (read (open-input-file charter-italic-directory-path)))) - (define offset (· dir tables head offset)) - (define length (· dir tables head length)) + (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'head) 'offset)) + (define length (hash-ref (hash-ref (hash-ref dir 'tables) 'head) 'length)) (check-equal? offset 236) (check-equal? length 54) (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) + (file-position ip 0) (check-equal? (peek-bytes length offset ip) table-bytes) (define table-data (decode head 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-hasheq '((shadow . #f) + (check-equal? (hash-ref table-data 'unitsPerEm) 1000) + (check-equal? (hash-ref table-data 'yMin) -236) + (check-equal? (hash-ref table-data 'yMax) 980) + (check-equal? (hash-ref table-data 'xMax) 1174) + (check-equal? (hash-ref table-data 'xMin) -226) + (check-equal? (hash-ref 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? (hash-ref table-data 'magicNumber) #x5F0F3CF5) + (check-equal? (hash-ref table-data 'indexToLocFormat) 0) ; used in loca table (check-equal? (encode head table-data #f) table-bytes)) \ No newline at end of file diff --git a/fontland/fontland/table/hhea.rkt b/fontland/fontland/table/hhea.rkt index b654fdca..bdc156c4 100644 --- a/fontland/fontland/table/hhea.rkt +++ b/fontland/fontland/table/hhea.rkt @@ -1,9 +1,6 @@ #lang racket/base -(require sugar/unstable/class - sugar/unstable/dict - "../helper.rkt" - xenomorph) -(provide (all-defined-out)) +(require xenomorph sugar/unstable/dict) +(provide hhea) (define hhea (x:struct (dictify @@ -24,21 +21,19 @@ ))) (module+ test - (require rackunit - racket/serialize - sugar/unstable/js - sugar/unstable/port) + (require rackunit "../helper.rkt" + racket/serialize) (define ip (open-input-file charter-path)) (define dir (deserialize (read (open-input-file charter-directory-path)))) - (define offset (· dir tables hhea offset)) - (define length (· dir tables hhea length)) + (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'hhea) 'offset)) + (define length (hash-ref (hash-ref (hash-ref dir 'tables) 'hhea) 'length)) (check-equal? offset 292) (check-equal? length 36) (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) + (file-position ip 0) (check-equal? (peek-bytes length offset ip) 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)) + (check-equal? (hash-ref table-data 'ascent) 980) + (check-equal? (hash-ref table-data 'descent) -238) + (check-equal? (hash-ref table-data 'numberOfMetrics) 229)) diff --git a/fontland/fontland/table/hmtx.rkt b/fontland/fontland/table/hmtx.rkt index d4f66c8d..66ec4eb7 100644 --- a/fontland/fontland/table/hmtx.rkt +++ b/fontland/fontland/table/hmtx.rkt @@ -1,10 +1,7 @@ #lang racket/base -(require sugar/unstable/class - sugar/unstable/dict - sugar/unstable/js - "../helper.rkt" - xenomorph) +(require xenomorph) (provide (all-defined-out)) + #| approximates https://github.com/mbutterick/fontkit/blob/master/src/tables/hmtx.js @@ -13,26 +10,26 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/hmtx.js (define hmtx-entry (x:struct 'advance uint16be 'bearing int16be)) (define hmtx (x:struct 'metrics (x:lazy-array #:type hmtx-entry - #:length (λ (arr) (· arr parent hhea numberOfMetrics))) + #:length (λ (arr) (hash-ref (hash-ref (hash-ref arr 'parent) 'hhea) 'numberOfMetrics))) 'bearings (x:lazy-array #:type int16be - #:length (λ (arr) (- (· arr parent maxp numGlyphs) - (· arr parent hhea numberOfMetrics)))))) + #:length (λ (arr) (- (hash-ref (hash-ref (hash-ref arr 'parent) 'maxp) 'numGlyphs) + (hash-ref (hash-ref (hash-ref arr 'parent) 'hhea) 'numberOfMetrics)))))) (module+ test - (require rackunit racket/serialize racket/stream) + (require rackunit racket/serialize racket/stream "../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)) 'bearing (x:lazy-array int16be (λ (t) 0)))) (define ip (open-input-file charter-path)) (define dir (deserialize (read (open-input-file charter-directory-path)))) - (define hmtx-offset (· dir tables hmtx offset)) - (define hmtx-length (· dir tables hmtx length)) + (define hmtx-offset (hash-ref (hash-ref (hash-ref dir 'tables) 'hmtx) 'offset)) + (define hmtx-length (hash-ref (hash-ref (hash-ref dir 'tables) 'hmtx) 'length)) (check-equal? hmtx-offset 456) (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))) (define H-gid 41) (define OE-gid 142) - (check-equal? (stream-ref (· hmtx-data metrics) H-gid) (make-hasheq '((bearing . 33) (advance . 738)))) - (check-equal? (stream-ref (· hmtx-data metrics) OE-gid) (make-hasheq '((bearing . 43) (advance . 993))))) \ No newline at end of file + (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))))) \ No newline at end of file diff --git a/fontland/fontland/table/loca.rkt b/fontland/fontland/table/loca.rkt index 789ccefb..530d9b07 100644 --- a/fontland/fontland/table/loca.rkt +++ b/fontland/fontland/table/loca.rkt @@ -1,15 +1,10 @@ #lang debug racket/base (require xenomorph - sugar/unstable/class - sugar/unstable/js - racket/dict sugar/unstable/dict - racket/class racket/list racket/promise - "../struct.rkt" - "../helper.rkt") -(provide (all-defined-out)) + "../struct.rkt") +(provide loca) (define 16bit-style 0) (define 32bit-style 1) @@ -20,21 +15,20 @@ approximates https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js |# - (define (loca-pre-encode val) - (unless (dict-has-key? val x:version-key) - (dict-set! val x:version-key (if (> (last (· val offsets)) max-32-bit-value) + (unless (hash-has-key? val x:version-key) + (hash-set! val x:version-key (if (> (last (hash-ref val 'offsets)) max-32-bit-value) 32bit-style 16bit-style)) - (when (= 16bit-style (dict-ref val x:version-key)) - (dict-update! val 'offsets (λ (offsets) (map (λ (x) (/ x 2)) offsets))))) + (when (= 16bit-style (hash-ref val x:version-key)) + (hash-update! val 'offsets (λ (offsets) (map (λ (x) (/ x 2)) offsets))))) val) (define (loca-post-decode val) - (when (= 16bit-style (dict-ref val x:version-key)) + (when (= 16bit-style (hash-ref val x:version-key)) ;; in a 16bits-style loca table, actual 32bit offset values are divided by 2 (to fit into 16 bits) ;; so we re-inflate them. - (dict-update! val 'offsets (λ (offsets) (map (λ (x) (* 2 x)) offsets)))) + (hash-update! val 'offsets (λ (offsets) (map (λ (x) (* 2 x)) offsets)))) val) (define loca (x:versioned-struct @@ -55,15 +49,15 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js 1 (dictify 'offsets (x:array #:type uint32be))))) (module+ test - (require rackunit racket/serialize) + (require rackunit racket/serialize "../helper.rkt") (check-equal? (encode loca (mhasheq x:version-key 0 'offsets '(0 76 156)) #f) #"\0\0\0L\0\234") (check-equal? (encode loca (mhasheq x:version-key 1 'offsets '(0 76 156)) #f) #"\0\0\0\0\0\0\0L\0\0\0\234") (define ip (open-input-file charter-path)) (define dir (deserialize (read (open-input-file charter-directory-path)))) - (define offset (dict-ref (dict-ref (dict-ref dir 'tables) 'loca) 'offset)) - (define len (dict-ref (dict-ref (dict-ref dir 'tables) 'loca) 'length)) + (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'loca) 'offset)) + (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'loca) 'length)) (check-equal? offset 38692) (check-equal? len 460) (define offset-bytes (peek-bytes len offset ip)) diff --git a/fontland/fontland/table/maxp.rkt b/fontland/fontland/table/maxp.rkt index 7dc0a5f5..15eaf861 100644 --- a/fontland/fontland/table/maxp.rkt +++ b/fontland/fontland/table/maxp.rkt @@ -1,9 +1,6 @@ #lang racket/base -(require xenomorph - sugar/unstable/class - sugar/unstable/dict - "../helper.rkt") -(provide (all-defined-out)) +(require xenomorph) +(provide maxp) (define maxp (x:struct 'version int32be @@ -23,20 +20,17 @@ 'maxComponentDepth uint16be ;; Maximum levels of recursion; 1 for simple components )) - (module+ test - (require rackunit racket/serialize - sugar/unstable/js - sugar/unstable/port) + (require rackunit racket/serialize "../helper.rkt") (define ip (open-input-file charter-path)) (define dir (deserialize (read (open-input-file charter-directory-path)))) - (define maxp-offset (· dir tables maxp offset)) - (define maxp-length (· dir tables maxp length)) + (define maxp-offset (hash-ref (hash-ref (hash-ref dir 'tables) 'maxp) 'offset)) + (define maxp-length (hash-ref (hash-ref (hash-ref dir 'tables) 'maxp) 'length)) (check-equal? maxp-offset 328) (check-equal? maxp-length 32) (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) + (file-position ip 0) (check-equal? (peek-bytes maxp-length maxp-offset ip) maxp-bytes) (define maxp-data (decode maxp maxp-bytes)) - (check-equal? (· maxp-data numGlyphs) 229) - (check-equal? (· maxp-data version) 65536)) \ No newline at end of file + (check-equal? (hash-ref maxp-data 'numGlyphs) 229) + (check-equal? (hash-ref maxp-data 'version) 65536)) \ No newline at end of file diff --git a/fontland/fontland/table/post.rkt b/fontland/fontland/table/post.rkt index 728ef4b8..6a923da0 100644 --- a/fontland/fontland/table/post.rkt +++ b/fontland/fontland/table/post.rkt @@ -1,10 +1,7 @@ #lang racket/base (require xenomorph - sugar/unstable/class - sugar/unstable/dict - sugar/unstable/js - "../helper.rkt") -(provide (all-defined-out)) + sugar/unstable/dict) +(provide post) #| approximates @@ -31,23 +28,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/post.js 2.5 (dictify 'numberOfGlyphs uint16be 'offsets (x:array #:type uint8)) 3 null - 4 (dictify 'map (x:array #:type uint32be #:length (λ (t) (· t parent maxp numGlyphs))))))) + 4 (dictify 'map (x:array #:type uint32be #:length (λ (t) (hash-ref (hash-ref (hash-ref t 'parent) 'maxp) 'numGlyphs))))))) (module+ test - (require rackunit racket/serialize racket/class) + (require rackunit racket/serialize racket/class "../helper.rkt") (define ip (open-input-file charter-path)) (define dir (deserialize (read (open-input-file charter-directory-path)))) - (define offset (· dir tables post offset)) - (define len (· dir tables post length)) + (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'post) 'offset)) + (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'post) 'length)) (check-equal? offset 41520) - (check-equal? len 514) - (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 (decode post ds)) - (check-equal? (· table-data underlineThickness) 58) - (check-equal? (· table-data underlinePosition) -178) - (check-equal? (· table-data names) '("periodcentered" "macron")) -|# - ) \ No newline at end of file + (check-equal? len 514)) \ No newline at end of file diff --git a/fontland/fontland/table/prep.rkt b/fontland/fontland/table/prep.rkt index 6f329d83..f032422f 100644 --- a/fontland/fontland/table/prep.rkt +++ b/fontland/fontland/table/prep.rkt @@ -1,9 +1,7 @@ #lang racket/base -(require sugar/unstable/dict - sugar/unstable/js - "../helper.rkt" - xenomorph) -(provide (all-defined-out)) +(require sugar/unstable/dict xenomorph) +(provide prep) + #| approximates https://github.com/mbutterick/fontkit/blob/master/src/tables/prep.js @@ -12,14 +10,14 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/prep.js (define prep (x:struct 'controlValueProgram (x:array #:type uint8))) (module+ test - (require rackunit racket/dict racket/serialize sugar/unstable/port) + (require rackunit racket/dict racket/serialize "../helper.rkt") (define ip (open-input-file charter-path)) (define dir (deserialize (read (open-input-file charter-directory-path)))) - (define offset (· dir tables prep offset)) - (define len (· dir tables prep length)) + (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'prep) 'offset)) + (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'prep) 'length)) (check-equal? offset 4512) (check-equal? len 78) - (set-port-position! ip 0) + (file-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 (open-input-bytes (peek-bytes len offset ip)))