resume in loca / versioned struct

main
Matthew Butterick 8 years ago
parent b2a563f523
commit 4b063efda4

@ -1,6 +1,7 @@
#lang fontkit/racket
(require racket/serialize)
(provide cloneDeep)
(define (cloneDeep val)
(parameterize ([print-graph #t])
(read (open-input-string (~s val)))))
(deserialize (serialize val)))

@ -80,7 +80,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
;; The size of the fonts internal coordinate grid
(define/contract (unitsPerEm this)
(->m number?)
(FT_FaceRec-units_per_EM (· this ft-face)))
(hash-ref (send this _getTable 'head) 'unitsPerEm))
;; The fonts [ascender](https://en.wikipedia.org/wiki/Ascender_(typography))

@ -0,0 +1,21 @@
#lang fontkit/racket
(require restructure)
(provide (all-defined-out))
#|
approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js
|#
(define-subclass RVersionedStruct (Rloca))
(define loca (make-object Rloca
(λ (this) (hash-ref (send this _getTable 'head) 'indexToLocFormat))
(dictify
)))
(test-module
)

@ -70,10 +70,10 @@ https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
(send this _addGlyph gid))
(define maxp (cloneDeep (send (· this font) _getTable 'maxp)))
;; (hash-set! maxp 'numGlyphs (length (· this glyf))) ; todo
(hash-set! maxp 'numGlyphs (length (· this glyf))) ; todo
;; todo
;; this.loca.offsets.push(this.offset);
(hash-update! (send (· this font) _getTable 'loca) 'offsets (λ (val) (push-end! val (· this offset))))
;; Tables.loca.preEncode.call(this.loca);
(define head (cloneDeep (send (· this font) _getTable 'head)))

@ -8,4 +8,4 @@
(r+p . TABLE-ID-STRINGS)
(define ID (make-hasheq (map cons (list 'TABLE-ID ...) (list TABLE-ID ...)))))))
(define-table-decoders table-decoders maxp hhea head)
(define-table-decoders table-decoders maxp hhea head loca)

@ -2,6 +2,7 @@
(r+p "number.rkt"
"struct.rkt"
"versioned-struct.rkt"
"string.rkt"
"array.rkt"
"bitfield.rkt"

@ -13,7 +13,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
(for ([(k v) (in-dict assocs)])
(hash-set! fields k v))
(define/overment (decode stream [parent #f] [length 0])
(define/override (decode stream [parent #f] [length 0])
(define res (_setup stream parent length))
(_parseFields stream res fields)
#;(hash-set! (hash-ref res '_props) '_currentOffset (· stream pos))

@ -0,0 +1,21 @@
#lang restructure/racket
(require racket/dict "struct.rkt")
(provide (all-defined-out))
#|
approximates
https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
|#
(define-subclass RStruct (RVersionedStruct type [versions (dictify)])
(define/override (decode stream [parent #f] [length 0])
(define res (send this _setup stream parent length))
(define version (cond
[(procedure? type) (type parent)]
[(is-a? type RBase) (send type decode stream)]
[else (raise-argument-error 'decode "way of finding version" type)]))
(report version 'yay)
#;(_parseFields stream res fields)
#;(send this process res stream)
res))
Loading…
Cancel
Save