main
Matthew Butterick 8 years ago
parent 5c879ccb92
commit a6df884510

@ -0,0 +1,32 @@
((3)
0
()
0
()
()
(h
!
()
(tag u . "\u0000\u0001\u0000\u0000")
(rangeShift . 96)
(searchRange . 128)
(numTables . 14)
(entrySelector . 3)
(tables
h
!
(equal)
(loca h ! () (tag u . "loca") (offset . 38692) (checkSum . 2795817194) (length . 460))
(glyf h ! () (tag u . "glyf") (offset . 4620) (checkSum . 1143629849) (length . 34072))
(OS/2 h ! () (tag u . "OS/2") (offset . 360) (checkSum . 2351070438) (length . 96))
(hhea h ! () (tag u . "hhea") (offset . 292) (checkSum . 132056097) (length . 36))
(post h ! () (tag u . "post") (offset . 41520) (checkSum . 1670855689) (length . 514))
(|cvt | h ! () (tag u . "cvt ") (offset . 4592) (checkSum . 10290865) (length . 26))
(VDMX h ! () (tag u . "VDMX") (offset . 1372) (checkSum . 1887795202) (length . 1504))
(prep h ! () (tag u . "prep") (offset . 4512) (checkSum . 490862356) (length . 78))
(maxp h ! () (tag u . "maxp") (offset . 328) (checkSum . 50135594) (length . 32))
(hmtx h ! () (tag u . "hmtx") (offset . 456) (checkSum . 3982043058) (length . 916))
(cmap h ! () (tag u . "cmap") (offset . 2876) (checkSum . 1723761408) (length . 1262))
(name h ! () (tag u . "name") (offset . 39152) (checkSum . 2629707307) (length . 2367))
(head h ! () (tag u . "head") (offset . 236) (checkSum . 4281190895) (length . 54))
(fpgm h ! () (tag u . "fpgm") (offset . 4140) (checkSum . 106535991) (length . 371)))))

@ -0,0 +1,32 @@
((3)
0
()
0
()
()
(h
!
()
(tag u . "\u0000\u0001\u0000\u0000")
(rangeShift . 96)
(searchRange . 128)
(numTables . 14)
(entrySelector . 3)
(tables
h
!
(equal)
(loca h ! () (tag u . "loca") (offset . 37392) (checkSum . 46801904) (length . 460))
(glyf h ! () (tag u . "glyf") (offset . 4620) (checkSum . 2099535230) (length . 32772))
(OS/2 h ! () (tag u . "OS/2") (offset . 360) (checkSum . 2367847603) (length . 96))
(hhea h ! () (tag u . "hhea") (offset . 292) (checkSum . 113838023) (length . 36))
(post h ! () (tag u . "post") (offset . 40280) (checkSum . 1671576585) (length . 514))
(|cvt | h ! () (tag u . "cvt ") (offset . 4592) (checkSum . 9307818) (length . 26))
(VDMX h ! () (tag u . "VDMX") (offset . 1372) (checkSum . 1905948947) (length . 1504))
(prep h ! () (tag u . "prep") (offset . 4512) (checkSum . 776081685) (length . 78))
(maxp h ! () (tag u . "maxp") (offset . 328) (checkSum . 50135583) (length . 32))
(hmtx h ! () (tag u . "hmtx") (offset . 456) (checkSum . 3798537071) (length . 916))
(cmap h ! () (tag u . "cmap") (offset . 2876) (checkSum . 1723761408) (length . 1262))
(name h ! () (tag u . "name") (offset . 37852) (checkSum . 2313429994) (length . 2427))
(head h ! () (tag u . "head") (offset . 236) (checkSum . 4275817075) (length . 54))
(fpgm h ! () (tag u . "fpgm") (offset . 4140) (checkSum . 106535991) (length . 371)))))

@ -18,4 +18,385 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/fpgm.js
'instructions (make-object Array uint8))))
(test-module
(require racket/serialize)
(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))
(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)))

@ -31,4 +31,29 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/head.js
)))
(test-module
(require 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))
(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)
(check-equal? (peek-bytes length offset ip) table-bytes)
(define table-data (send head decode (+DecodeStream 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 magicNumber) #x5F0F3CF5)
(check-equal? (· table-data indexToLocFormat) 0)) ; used in loca table

@ -6,6 +6,8 @@
(define-runtime-path charter-path "../pitfall/test/assets/charter.ttf")
(define-runtime-path charter-italic-path "../pitfall/test/assets/charter-italic.ttf")
(define-runtime-path charter-directory-path "charter-directory.rktd")
(define-runtime-path charter-italic-directory-path "charter-italic-directory.rktd")
(define-macro (test-module . EXPRS)
#`(module+ test

@ -22,5 +22,18 @@
'numberOfMetrics uint16be ;; Number of advance widths in 'hmtx' table
)))
(test-module
(require 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))
(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)
(check-equal? (peek-bytes length offset ip) table-bytes)
(define table-data (send hhea decode (+DecodeStream table-bytes)))
(check-equal? (· table-data ascent) 980)
(check-equal? (· table-data descent) -238))

