new notation

main
Matthew Butterick 6 years ago
parent 0c90a06512
commit d6fff41bb8

@ -53,16 +53,15 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
'rangeShift (- (* numTables 16) searchRange)) 'rangeShift (- (* numTables 16) searchRange))
this-val) this-val)
(define Directory (+xstruct 'tag (+xsymbol #:length 4) (define Directory (+xstruct #:pre-encode directory-pre-encode
#:post-decode directory-post-decode
'tag (+xsymbol #:length 4)
'numTables uint16be 'numTables uint16be
'searchRange uint16be 'searchRange uint16be
'entrySelector uint16be 'entrySelector uint16be
'rangeShift uint16be 'rangeShift uint16be
'tables (+xarray #:type table-entry #:length 'numTables))) 'tables (+xarray #:type table-entry #:length 'numTables)))
(set-pre-encode! Directory directory-pre-encode)
(set-post-decode! Directory directory-post-decode)
(define (directory-decode ip [options (mhash)]) (define (directory-decode ip [options (mhash)])
(decode Directory ip)) (decode Directory ip))

@ -8,6 +8,7 @@
"db.rkt" "db.rkt"
"struct.rkt" "struct.rkt"
"table-stream.rkt" "table-stream.rkt"
racket/class
xenomorph xenomorph
racket/match racket/match
sugar/unstable/dict sugar/unstable/dict
@ -35,8 +36,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
(define (+ttf-font port (define (+ttf-font port
[decoded-tables (mhash)] [decoded-tables (mhash)]
[src (path->string (object-name port))] [src (path->string (object-name port))]
[directory (delay (parameterize ([current-parent (mhash '_startOffset 0)]) [directory (delay (decode Directory port #:parent (mhash '_startOffset 0)))]
(xdecode Directory port)))]
[ft-face (delay (and src (FT_New_Face (force ft-library) src)))] [ft-face (delay (and src (FT_New_Face (force ft-library) src)))]
[hb-font (delay (and src (hb_ft_font_create (force ft-face))))] [hb-font (delay (and src (hb_ft_font_create (force ft-face))))]
[hb-buf (delay (hb_buffer_create))] [hb-buf (delay (hb_buffer_create))]

@ -24,8 +24,6 @@
(hash-has-key? (· directory tables) (match tag (hash-has-key? (· directory tables) (match tag
[(? bytes?) (string->symbol (bytes->string/latin-1 tag))] [(? bytes?) (string->symbol (bytes->string/latin-1 tag))]
[_ tag]))) [_ tag])))
(define (get-table this table-tag) (define (get-table this table-tag)
(unless (has-table? this table-tag) (unless (has-table? this table-tag)
@ -48,6 +46,5 @@
(pos (ttf-font-port this) (· table offset)) (pos (ttf-font-port this) (· table offset))
(define table-bytes (open-input-bytes (peek-bytes (· table length) 0 (ttf-font-port this)))) (define table-bytes (open-input-bytes (peek-bytes (· table length) 0 (ttf-font-port this))))
(define table-decoder (hash-ref table-codecs table-tag)) (define table-decoder (hash-ref table-codecs table-tag))
(parameterize ([current-parent this]) (decode table-decoder table-bytes #:parent this))
(decode table-decoder table-bytes)))

@ -37,24 +37,21 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js
val) val)
(define loca (+xversioned-struct (define loca (+xversioned-struct
#:pre-encode loca-pre-encode
#:post-decode loca-post-decode
;; todo: address ugliness to cross-ref head table from ttffont ;; todo: address ugliness to cross-ref head table from ttffont
(λ (o) (hash-ref (force (ttf-font-get-head-table-proc o)) 'indexToLocFormat)) (λ (o) (hash-ref (force (ttf-font-get-head-table-proc o)) 'indexToLocFormat))
(dictify (dictify
0 (dictify 'offsets (+xarray #:type uint16be)) 0 (dictify 'offsets (+xarray #:type uint16be))
1 (dictify 'offsets (+xarray #:type uint32be))))) 1 (dictify 'offsets (+xarray #:type uint32be)))))
(set-pre-encode! loca loca-pre-encode)
(set-post-decode! loca loca-post-decode)
(define loca-v0 (+xversioned-struct (define loca-v0 (+xversioned-struct
;; todo: address ugliness to cross-ref head table from ttffont #:pre-encode loca-pre-encode
0 #:post-decode loca-post-decode
(dictify 0
0 (dictify 'offsets (+xarray #:type uint16be)) (dictify
1 (dictify 'offsets (+xarray #:type uint32be))))) 0 (dictify 'offsets (+xarray #:type uint16be))
1 (dictify 'offsets (+xarray #:type uint32be)))))
(set-pre-encode! loca-v0 loca-pre-encode)
(set-post-decode! loca-v0 loca-post-decode)
(module+ test (module+ test
(require rackunit racket/serialize) (require rackunit racket/serialize)

Loading…
Cancel
Save