preserve order of subset tables & skip missing

main
Matthew Butterick 5 years ago
parent d059948cd9
commit 9c973ddf24

@ -2,6 +2,7 @@
(require xenomorph (require xenomorph
"tables.rkt" "tables.rkt"
racket/dict racket/dict
racket/match
sugar/unstable/dict sugar/unstable/dict
racket/string) racket/string)
@ -33,7 +34,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
this-res) this-res)
(define (directory-pre-encode this-val) (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)) (define table-codec (hash-ref table-codecs tag))
(mhash 'tag (unescape-tag tag) (mhash 'tag (unescape-tag tag)
'checkSum 0 '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))) (dict-set! new-hhea-table 'numberOfMetrics (length (dict-ref (ttf-subset-hmtx ss) 'metrics)))
(define new-tables (define new-tables
(let () (filter cdr (dictify 'head new-head-table
;; unhinted ttfs don't have `cvt_` `prep` or `fpgm`; 'hhea new-hhea-table
;; so fill in dummy data 'loca (ttf-subset-loca ss)
(define kvs (dictify 'head new-head-table 'maxp new-maxp-table
'hhea new-hhea-table 'cvt_ (and (has-table? (subset-font ss) 'cvt_)
'loca (ttf-subset-loca ss) (get-cvt_-table (subset-font ss)))
'maxp new-maxp-table 'prep (and (has-table? (subset-font ss) 'prep)
'cvt_ (if (has-table? (subset-font ss) 'cvt_) (get-prep-table (subset-font ss)))
(get-cvt_-table (subset-font ss)) 'glyf (ttf-subset-glyf ss)
(hash 'controlValues (list 0))) 'hmtx (ttf-subset-hmtx ss)
'prep (if (has-table? (subset-font ss) 'prep) 'fpgm (and (has-table? (subset-font ss) 'fpgm)
(get-prep-table (subset-font ss)) (get-fpgm-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)))
(encode Directory (mhash 'tables new-tables) port) (encode Directory (mhash 'tables new-tables) port)
(void)) (void))

Loading…
Cancel
Save