From 28adeb6e808d4ef38d4b5edf1942131a924cb432 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 30 Nov 2018 16:38:09 -0800 Subject: [PATCH] CFF cuts --- fontland/fontland/font.rkt | 13 ++++++++----- fontland/fontland/subset.rkt | 32 +++++++++++++++++--------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/fontland/fontland/font.rkt b/fontland/fontland/font.rkt index 9dd67b57..24effa6f 100644 --- a/fontland/fontland/font.rkt +++ b/fontland/fontland/font.rkt @@ -32,8 +32,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js (syntax-case stx () [(_) (with-syntax ([(TABLE-TAG ...) (hash-keys table-codecs)]) - #'(begin - (define/public (TABLE-TAG) (_getTable 'TABLE-TAG)) ...))])) + #'(begin + (define/public (TABLE-TAG) (_getTable 'TABLE-TAG)) ...))])) (test-module @@ -215,9 +215,12 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js ;; Returns a Subset for this font. (define/contract (createSubset this) (->m (is-a?/c Subset)) - (make-object (if (· this has-cff-table?) - CFFSubset - TTFSubset) this)) + (make-object + ;; no CFF support + #;(if (· this has-cff-table?) + CFFSubset + TTFSubset) + TTFSubset this)) diff --git a/fontland/fontland/subset.rkt b/fontland/fontland/subset.rkt index e42d87a2..b749cde8 100644 --- a/fontland/fontland/subset.rkt +++ b/fontland/fontland/subset.rkt @@ -11,7 +11,7 @@ "directory.rkt" "helper.rkt" xenomorph) -(provide Subset CFFSubset TTFSubset) +(provide Subset TTFSubset) #| approximates @@ -20,9 +20,8 @@ https://github.com/devongovett/fontkit/blob/master/src/subset/Subset.js (define-subclass object% (Subset font) (field [glyphs empty] ; list of glyph ids in the subset - [mapping (mhash)] ; mapping of glyph ids to indexes in `glyphs` - ) - + [mapping (mhash)]) ; mapping of glyph ids to indexes in `glyphs` + (send this includeGlyph 0) ; always include the missing glyph in subset (define/public (encode-to-port) @@ -33,17 +32,17 @@ https://github.com/devongovett/fontkit/blob/master/src/subset/Subset.js (as-methods includeGlyph)) -(define/contract (includeGlyph this glyph) +(define/contract (includeGlyph this glyph-or-gid) ((or/c object? index?) . ->m . index?) - (let ([glyph (if (object? glyph) (· glyph id) glyph)]) - (hash-ref! (· this mapping) glyph - (λ () - ;; put the new glyph at the end of `glyphs`, - ;; and put its index in the mapping - (push-end-field! glyphs this glyph) - (sub1 (length (· this glyphs))))))) - - + (define glyph (if (object? glyph-or-gid) + (· glyph-or-gid id) + glyph-or-gid)) + (hash-ref! (· this mapping) glyph + (λ () + ;; put the new glyph at the end of `glyphs`, + ;; and put its index in the mapping + (push-end-field! glyphs this glyph) + (sub1 (length (· this glyphs)))))) #| approximates @@ -51,6 +50,9 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/CFFSubset.js |# +#| +;; no CFF font support for now + (define-subclass Subset (CFFSubset) #R (· this font) (field [cff (send (· this font) _getTable 'CFF_)]) @@ -65,7 +67,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/CFFSubset.js #;createCIDFontdict #;addString #;encode)) - +|# (define/contract (subsetCharstrings this) (->m void?)