new notation

main
Matthew Butterick 5 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))
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
'searchRange uint16be
'entrySelector uint16be
'rangeShift uint16be
'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)])
(decode Directory ip))

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

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

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

Loading…
Cancel
Save