diff --git a/pitfall/fontkit/clone.rkt b/pitfall/fontkit/clone.rkt index 5a1fc990..ffcad17f 100644 --- a/pitfall/fontkit/clone.rkt +++ b/pitfall/fontkit/clone.rkt @@ -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))))) \ No newline at end of file + (deserialize (serialize val))) + diff --git a/pitfall/fontkit/font.rkt b/pitfall/fontkit/font.rkt index da1c91b7..53a3b16e 100644 --- a/pitfall/fontkit/font.rkt +++ b/pitfall/fontkit/font.rkt @@ -80,7 +80,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js ;; The size of the font’s 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 font’s [ascender](https://en.wikipedia.org/wiki/Ascender_(typography)) diff --git a/pitfall/fontkit/loca.rkt b/pitfall/fontkit/loca.rkt new file mode 100644 index 00000000..9894b70d --- /dev/null +++ b/pitfall/fontkit/loca.rkt @@ -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 + ) + diff --git a/pitfall/fontkit/subset.rkt b/pitfall/fontkit/subset.rkt index 6a9095ef..f809e145 100644 --- a/pitfall/fontkit/subset.rkt +++ b/pitfall/fontkit/subset.rkt @@ -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))) diff --git a/pitfall/fontkit/tables.rkt b/pitfall/fontkit/tables.rkt index c6a1a3d3..86cff693 100644 --- a/pitfall/fontkit/tables.rkt +++ b/pitfall/fontkit/tables.rkt @@ -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) \ No newline at end of file +(define-table-decoders table-decoders maxp hhea head loca) \ No newline at end of file diff --git a/pitfall/restructure/main.rkt b/pitfall/restructure/main.rkt index 50cb9f0f..02c524c7 100644 --- a/pitfall/restructure/main.rkt +++ b/pitfall/restructure/main.rkt @@ -2,6 +2,7 @@ (r+p "number.rkt" "struct.rkt" + "versioned-struct.rkt" "string.rkt" "array.rkt" "bitfield.rkt" diff --git a/pitfall/restructure/struct.rkt b/pitfall/restructure/struct.rkt index 08e44123..e433dbe4 100644 --- a/pitfall/restructure/struct.rkt +++ b/pitfall/restructure/struct.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)) diff --git a/pitfall/restructure/versioned-struct.rkt b/pitfall/restructure/versioned-struct.rkt new file mode 100644 index 00000000..c46e0cc7 --- /dev/null +++ b/pitfall/restructure/versioned-struct.rkt @@ -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)) \ No newline at end of file