From cf7e0a633b543f3833148d83e24a23b3477e71b5 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 21 Jun 2017 23:53:01 -0700 Subject: [PATCH] resume in ValueRecord:buildStruct --- pitfall/fontkit/GPOS.rkt | 6 ++--- pitfall/fontkit/opentype.rkt | 27 +++++++++++++++++-- .../node_modules/restructure/src/Pointer.js | 1 + .../node_modules/restructure/src/Struct.js | 2 ++ pitfall/restructure/pointer.rkt | 7 +++-- pitfall/restructure/struct.rkt | 1 + 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/pitfall/fontkit/GPOS.rkt b/pitfall/fontkit/GPOS.rkt index bd248757..52953e5b 100644 --- a/pitfall/fontkit/GPOS.rkt +++ b/pitfall/fontkit/GPOS.rkt @@ -24,7 +24,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/GPOS.js (define/public (buildStruct parent) (define struct parent) - (while (and (not (hash-ref struct (· this key))) (hash-ref struct parent)) + (while (and (not (· struct (· this key))) (· struct parent)) (hash-set! struct (hash-ref struct parent))) (cond @@ -100,7 +100,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/GPOS.js (define-subclass VersionedStruct (GPOSLookup-VersionedStruct)) (define GPOSLookup (+GPOSLookup-VersionedStruct - (λ (parent) (or (· parent parent res ) + (λ (parent) (or (· parent parent res lookupType) (raise-argument-error 'GPOSLookup "parent object" #f))) (dictify ;; Single Adjustment @@ -108,7 +108,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/GPOS.js (dictify ;; Single positioning value 1 (dictify - 'coverage uint16be ; pointer + 'coverage (+Pointer uint16be Coverage) 'valueFormat ValueFormat 'value (+ValueRecord)) 2 (dictify diff --git a/pitfall/fontkit/opentype.rkt b/pitfall/fontkit/opentype.rkt index ca498f9f..42780b9b 100644 --- a/pitfall/fontkit/opentype.rkt +++ b/pitfall/fontkit/opentype.rkt @@ -52,11 +52,34 @@ 'lookupType uint16be 'flags LookupFlags 'subTableCount uint16be - 'subTables (+Array (+Pointer uint16be SubTable) 'subTableCount) - ;'subTables (+Array uint16be 'subTableCount) + 'subTables (+Array (+Pointer uint16be SubTable 'parent) 'subTableCount) 'markFilteringSet uint16be))) (+Array (+Pointer uint16be Lookup) uint16be)) + +;;################# +;; Coverage Table # +;;################# + +(define RangeRecord + (+Struct + (dictify + 'start uint16be + 'end uint16be + 'startCoverageIndex uint16be))) + +(define Coverage + (+VersionedStruct uint16be + (dictify + 1 (dictify + 'glyphCount uint16be + 'glyphs (+Array uint16be 'glyphCount)) + + 2 (dictify + 'rangeCount uint16be + 'rangeRecords (+Array RangeRecord 'rangeCount))))) + + ;;############################################# ;; Contextual Substitution/Positioning Tables # ;;############################################# diff --git a/pitfall/pdfkit/node_modules/restructure/src/Pointer.js b/pitfall/pdfkit/node_modules/restructure/src/Pointer.js index 078dcf61..e75ac4f7 100644 --- a/pitfall/pdfkit/node_modules/restructure/src/Pointer.js +++ b/pitfall/pdfkit/node_modules/restructure/src/Pointer.js @@ -56,6 +56,7 @@ relative += this.relativeToGetter(ctx); } ptr = offset + relative; + console.log("ptr="+ptr+" type="+this.offsetType.size()); if (this.type != null) { val = null; decodeValue = (function(_this) { diff --git a/pitfall/pdfkit/node_modules/restructure/src/Struct.js b/pitfall/pdfkit/node_modules/restructure/src/Struct.js index 83aeffd3..8e1bf081 100644 --- a/pitfall/pdfkit/node_modules/restructure/src/Struct.js +++ b/pitfall/pdfkit/node_modules/restructure/src/Struct.js @@ -47,6 +47,8 @@ var key, type, val; for (key in fields) { type = fields[key]; + + console.log("key=" + key + " type="+type); if (typeof type === 'function') { val = type.call(res, res); } else { diff --git a/pitfall/restructure/pointer.rkt b/pitfall/restructure/pointer.rkt index c7b79254..269f3d51 100644 --- a/pitfall/restructure/pointer.rkt +++ b/pitfall/restructure/pointer.rkt @@ -8,14 +8,17 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee (define-subclass RestructureBase (Pointer offsetType type [scope 'local]) (and (symbol? scope) (caseq scope - [(local parent) 'yay] + [(local parent grandparent immediate) 'yay] [else (raise-argument-error 'Pointer "local or parent" scope)])) (define/augride (decode stream ctx) (define offset (send offsetType decode stream ctx)) (define ptr (+ offset (caseq scope + [(immediate) (· this starting-offset)] [(local) (· this parent starting-offset)] - [(parent) (· this parent parent starting-offset)]))) + [(parent) (· this parent parent starting-offset)] + [(grandparent) (· this parent parent parent starting-offset)]))) + (report* ptr (send offsetType size)) (cond [type (define orig-pos (send stream pos)) (send stream pos ptr) diff --git a/pitfall/restructure/struct.rkt b/pitfall/restructure/struct.rkt index 6017b226..320906ef 100644 --- a/pitfall/restructure/struct.rkt +++ b/pitfall/restructure/struct.rkt @@ -42,6 +42,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee (unless (assocs? fields) (raise-argument-error '_parseFields "assocs" fields)) (for ([(key type) (in-dict fields)]) + (report* key type) (define val (if (procedure? type) (type res)