start cff

main
Matthew Butterick 5 years ago
parent 3e09e0cf74
commit 00d99793ac

@ -12,11 +12,24 @@
xenomorph
racket/dict)
(provide subset +subset ttf-subset +ttf-subset subset-add-glyph! encode-to-port create-subset)
(provide subset +subset
ttf-subset +ttf-subset
cff-subset +cff-subset
subset-add-glyph! encode-to-port create-subset)
#|
from
https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
|#
(define (create-subset font)
((if (has-table? font #"CFF_")
+cff-subset
+ttf-subset) font))
#|
approximates
https://github.com/devongovett/fontkit/blob/master/src/subset/Subset.js
https://github.com/mbutterick/fontkit/blob/master/src/subset/Subset.js
|#
; glyphs = list of glyph ids in the subset
@ -33,7 +46,7 @@ https://github.com/devongovett/fontkit/blob/master/src/subset/Subset.js
(subset-encode ss p)
p)
(define (subset-add-glyph! ss glyph-or-gid)
(define (subset-add-glyph! ss glyph-or-gid) ; fka `includeGlyph`
(define new-gid ((if (glyph? glyph-or-gid) glyph-id values) glyph-or-gid))
;; put the new glyph at the end of `glyphs`,
;; and put its index in the mapping
@ -43,6 +56,28 @@ https://github.com/devongovett/fontkit/blob/master/src/subset/Subset.js
(sub1 (length (subset-glyphs ss))))))
#|
approximates
https://github.com/mbutterick/fontkit/blob/master/src/subset/CFFSubset.js
|#
(struct cff-subset subset (cff strings charstrings gsubrs) #:transparent #:mutable)
(define (+cff-subset font [glyphs empty] [mapping (mhash)]
[cff #f]
[strings #f]
[charstrings #f]
[gsubrs #f])
(define ss (cff-subset font glyphs mapping cff strings charstrings gsubrs))
(subset-add-glyph! ss 0)
ss)
(module+ test
(require "font.rkt" "helper.rkt")
(define otf (open-font (path->string fira-otf-path)))
(define cffss (+cff-subset otf))
cffss)
#|
approximates
https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
@ -59,10 +94,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(subset-add-glyph! ss 0)
ss)
(define (create-subset font)
((if (has-table? font #"CFF_")
(error 'cff-fonts-unsupported)
+ttf-subset) font))
(define (ttf-subset-add-glyph ss gid)
;; glyph-decode unpacks the `glyf` table data corresponding to a certin gid.

Loading…
Cancel
Save