From 9c973ddf241a6a85623d00f430846f58db886fd5 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 13 May 2019 20:56:41 -0500 Subject: [PATCH] preserve order of subset tables & skip missing --- fontland/fontland/directory.rkt | 4 +++- fontland/fontland/subset.rkt | 34 ++++++++++++--------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/fontland/fontland/directory.rkt b/fontland/fontland/directory.rkt index 7bd934d6..b6cdd686 100644 --- a/fontland/fontland/directory.rkt +++ b/fontland/fontland/directory.rkt @@ -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 diff --git a/fontland/fontland/subset.rkt b/fontland/fontland/subset.rkt index 5abb3332..f9481884 100644 --- a/fontland/fontland/subset.rkt +++ b/fontland/fontland/subset.rkt @@ -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))