working on subset
parent
9fdeb7e7b8
commit
fa4eef1325
@ -1,15 +1,41 @@
|
||||
#lang pitfall/racket
|
||||
(provide Subset CFFSubset TTFSubset)
|
||||
|
||||
(define-subclass object% (Subset)
|
||||
(super-new))
|
||||
(define index? (and/c (not/c negative?) integer?))
|
||||
|
||||
;; approximates
|
||||
;; https://github.com/devongovett/fontkit/blob/master/src/subset/Subset.js
|
||||
|
||||
(define-subclass Subset (CFFSubset font)
|
||||
(define-subclass object% (Subset font)
|
||||
(super-new)
|
||||
(field [glyphs empty] ; list of glyphs in the subset
|
||||
[mapping (mhash)] ; mapping of glyph ids to indexes in `glyphs`
|
||||
)
|
||||
|
||||
(send this includeGlyph 0) ; always include the missing glyph in subset
|
||||
|
||||
(as-methods
|
||||
includeGlyph))
|
||||
|
||||
(define/contract (includeGlyph this glyph)
|
||||
((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-subclass Subset (CFFSubset)
|
||||
(super-new)
|
||||
(error 'cff-subset-unimplemented))
|
||||
|
||||
|
||||
(define-subclass Subset (TTFSubset font)
|
||||
;; approximates
|
||||
;; https://github.com/devongovett/fontkit/blob/master/src/subset/TTFSubset.js
|
||||
|
||||
(define-subclass Subset (TTFSubset)
|
||||
(super-new)
|
||||
(error 'ttf-subset-unimplemented))
|
||||
)
|
Binary file not shown.
Loading…
Reference in New Issue