next: start table decoding with maxp

main
Matthew Butterick 8 years ago
parent 0765d3e9cd
commit 638a578faa

@ -17,7 +17,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
(define/override (process res stream)
(define new-tables-val (mhash))
(for ([table (in-list (· res tables))])
(hash-set! new-tables-val (· table tag) table))
(hash-set! new-tables-val (string->symbol (· table tag)) table))
(hash-set! res 'tables new-tables-val)))
(define Directory (make-object RDirectory
@ -40,21 +40,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
(deserialize '((3)
0
()
14
((u . "head")
(u . "prep")
(u . "fpgm")
(u . "hmtx")
(u . "hhea")
(u . "maxp")
(u . "VDMX")
(u . "loca")
(u . "name")
(u . "cvt ")
(u . "OS/2")
(u . "post")
(u . "glyf")
(u . "cmap"))
0
()
()
(h
!
@ -68,17 +55,17 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
h
!
(equal)
((? . 0) h ! () (tag ? . 0) (offset . 236) (checkSum . 4281190895) (length . 54))
((? . 1) h ! () (tag ? . 1) (offset . 4512) (checkSum . 490862356) (length . 78))
((? . 2) h ! () (tag ? . 2) (offset . 4140) (checkSum . 106535991) (length . 371))
((? . 3) h ! () (tag ? . 3) (offset . 456) (checkSum . 3982043058) (length . 916))
((? . 4) h ! () (tag ? . 4) (offset . 292) (checkSum . 132056097) (length . 36))
((? . 5) h ! () (tag ? . 5) (offset . 328) (checkSum . 50135594) (length . 32))
((? . 6) h ! () (tag ? . 6) (offset . 1372) (checkSum . 1887795202) (length . 1504))
((? . 7) h ! () (tag ? . 7) (offset . 38692) (checkSum . 2795817194) (length . 460))
((? . 8) h ! () (tag ? . 8) (offset . 39152) (checkSum . 2629707307) (length . 2367))
((? . 9) h ! () (tag ? . 9) (offset . 4592) (checkSum . 10290865) (length . 26))
((? . 10) h ! () (tag ? . 10) (offset . 360) (checkSum . 2351070438) (length . 96))
((? . 11) h ! () (tag ? . 11) (offset . 41520) (checkSum . 1670855689) (length . 514))
((? . 12) h ! () (tag ? . 12) (offset . 4620) (checkSum . 1143629849) (length . 34072))
((? . 13) h ! () (tag ? . 13) (offset . 2876) (checkSum . 1723761408) (length . 1262))))))))
(loca h ! () (tag u . "loca") (offset . 38692) (checkSum . 2795817194) (length . 460))
(glyf h ! () (tag u . "glyf") (offset . 4620) (checkSum . 1143629849) (length . 34072))
(OS/2 h ! () (tag u . "OS/2") (offset . 360) (checkSum . 2351070438) (length . 96))
(hhea h ! () (tag u . "hhea") (offset . 292) (checkSum . 132056097) (length . 36))
(post h ! () (tag u . "post") (offset . 41520) (checkSum . 1670855689) (length . 514))
(|cvt | h ! () (tag u . "cvt ") (offset . 4592) (checkSum . 10290865) (length . 26))
(VDMX h ! () (tag u . "VDMX") (offset . 1372) (checkSum . 1887795202) (length . 1504))
(prep h ! () (tag u . "prep") (offset . 4512) (checkSum . 490862356) (length . 78))
(maxp h ! () (tag u . "maxp") (offset . 328) (checkSum . 50135594) (length . 32))
(hmtx h ! () (tag u . "hmtx") (offset . 456) (checkSum . 3982043058) (length . 916))
(cmap h ! () (tag u . "cmap") (offset . 2876) (checkSum . 1723761408) (length . 1262))
(name h ! () (tag u . "name") (offset . 39152) (checkSum . 2629707307) (length . 2367))
(head h ! () (tag u . "head") (offset . 236) (checkSum . 4281190895) (length . 54))
(fpgm h ! () (tag u . "fpgm") (offset . 4140) (checkSum . 106535991) (length . 371))))))))