@ -42,4 +42,245 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js
)))
(test-module
(require racket/serialize)
(define ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path))))
(define offset (· dir tables loca offset))
(define len (· dir tables loca length))
(check-equal? offset 38692)
(check-equal? len 460)
(set-port-position! ip 0)
(define ds (+DecodeStream (peek-bytes len offset ip)))
(define table-data (send loca decode ds #:version 0))
(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)))

@ -22,3 +22,18 @@
'maxComponentDepth uint16be ;; Maximum levels of recursion; 1 for simple components
)))
(test-module
(require racket/serialize)
(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))
(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)
(check-equal? (peek-bytes maxp-length maxp-offset ip) maxp-bytes)
(define maxp-data (send maxp decode (+DecodeStream maxp-bytes)))
(check-equal? (· maxp-data numGlyphs) 229)
(check-equal? (· maxp-data version) 65536))

@ -13,4 +13,93 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/prep.js
'controlValueProgram (+Array uint8))))
(test-module
(require racket/serialize)
(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))
(check-equal? offset 4512)
(check-equal? len 78)
(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)))

@ -1,775 +0,0 @@
#lang fontkit/racket
(require "directory.rkt")
(require rackunit "tables.rkt" restructure)
(define ip (open-input-file charter-path))
(define dir (directory-decode ip))
;; maxp
(let ()
(define maxp-offset (· dir tables maxp offset))
(define maxp-length (· 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)
(check-equal? (peek-bytes maxp-length maxp-offset ip) maxp-bytes)
(define maxp-data (send maxp decode (+DecodeStream maxp-bytes)))
(check-equal? (· maxp-data numGlyphs) 229)
(check-equal? (· maxp-data version) 65536))
;; hhea
(let ()
(define offset (· dir tables hhea offset))
(define length (· 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)
(check-equal? (peek-bytes length offset ip) table-bytes)
(define table-data (send hhea decode (+DecodeStream table-bytes)))
(check-equal? (· table-data ascent) 980)
(check-equal? (· table-data descent) -238))
;; head
(let ()
(define ip (open-input-file charter-italic-path)) ; use italic to make sure style flags are set correctly
(define dir (directory-decode ip))
(define offset (· dir tables head offset))
(define length (· 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)
(check-equal? (peek-bytes length offset ip) table-bytes)
(define table-data (send head decode (+DecodeStream 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 magicNumber) #x5F0F3CF5)
(check-equal? (· table-data indexToLocFormat) 0) ; used in loca table
)
;; prep
(let ()
(define offset (· dir tables prep offset))
(define len (· dir tables prep length))
(check-equal? offset 4512)
(check-equal? len 78)
(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)))
;; fpgm
(let ()
(define offset (· dir tables fpgm offset))
(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)))
;; loca
(let ()
(define offset (· dir tables loca offset))
(define len (· dir tables loca length))
(check-equal? offset 38692)
(check-equal? len 460)
(set-port-position! ip 0)
(define ds (+DecodeStream (peek-bytes len offset ip)))
(define table-data (send loca decode ds #:version 0))
(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)))

@ -7,20 +7,20 @@ approximates
https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
|#
(define-subclass RestructureBase (Struct [assocs (dictify)])
(define-subclass Streamcoder (Struct [assocs (dictify)])
(field [key-index (map car assocs)] ; store the original key order
[struct-types (mhash)])
(for ([(k v) (in-dict assocs)])
(hash-set! struct-types k v))
(define/override (decode stream [parent #f] [length 0])
(define/augride (decode stream [parent #f] [length 0])
(define res (_setup stream parent length))
(_parseFields stream res struct-types)
#;(hash-set! (hash-ref res '_props) '_currentOffset (· stream pos))
(send this process res stream)
res)
(define/override (encode stream input-hash [parent #f])
(define/augride (encode stream input-hash [parent #f])
(unless (hash? input-hash)
(raise-argument-error 'Struct:encode "hash" input-hash))
(define sorted-input-keys (sort (hash-keys input-hash) #:key symbol->string string<?))

Loading…
Cancel
Save