main
Matthew Butterick 6 years ago
parent 2d050f5619
commit 61a9ea4d8c

@ -30,13 +30,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
(define (directory-post-decode this-res)
(define new-tables-val (mhash))
(for ([table (in-list (· this-res tables))])
(hash-set! new-tables-val (escape-tag (· table tag)) table))
(for ([table (in-list (hash-ref this-res 'tables))])
(hash-set! new-tables-val (escape-tag (hash-ref table 'tag)) table))
(dict-set! this-res 'tables new-tables-val)
this-res)
(define (directory-pre-encode this-val)
(define tables (for/list ([(tag table) (in-hash (· this-val tables))])
(define tables (for/list ([(tag table) (in-hash (hash-ref this-val 'tables))])
(define table-codec (hash-ref table-codecs tag))
(mhash 'tag (unescape-tag tag)
'checkSum 0

@ -84,8 +84,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(define glyf-bytes (read-bytes (- next-offset this-offset) port))
;; if it is a compound glyph, include its components
(when (and ttf-glyf-data (negative? (· ttf-glyf-data numberOfContours)))
(for ([ttf-glyph-component (in-list (· ttf-glyf-data components))])
(when (and ttf-glyf-data (negative? (hash-ref ttf-glyf-data 'numberOfContours)))
(for ([ttf-glyph-component (in-list (hash-ref ttf-glyf-data 'components))])
(define gid (subset-add-glyph! ss (ttf-glyph-component-glyph-id ttf-glyph-component)))
;; note: this (ttf-glyph-component-pos component) is correct. It's a field of a Component object, not a port
(bytes-copy! glyf-bytes (ttf-glyph-component-pos ttf-glyph-component) (encode uint16be gid #f))))
@ -97,7 +97,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(hash-update! (ttf-subset-hmtx ss) 'metrics
(λ (ms) (append ms
(list (mhash 'advance (glyph-advance-width glyph)
'bearing (· (get-glyph-metrics glyph) leftBearing))))))
'bearing (hash-ref (get-glyph-metrics glyph) 'leftBearing))))))
(set-ttf-subset-offset! ss (+ (ttf-subset-offset ss) (bytes-length glyf-bytes)))
(sub1 (length (ttf-subset-glyf ss))))

@ -21,7 +21,7 @@
(define (has-table? this tag)
#;((or/c bytes? symbol?) . ->m . boolean?)
(define directory (force (ttf-font-directory this)))
(hash-has-key? (· directory tables) (match tag
(hash-has-key? (hash-ref directory 'tables) (match tag
[(? bytes?) (string->symbol (bytes->string/latin-1 tag))]
[_ tag])))
@ -34,17 +34,17 @@
(define (get-table-stream this tag)
(define directory (force (ttf-font-directory this)))
(define table (hash-ref (· directory tables) tag))
(and table (pos (ttf-font-port this) (· table offset)) (ttf-font-port this)))
(define table (hash-ref (hash-ref directory 'tables) tag))
(and table (pos (ttf-font-port this) (hash-ref table 'offset)) (ttf-font-port this)))
(define (decode-table this table-tag)
(unless (hash-has-key? table-codecs table-tag)
(raise-argument-error 'decode-table "decodable table" table-tag))
(define directory (force (ttf-font-directory this)))
(define table (hash-ref (· directory tables) table-tag))
(define table (hash-ref (hash-ref directory 'tables) table-tag))
;; todo: possible to avoid copying the bytes here?
(pos (ttf-font-port this) (· table offset))
(define table-bytes (open-input-bytes (peek-bytes (· table length) 0 (ttf-font-port this))))
(pos (ttf-font-port this) (hash-ref table 'offset))
(define table-bytes (open-input-bytes (peek-bytes (hash-ref table 'length) 0 (ttf-font-port this))))
(define table-decoder (hash-ref table-codecs table-tag))
(decode table-decoder table-bytes #:parent this))

@ -108,7 +108,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
(pos port (+ (pos port) glyfPos))
(define startPos (pos port))
(define glyph-data (decode GlyfHeader port))
(match (· glyph-data numberOfContours)
(match (hash-ref glyph-data 'numberOfContours)
[(? positive?) (decode-simple glyph-data port)]
[(? negative?) (decode-composite glyph-data port startPos)])
glyph-data)))
@ -122,7 +122,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
;; this is a simple glyph
(dict-set! glyph-data 'points empty)
(define endpts-of-contours (decode (x:array #:type uint16be #:length (· glyph-data numberOfContours)) port))
(define endpts-of-contours (decode (x:array #:type uint16be #:length (hash-ref glyph-data 'numberOfContours)) port))
(dict-set! glyph-data 'instructions (decode (x:array #:type uint8be #:length uint16be) port))
(define num-coords (add1 (last endpts-of-contours)))

Loading…
Cancel
Save