main
Matthew Butterick 6 years ago
parent 35c01c67f8
commit 2d050f5619

@ -1,6 +1,5 @@
#lang racket/base #lang racket/base
(require sugar/unstable/class (require xenomorph)
xenomorph)
(provide CFF_) (provide CFF_)
#| #|

@ -1,9 +1,6 @@
#lang racket/base #lang racket/base
(require xenomorph (require xenomorph sugar/unstable/dict)
sugar/unstable/class (provide OS/2)
sugar/unstable/dict
"../helper.rkt")
(provide (all-defined-out))
#| #|
approximates approximates
@ -67,16 +64,10 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/OS2.js
5 (append type-1 type-2 type-5))))) 5 (append type-1 type-2 type-5)))))
(module+ test (module+ test
(require rackunit racket/serialize sugar/unstable/js) (require rackunit racket/serialize "../helper.rkt")
(define ip (open-input-file charter-path)) (define ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path)))) (define dir (deserialize (read (open-input-file charter-directory-path))))
(define offset (· dir tables OS/2 offset)) (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'OS/2) 'offset))
(define len (· dir tables OS/2 length)) (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'OS/2) 'length))
(check-equal? offset 360) (check-equal? offset 360)
(check-equal? len 96) (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))

@ -1,10 +1,6 @@
#lang racket/base #lang racket/base
(require sugar/unstable/class (require xenomorph)
sugar/unstable/dict (provide cvt_)
"../helper.rkt"
racket/dict
xenomorph)
(provide (all-defined-out))
#| #|
approximates 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))) (define cvt_ (x:struct 'controlValues (x:array #:type int16be)))
(module+ test (module+ test
(require rackunit racket/serialize (require rackunit racket/serialize "../helper.rkt")
sugar/unstable/js
sugar/unstable/port)
(define ip (open-input-file charter-path)) (define ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path)))) (define dir (deserialize (read (open-input-file charter-directory-path))))
(define offset (· dir tables cvt_ offset)) (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'cvt_) 'offset))
(define len (· dir tables cvt_ length)) (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'cvt_) 'length))
(check-equal? offset 4592) (check-equal? offset 4592)
(check-equal? len 26) (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") (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)) (check-equal? table-bytes (peek-bytes len offset ip))
(define ds (open-input-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)) (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? (hash-ref (decode cvt_ ds) 'controlValues) cvt-array)
(check-equal? (encode cvt_ (mhash 'controlValues cvt-array) #f) table-bytes)) (check-equal? (encode cvt_ (make-hash (list (cons 'controlValues cvt-array))) #f) table-bytes))

@ -1,8 +1,6 @@
#lang racket/base #lang racket/base
(require sugar/unstable/dict (require xenomorph)
"../helper.rkt" (provide fpgm)
xenomorph)
(provide (all-defined-out))
#| #|
approximates approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/fpgm.js 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))) (define fpgm (x:struct 'instructions (x:array #:type uint8)))
(module+ test (module+ test
(require rackunit racket/serialize racket/dict (require rackunit racket/serialize "../helper.rkt")
sugar/unstable/js
racket/class)
(define ip (open-input-file charter-path)) (define ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path)))) (define dir (deserialize (read (open-input-file charter-directory-path))))
(define offset (· dir tables fpgm offset)) (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'fpgm) 'offset))
(define len (· dir tables fpgm length)) (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'fpgm) 'length))
(check-equal? offset 4140) (check-equal? offset 4140)
(check-equal? len 371) (check-equal? len 371)
(check-equal? (pos ip 0) 0) (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)))

@ -1,8 +1,6 @@
#lang racket/base #lang racket/base
(require sugar/unstable/class (require xenomorph)
"../helper.rkt" (provide glyf)
xenomorph)
(provide (all-defined-out))
#| #|
approximates approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/glyf.js 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))) (define glyf (x:array #:type (x:buffer)))
(test-module (module+ test
(require sugar/unstable/js (require rackunit racket/serialize "../helper.rkt")
sugar/unstable/port)
(define ip (open-input-file charter-path)) (define ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path)))) (define dir (deserialize (read (open-input-file charter-directory-path))))
(define offset (· dir tables glyf offset)) (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'glyf) 'offset))
(define len (· dir tables glyf length)) (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'glyf) 'length))
(check-equal? offset 4620) (check-equal? offset 4620)
(check-equal? len 34072) (check-equal? len 34072)
(set-port-position! ip 0) (file-position ip 0)
(define table-bytes (peek-bytes len offset ip))) (define table-bytes (peek-bytes len offset ip)))