@ -6,7 +6,7 @@
#|
approximates
https://github.com/devongovett/fontkit/blob/master/src/TTFFont.js
https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
|#
;; This is the base class for all SFNT-based font formats in fontkit.
@ -27,19 +27,20 @@ https://github.com/devongovett/fontkit/blob/master/src/TTFFont.js
(field [directory #f])
(send this _decodeDirectory)
#;(define/public (_getTable tag)
(unless (member (· directory tag) _tables)
(raise-argument-error '_getTable "table that exists" (· table tag)))
(hash-set! _tables (· table tag) (_decodeTable table)))
(define/public (_getTable table-tag)
(unless (hash-has-key? (hash-ref directory 'tables) table-tag)
(raise-argument-error '_getTable "table that exists" table-tag))
(hash-ref! _tables table-tag (_decodeTable table-tag))) ; load table from cache, decode if necessary
(define/public (_decodeTable table)
(report table '_decodeTable:starting)
(define-values (l c p) (port-next-location stream))
(displayln 'whee)
(set-port-next-location! stream l c p))
(define/public (_decodeDirectory)
(set! directory (directory-decode stream (mhash '_startOffset 0)))
directory)
(field [ft-library (FT_Init_FreeType)])
(field [ft-face (FT_New_Face ft-library charter-path 0)])
@ -275,8 +276,8 @@ https://github.com/devongovett/fontkit/blob/master/src/TTFFont.js
(check-false (· f has-gpos-table?))
(check-true (send f has-table? #"cmap"))
(check-equal? (· f lineGap) 0)
f
#;(send f _getTable 'maxp)
(check-exn exn:fail:contract? (λ () (send f _getTable 'nonexistent-table-tag)))
(send f _getTable 'maxp)
#;(· f createSubset)

@ -30,8 +30,10 @@
(error 'cff-subset-unimplemented))
;; approximates
;; https://github.com/devongovett/fontkit/blob/master/src/subset/TTFSubset.js
#|
approximates
https://github.com/mbutterick/fontkit/blob/master/src/subset/TTFSubset.js
|#
(define-subclass Subset (TTFSubset)
(field [glyphEncoder (make-object TTFGlyphEncoder)])
@ -65,7 +67,7 @@
(for ([gid (in-list (· this glyphs))])
(send this _addGlyph gid))
#;(define maxp (cloneDeep (· this font maxp)))
(define maxp (cloneDeep (send (· this font) _getTable maxp)))
(unfinished)
)

@ -2,20 +2,25 @@
(require (for-syntax racket/base br/syntax) br/define)
(provide (all-defined-out))
(begin-for-syntax
(require racket/string racket/format)
(define (make-prefix caller-stx)
(string-join (map ~a (list (syntax-source caller-stx) (syntax-line caller-stx))) ":" #:after-last ":")))
(define-macro (define-stub-stop ID)
(with-pattern ([ERROR-ID (suffix-id (prefix-id (syntax-source #'this) ":" #'ID) ":not-implemented")])
(with-pattern ([ERROR-ID (suffix-id (prefix-id (make-prefix caller-stx) #'ID) ":not-implemented")])
#'(define (ID . args)
(error 'ERROR-ID))))
(provide (rename-out [define-stub-stop define-stub]))
(define-macro (define-stub-go ID)
(with-pattern ([ERROR-ID (suffix-id (prefix-id (syntax-source #'this) ":" #'ID) ":not-implemented")])
(with-pattern ([ERROR-ID (suffix-id (prefix-id (make-prefix caller-stx) #'ID) ":not-implemented")])
#'(define (ID . args)
(displayln 'ERROR-ID))))
(define-macro (define-unfinished (ID . ARGS) . BODY)
(with-pattern ([ID-UNFINISHED (suffix-id (prefix-id (syntax-source #'this) ":" #'ID) ":unfinished")])
(with-pattern ([ID-UNFINISHED (suffix-id (prefix-id (make-prefix caller-stx) #'ID) ":unfinished")])
#'(define (ID . ARGS)
(begin . BODY)
(error 'ID-UNFINISHED))))

Loading…
Cancel
Save