working on pointers
parent
ff8e2f867b
commit
a028c6fd95
@ -0,0 +1,222 @@
|
||||
fontkit = require '../pdfkit/node_modules/fontkit'
|
||||
|
||||
fira_path = "../pitfall/test/assets/fira.ttf"
|
||||
f = fontkit.openSync(fira_path)
|
||||
console.log(f.GPOS)
|
||||
|
||||
###
|
||||
{ version: 65536,
|
||||
scriptList:
|
||||
[ { tag: 'DFLT', script: [Object] },
|
||||
{ tag: 'cyrl', script: [Object] },
|
||||
{ tag: 'grek', script: [Object] },
|
||||
{ tag: 'latn', script: [Object] } ],
|
||||
featureList:
|
||||
[ { tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'cpsp', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'kern', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mark', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] },
|
||||
{ tag: 'mkmk', feature: [Object] } ],
|
||||
lookupList:
|
||||
[ { lookupType: 1,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 1,
|
||||
subTables: [ [Object] ],
|
||||
markFilteringSet: 2 },
|
||||
{ lookupType: 2,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 6,
|
||||
subTables: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
|
||||
markFilteringSet: 2 },
|
||||
{ lookupType: 2,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 7,
|
||||
subTables:
|
||||
[ [Object],
|
||||
[Object],
|
||||
[Object],
|
||||
[Object],
|
||||
[Object],
|
||||
[Object],
|
||||
[Object] ],
|
||||
markFilteringSet: 2 },
|
||||
{ lookupType: 2,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 6,
|
||||
subTables: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
|
||||
markFilteringSet: 2 },
|
||||
{ lookupType: 2,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 2,
|
||||
subTables: [ [Object], [Object] ],
|
||||
markFilteringSet: 4 },
|
||||
{ lookupType: 4,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 1,
|
||||
subTables: [ [Object] ],
|
||||
markFilteringSet: 4 },
|
||||
{ lookupType: 4,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 1,
|
||||
subTables: [ [Object] ],
|
||||
markFilteringSet: 4 },
|
||||
{ lookupType: 4,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 1,
|
||||
subTables: [ [Object] ],
|
||||
markFilteringSet: 6 },
|
||||
{ lookupType: 6,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 1,
|
||||
subTables: [ [Object] ],
|
||||
markFilteringSet: 6 },
|
||||
{ lookupType: 6,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 1,
|
||||
subTables: [ [Object] ],
|
||||
markFilteringSet: 6 },
|
||||
{ lookupType: 6,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 1,
|
||||
subTables: [ [Object] ],
|
||||
markFilteringSet: 6 },
|
||||
{ lookupType: 6,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 1,
|
||||
subTables: [ [Object] ],
|
||||
markFilteringSet: 6 },
|
||||
{ lookupType: 6,
|
||||
flags:
|
||||
{ rightToLeft: false,
|
||||
ignoreBaseGlyphs: false,
|
||||
ignoreLigatures: false,
|
||||
ignoreMarks: false,
|
||||
useMarkFilteringSet: false,
|
||||
markAttachmentType: false },
|
||||
subTableCount: 1,
|
||||
subTables: [ [Object] ],
|
||||
markFilteringSet: 1 } ] }
|
||||
###
|
@ -1,7 +1,22 @@
|
||||
#lang fontkit/racket
|
||||
(require "font.rkt" "directory.rkt" "gpos.rkt")
|
||||
(require fontkit rackunit restructure)
|
||||
|
||||
(define fira-path "../pitfall/test/assets/fira.ttf")
|
||||
(define f (openSync fira-path))
|
||||
(define ds (send f _getTableStream 'GPOS))
|
||||
|
||||
(send GPOS decode ds)
|
||||
(file-position (· ds _port))
|
||||
(peek-bytes 4 0 (· ds _port)) ; version
|
||||
(peek-bytes 2 4 (· ds _port)) ; scriptList pointer
|
||||
(peek-bytes 2 10 (· ds _port)) ; number of Scriptrecords
|
||||
|
||||
(send uint16be decode #"\0\n")
|
||||
|
||||
(define h (send GPOS decode ds))
|
||||
|
||||
|
||||
|
||||
;(check-equal? (· h version) #x00010000)
|
||||
|
||||
;h
|
||||
;(check-equal? (length (· h scriptList)) 4)
|
@ -1,21 +1,34 @@
|
||||
#lang restructure/racket
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define pointer-ks (make-hash))
|
||||
(define results (make-hash))
|
||||
#|
|
||||
approximates
|
||||
https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
|
||||
|#
|
||||
|
||||
(define vals '(a b (h) d e f g h i j))
|
||||
(define-subclass RestructureBase (Pointer offsetType type [options (mhash)])
|
||||
|
||||
(for ([(val i) (in-indexed vals)]
|
||||
#:unless (hash-has-key? results val))
|
||||
(hash-set! results i (let/cc pointer-k
|
||||
(cond
|
||||
[(hash-ref pointer-ks val #f) => (λ (pk)
|
||||
(hash-remove! pointer-ks val)
|
||||
(pk (format "~a@~a" val i)))]
|
||||
[(pair? val) (hash-set! pointer-ks (car val) pointer-k) 'tbd]
|
||||
[else val]))))
|
||||
(test-module
|
||||
(check-equal?
|
||||
(for/list ([i (in-range (length (hash-keys results)))])
|
||||
(hash-ref results i))
|
||||
'(a b "h@7" d e f g h i j)))
|
||||
(define/override (decode stream ctx)
|
||||
(report (file-position (· stream _port)))
|
||||
(define offset (send offsetType decode stream ctx))
|
||||
(define ptr offset)
|
||||
(report* offset ptr)
|
||||
(cond
|
||||
[type (define orig-pos (send stream pos))
|
||||
(send stream pos ptr)
|
||||
(define val (send type decode stream ctx))
|
||||
(send stream pos orig-pos)
|
||||
(report* options)
|
||||
val]
|
||||
[else ptr]))
|
||||
|
||||
|
||||
(define/override (encode stream val)
|
||||
(error 'Pointer-encode-not-done))
|
||||
|
||||
(define/override (size val)
|
||||
(error 'Pointer-size-not-done))
|
||||
|
||||
|
||||
|
||||
)
|
Loading…
Reference in New Issue