dump free

main
Matthew Butterick 6 years ago
parent 9dd05cf37c
commit 0c90a06512

@ -35,7 +35,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
(define (+ttf-font port
[decoded-tables (mhash)]
[src (path->string (object-name port))]
[directory (delay (decode Directory port #:parent (mhash '_startOffset 0)))]
[directory (delay (parameterize ([current-parent (mhash '_startOffset 0)])
(xdecode Directory port)))]
[ft-face (delay (and src (FT_New_Face (force ft-library) src)))]
[hb-font (delay (and src (hb_ft_font_create (force ft-face))))]
[hb-buf (delay (hb_buffer_create))]
@ -48,7 +49,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
(define font
(ttf-font port decoded-tables src directory ft-face hb-font hb-buf crc get-head-table-proc))
;; needed for `loca` table decoding cross-reference
(set-ttf-font-get-head-table-proc! font (delay (dump (get-head-table font))))
(set-ttf-font-get-head-table-proc! font (delay (get-head-table font)))
font)
(define (font-postscript-name font) (FT_Get_Postscript_Name (ft-face font)))
@ -146,7 +147,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
(λ ()
#;(encode hb-output (apply harfbuzz-layout font args) #f)
(match (get-layout-from-db key)
[(? bytes? res) (dump (decode hb-output res))]
[(? bytes? res) (decode hb-output res)]
[_ (define new-layout (apply harfbuzz-layout font args))
(add-record! (cons key (encode hb-output new-layout #f)))
(make-hasheq new-layout)])))) ;; `dump` converts to hash

@ -77,7 +77,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
;; get the offset to the glyph from the loca table
(match-define (list this-offset next-offset)
(take (drop (hash-ref (dump (get-table (subset-font ss) 'loca)) 'offsets) gid) 2))
(take (drop (hash-ref (get-table (subset-font ss) 'loca) 'offsets) gid) 2))
(define port (get-table-stream (subset-font ss) 'glyf))
(pos port (+ (pos port) this-offset))
@ -122,17 +122,17 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(define gid (list-ref (subset-glyphs ss) idx))
(ttf-subset-add-glyph ss gid))
(define new-maxp-table (clone-deep (dump-mutable (get-maxp-table (subset-font ss)))))
(define new-maxp-table (clone-deep (get-maxp-table (subset-font ss))))
(dict-set! new-maxp-table 'numGlyphs (length (ttf-subset-glyf ss)))
;; populate the new loca table
(dict-update! (ttf-subset-loca ss) 'offsets (λ (vals) (append vals (list (ttf-subset-offset ss)))))
(loca-pre-encode (ttf-subset-loca ss))
(define new-head-table (clone-deep (dump-mutable (get-head-table (subset-font ss)))))
(define new-head-table (clone-deep (get-head-table (subset-font ss))))
(dict-set! new-head-table 'indexToLocFormat (dict-ref (ttf-subset-loca ss) 'version))
(define new-hhea-table (clone-deep (dump-mutable (get-hhea-table (subset-font ss)))))
(define new-hhea-table (clone-deep (get-hhea-table (subset-font ss))))
(dict-set! new-hhea-table 'numberOfMetrics (length (dict-ref (ttf-subset-hmtx ss) 'metrics)))
(define new-tables

@ -1,6 +1,6 @@
#lang debug racket
(require sugar/unstable/js
(only-in xenomorph pos decode)
xenomorph
"tables.rkt"
"struct.rkt"
(for-syntax "tables.rkt"))
@ -48,5 +48,6 @@
(pos (ttf-font-port this) (· table offset))
(define table-bytes (open-input-bytes (peek-bytes (· table length) 0 (ttf-font-port this))))
(define table-decoder (hash-ref table-codecs table-tag))
(decode table-decoder table-bytes #:parent this))
(parameterize ([current-parent this])
(decode table-decoder table-bytes)))

@ -34,5 +34,5 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/hmtx.js
(define hmtx-data (decode hmtx-test hmtx-bytes))
(check-equal? (size hmtx-test) (* 229 (size hmtx-entry)))
(define H-gid 41) (define OE-gid 142)
(check-equal? (dump (stream-ref (· hmtx-data metrics) H-gid)) '((bearing . 33) (advance . 738)))
(check-equal? (dump (stream-ref (· hmtx-data metrics) OE-gid)) '((bearing . 43) (advance . 993))))
(check-equal? (stream-ref (· hmtx-data metrics) H-gid) (make-hasheq '((bearing . 33) (advance . 738))))
(check-equal? (stream-ref (· hmtx-data metrics) OE-gid) (make-hasheq '((bearing . 43) (advance . 993)))))

@ -98,7 +98,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
;; or components for composite glyphs
(require "table-stream.rkt")
(define (glyph-decode ttfg)
(define offsets (hash-ref (dump (get-table (glyph-font ttfg) 'loca)) 'offsets))
(define offsets (hash-ref (get-table (glyph-font ttfg) 'loca) 'offsets))
(match-define (list glyfPos nextPos) (take (drop offsets (glyph-id ttfg)) 2))
;; Nothing to do if there is no data for this glyph

Loading…
Cancel
Save