preserve order of subset tables & skip missing

main
Matthew Butterick 5 years ago
parent d059948cd9
commit 9c973ddf24

@ -2,6 +2,7 @@
(require xenomorph
"tables.rkt"
racket/dict
racket/match
sugar/unstable/dict
racket/string)
@ -33,7 +34,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
this-res)
(define (directory-pre-encode this-val)
(define tables (for/list ([(tag table) (in-hash (hash-ref this-val 'tables))])
(define tables (for/list ([tag-table-pair (in-list (hash-ref this-val 'tables))])
(match-define (cons tag table) tag-table-pair)
(define table-codec (hash-ref table-codecs tag))
(mhash 'tag (unescape-tag tag)
'checkSum 0

@ -283,28 +283,18 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(dict-set! new-hhea-table 'numberOfMetrics (length (dict-ref (ttf-subset-hmtx ss) 'metrics)))
(define new-tables
(let ()
;; unhinted ttfs don't have `cvt_` `prep` or `fpgm`;
;; so fill in dummy data
(define kvs (dictify 'head new-head-table
'hhea new-hhea-table
'loca (ttf-subset-loca ss)
'maxp new-maxp-table
'cvt_ (if (has-table? (subset-font ss) 'cvt_)
(get-cvt_-table (subset-font ss))
(hash 'controlValues (list 0)))
'prep (if (has-table? (subset-font ss) 'prep)
(get-prep-table (subset-font ss))
(hash 'controlValueProgram (list 0)))
'glyf (ttf-subset-glyf ss)
'hmtx (ttf-subset-hmtx ss)
'fpgm (if (has-table? (subset-font ss) 'fpgm)
(get-fpgm-table (subset-font ss))
(hash 'instructions (list 0)))))
(for ([(k v) (in-dict kvs)]
#:unless v)
(error 'encode (format "missing value for ~a" k)))
(make-hasheq kvs)))
(filter cdr (dictify 'head new-head-table
'hhea new-hhea-table
'loca (ttf-subset-loca ss)
'maxp new-maxp-table
'cvt_ (and (has-table? (subset-font ss) 'cvt_)
(get-cvt_-table (subset-font ss)))
'prep (and (has-table? (subset-font ss) 'prep)
(get-prep-table (subset-font ss)))
'glyf (ttf-subset-glyf ss)
'hmtx (ttf-subset-hmtx ss)
'fpgm (and (has-table? (subset-font ss) 'fpgm)
(get-fpgm-table (subset-font ss))))))
(encode Directory (mhash 'tables new-tables) port)
(void))

Loading…
Cancel
Save