@ -1,16 +1,12 @@
#lang racket/base #lang racket/base
(require "../helper.rkt" (require xenomorph)
sugar/unstable/class (provide head)
sugar/unstable/dict
xenomorph)
(provide (all-defined-out))
#| #|
approximates approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/head.js https://github.com/mbutterick/fontkit/blob/master/src/tables/head.js
|# |#
(define head (x:struct (define head (x:struct
'version int32be ;; 0x00010000 (version 1.0) 'version int32be ;; 0x00010000 (version 1.0)
'revision int32be ;; set by font manufacturer 'revision int32be ;; set by font manufacturer
@ -34,32 +30,30 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/head.js
(module+ test (module+ test
(require rackunit (require rackunit "../helper.rkt"
racket/serialize racket/serialize)
sugar/unstable/js
sugar/unstable/port)
(define ip (open-input-file charter-italic-path)) (define ip (open-input-file charter-italic-path))
(define dir (deserialize (read (open-input-file charter-italic-directory-path)))) (define dir (deserialize (read (open-input-file charter-italic-directory-path))))
(define offset (· dir tables head offset)) (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'head) 'offset))
(define length (· dir tables head length)) (define length (hash-ref (hash-ref (hash-ref dir 'tables) 'head) 'length))
(check-equal? offset 236) (check-equal? offset 236)
(check-equal? length 54) (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") (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) (check-equal? (peek-bytes length offset ip) table-bytes)
(define table-data (decode head table-bytes)) (define table-data (decode head table-bytes))
(check-equal? (· table-data unitsPerEm) 1000) (check-equal? (hash-ref table-data 'unitsPerEm) 1000)
(check-equal? (· table-data yMin) -236) (check-equal? (hash-ref table-data 'yMin) -236)
(check-equal? (· table-data yMax) 980) (check-equal? (hash-ref table-data 'yMax) 980)
(check-equal? (· table-data xMax) 1174) (check-equal? (hash-ref table-data 'xMax) 1174)
(check-equal? (· table-data xMin) -226) (check-equal? (hash-ref table-data 'xMin) -226)
(check-equal? (· table-data macStyle) (make-hasheq '((shadow . #f) (check-equal? (hash-ref table-data 'macStyle) (make-hasheq '((shadow . #f)
(extended . #f) (extended . #f)
(condensed . #f) (condensed . #f)
(underline . #f) (underline . #f)
(outline . #f) (outline . #f)
(bold . #f) (bold . #f)
(italic . #t)))) (italic . #t))))
(check-equal? (· table-data magicNumber) #x5F0F3CF5) (check-equal? (hash-ref table-data 'magicNumber) #x5F0F3CF5)
(check-equal? (· table-data indexToLocFormat) 0) ; used in loca table (check-equal? (hash-ref table-data 'indexToLocFormat) 0) ; used in loca table
(check-equal? (encode head table-data #f) table-bytes)) (check-equal? (encode head table-data #f) table-bytes))

@ -1,9 +1,6 @@
#lang racket/base #lang racket/base
(require sugar/unstable/class (require xenomorph sugar/unstable/dict)
sugar/unstable/dict (provide hhea)
"../helper.rkt"
xenomorph)
(provide (all-defined-out))
(define hhea (x:struct (define hhea (x:struct
(dictify (dictify
@ -24,21 +21,19 @@
))) )))
(module+ test (module+ test
(require rackunit (require rackunit "../helper.rkt"
racket/serialize racket/serialize)
sugar/unstable/js
sugar/unstable/port)
(define ip (open-input-file charter-path)) (define ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path)))) (define dir (deserialize (read (open-input-file charter-directory-path))))
(define offset (· dir tables hhea offset)) (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'hhea) 'offset))
(define length (· dir tables hhea length)) (define length (hash-ref (hash-ref (hash-ref dir 'tables) 'hhea) 'length))
(check-equal? offset 292) (check-equal? offset 292)
(check-equal? length 36) (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") (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) (check-equal? (peek-bytes length offset ip) table-bytes)
(define table-data (decode hhea table-bytes)) (define table-data (decode hhea table-bytes))
(check-equal? (· table-data ascent) 980) (check-equal? (hash-ref table-data 'ascent) 980)
(check-equal? (· table-data descent) -238) (check-equal? (hash-ref table-data 'descent) -238)
(check-equal? (· table-data numberOfMetrics) 229)) (check-equal? (hash-ref table-data 'numberOfMetrics) 229))

@ -1,10 +1,7 @@
#lang racket/base #lang racket/base
(require sugar/unstable/class (require xenomorph)
sugar/unstable/dict
sugar/unstable/js
"../helper.rkt"
xenomorph)
(provide (all-defined-out)) (provide (all-defined-out))
#| #|
approximates approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/hmtx.js 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-entry (x:struct 'advance uint16be 'bearing int16be))
(define hmtx (x:struct 'metrics (x:lazy-array #:type hmtx-entry (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 'bearings (x:lazy-array #:type int16be
#:length (λ (arr) (- (· arr parent maxp numGlyphs) #:length (λ (arr) (- (hash-ref (hash-ref (hash-ref arr 'parent) 'maxp) 'numGlyphs)
(· arr parent hhea numberOfMetrics)))))) (hash-ref (hash-ref (hash-ref arr 'parent) 'hhea) 'numberOfMetrics))))))
(module+ test (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 ;; same as hmtx but doesn't require resolution of function to get length
(define hmtx-test (x:struct (define hmtx-test (x:struct
'metrics (x:lazy-array hmtx-entry (λ (t) 229)) 'metrics (x:lazy-array hmtx-entry (λ (t) 229))
'bearing (x:lazy-array int16be (λ (t) 0)))) 'bearing (x:lazy-array int16be (λ (t) 0))))
(define ip (open-input-file charter-path)) (define ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path)))) (define dir (deserialize (read (open-input-file charter-directory-path))))
(define hmtx-offset (· dir tables hmtx offset)) (define hmtx-offset (hash-ref (hash-ref (hash-ref dir 'tables) 'hmtx) 'offset))
(define hmtx-length (· dir tables hmtx length)) (define hmtx-length (hash-ref (hash-ref (hash-ref dir 'tables) 'hmtx) 'length))
(check-equal? hmtx-offset 456) (check-equal? hmtx-offset 456)
(check-equal? hmtx-length 916) (check-equal? hmtx-length 916)
(define hmtx-bytes (peek-bytes hmtx-length hmtx-offset ip)) (define hmtx-bytes (peek-bytes hmtx-length hmtx-offset ip))
(define hmtx-data (decode hmtx-test hmtx-bytes)) (define hmtx-data (decode hmtx-test hmtx-bytes))
(check-equal? (size hmtx-test) (* 229 (size hmtx-entry))) (check-equal? (size hmtx-test) (* 229 (size hmtx-entry)))
(define H-gid 41) (define OE-gid 142) (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 (hash-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))))) (check-equal? (stream-ref (hash-ref hmtx-data 'metrics) OE-gid) (make-hasheq '((bearing . 43) (advance . 993)))))

@ -1,15 +1,10 @@
#lang debug racket/base #lang debug racket/base
(require xenomorph (require xenomorph
sugar/unstable/class
sugar/unstable/js
racket/dict
sugar/unstable/dict sugar/unstable/dict
racket/class
racket/list racket/list
racket/promise racket/promise
"../struct.rkt" "../struct.rkt")
"../helper.rkt") (provide loca)
(provide (all-defined-out))
(define 16bit-style 0) (define 16bit-style 0)
(define 32bit-style 1) (define 32bit-style 1)
@ -20,21 +15,20 @@ approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js
|# |#
(define (loca-pre-encode val) (define (loca-pre-encode val)
(unless (dict-has-key? val x:version-key) (unless (hash-has-key? val x:version-key)
(dict-set! val x:version-key (if (> (last (· val offsets)) max-32-bit-value) (hash-set! val x:version-key (if (> (last (hash-ref val 'offsets)) max-32-bit-value)
32bit-style 32bit-style
16bit-style)) 16bit-style))
(when (= 16bit-style (dict-ref val x:version-key)) (when (= 16bit-style (hash-ref val x:version-key))
(dict-update! val 'offsets (λ (offsets) (map (λ (x) (/ x 2)) offsets))))) (hash-update! val 'offsets (λ (offsets) (map (λ (x) (/ x 2)) offsets)))))
val) val)
(define (loca-post-decode 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) ;; in a 16bits-style loca table, actual 32bit offset values are divided by 2 (to fit into 16 bits)
;; so we re-inflate them. ;; 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) val)
(define loca (x:versioned-struct (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))))) 1 (dictify 'offsets (x:array #:type uint32be)))))
(module+ test (module+ test
(require rackunit racket/serialize) (require rackunit racket/serialize "../helper.rkt")
(check-equal? (check-equal?
(encode loca (mhasheq x:version-key 0 'offsets '(0 76 156)) #f) #"\0\0\0L\0\234") (encode loca (mhasheq x:version-key 0 'offsets '(0 76 156)) #f) #"\0\0\0L\0\234")
(check-equal? (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") (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 ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path)))) (define dir (deserialize (read (open-input-file charter-directory-path))))
(define offset (dict-ref (dict-ref (dict-ref dir 'tables) 'loca) 'offset)) (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'loca) 'offset))
(define len (dict-ref (dict-ref (dict-ref dir 'tables) 'loca) 'length)) (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'loca) 'length))
(check-equal? offset 38692) (check-equal? offset 38692)
(check-equal? len 460) (check-equal? len 460)
(define offset-bytes (peek-bytes len offset ip)) (define offset-bytes (peek-bytes len offset ip))

@ -1,9 +1,6 @@
#lang racket/base #lang racket/base
(require xenomorph (require xenomorph)
sugar/unstable/class (provide maxp)
sugar/unstable/dict
"../helper.rkt")
(provide (all-defined-out))
(define maxp (x:struct (define maxp (x:struct
'version int32be 'version int32be
@ -23,20 +20,17 @@
'maxComponentDepth uint16be ;; Maximum levels of recursion; 1 for simple components 'maxComponentDepth uint16be ;; Maximum levels of recursion; 1 for simple components
)) ))
(module+ test (module+ test
(require rackunit racket/serialize (require rackunit racket/serialize "../helper.rkt")
sugar/unstable/js
sugar/unstable/port)
(define ip (open-input-file charter-path)) (define ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path)))) (define dir (deserialize (read (open-input-file charter-directory-path))))
(define maxp-offset (· dir tables maxp offset)) (define maxp-offset (hash-ref (hash-ref (hash-ref dir 'tables) 'maxp) 'offset))
(define maxp-length (· dir tables maxp length)) (define maxp-length (hash-ref (hash-ref (hash-ref dir 'tables) 'maxp) 'length))
(check-equal? maxp-offset 328) (check-equal? maxp-offset 328)
(check-equal? maxp-length 32) (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") (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) (check-equal? (peek-bytes maxp-length maxp-offset ip) maxp-bytes)
(define maxp-data (decode maxp maxp-bytes)) (define maxp-data (decode maxp maxp-bytes))
(check-equal? (· maxp-data numGlyphs) 229) (check-equal? (hash-ref maxp-data 'numGlyphs) 229)
(check-equal? (· maxp-data version) 65536)) (check-equal? (hash-ref maxp-data 'version) 65536))

@ -1,10 +1,7 @@
#lang racket/base #lang racket/base
(require xenomorph (require xenomorph
sugar/unstable/class sugar/unstable/dict)
sugar/unstable/dict (provide post)
sugar/unstable/js
"../helper.rkt")
(provide (all-defined-out))
#| #|
approximates approximates
@ -31,23 +28,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/post.js
2.5 (dictify 'numberOfGlyphs uint16be 2.5 (dictify 'numberOfGlyphs uint16be
'offsets (x:array #:type uint8)) 'offsets (x:array #:type uint8))
3 null 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 (module+ test
(require rackunit racket/serialize racket/class) (require rackunit racket/serialize racket/class "../helper.rkt")
(define ip (open-input-file charter-path)) (define ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path)))) (define dir (deserialize (read (open-input-file charter-directory-path))))
(define offset (· dir tables post offset)) (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'post) 'offset))
(define len (· dir tables post length)) (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'post) 'length))
(check-equal? offset 41520) (check-equal? offset 41520)
(check-equal? len 514) (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"))
|#
)

@ -1,9 +1,7 @@
#lang racket/base #lang racket/base
(require sugar/unstable/dict (require sugar/unstable/dict xenomorph)
sugar/unstable/js (provide prep)
"../helper.rkt"
xenomorph)
(provide (all-defined-out))
#| #|
approximates approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/prep.js 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))) (define prep (x:struct 'controlValueProgram (x:array #:type uint8)))
(module+ test (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 ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path)))) (define dir (deserialize (read (open-input-file charter-directory-path))))
(define offset (· dir tables prep offset)) (define offset (hash-ref (hash-ref (hash-ref dir 'tables) 'prep) 'offset))
(define len (· dir tables prep length)) (define len (hash-ref (hash-ref (hash-ref dir 'tables) 'prep) 'length))
(check-equal? offset 4512) (check-equal? offset 4512)
(check-equal? len 78) (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") (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)) (check-equal? table-bytes (peek-bytes len offset ip))
(define ds (open-input-bytes (peek-bytes len offset ip))) (define ds (open-input-bytes (peek-bytes len offset ip)))

Loading…
Cancel
Save