main
Matthew Butterick 8 years ago
parent fa1374984d
commit 0765d3e9cd

@ -10,7 +10,6 @@
[maxX -inf.0]
; The maxmimum Y position in the bounding box
[maxY -inf.0])
(super-new)
(as-methods
width

@ -14,8 +14,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
'length uint32be)))
(define-subclass RStruct (RDirectory)
(define/public (process)
'boom))
(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! res 'tables new-tables-val)))
(define Directory (make-object RDirectory
(dictify 'tag (make-object RString 4)
@ -30,28 +33,52 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
(send Directory decode is))
(module+ test
(require rackunit)
(require rackunit racket/serialize)
(define ip (open-input-file "test/assets/Charter.ttf"))
(check-equal?
(directory-decode ip)
(make-hasheq
(list (cons 'tables
(list (make-hasheq '((length . 96) (checkSum . 2351070438) (offset . 360) (tag . "OS/2")))
(make-hasheq '((length . 1504) (checkSum . 1887795202) (offset . 1372) (tag . "VDMX")))
(make-hasheq '((length . 1262) (checkSum . 1723761408) (offset . 2876) (tag . "cmap")))
(make-hasheq '((length . 26) (checkSum . 10290865) (offset . 4592) (tag . "cvt ")))
(make-hasheq '((length . 371) (checkSum . 106535991) (offset . 4140) (tag . "fpgm")))
(make-hasheq '((length . 34072) (checkSum . 1143629849) (offset . 4620) (tag . "glyf")))
(make-hasheq '((length . 54) (checkSum . 4281190895) (offset . 236) (tag . "head")))
(make-hasheq '((length . 36) (checkSum . 132056097) (offset . 292) (tag . "hhea")))
(make-hasheq '((length . 916) (checkSum . 3982043058) (offset . 456) (tag . "hmtx")))
(make-hasheq '((length . 460) (checkSum . 2795817194) (offset . 38692) (tag . "loca")))
(make-hasheq '((length . 32) (checkSum . 50135594) (offset . 328) (tag . "maxp")))
(make-hasheq '((length . 2367) (checkSum . 2629707307) (offset . 39152) (tag . "name")))
(make-hasheq '((length . 514) (checkSum . 1670855689) (offset . 41520) (tag . "post")))
(make-hasheq '((length . 78) (checkSum . 490862356) (offset . 4512) (tag . "prep")))))
(cons 'entrySelector 3)
(cons 'numTables 14)
(cons 'searchRange 128)
(cons 'rangeShift 96)
(cons 'tag "\u0000\u0001\u0000\u0000")))))
(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"))
()
(h
!
()
(tag u . "\u0000\u0001\u0000\u0000")
(rangeShift . 96)
(searchRange . 128)
(numTables . 14)
(entrySelector . 3)
(tables
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))))))))

@ -3,7 +3,6 @@
(provide EmbeddedFont)
(define-subclass PDFFont (EmbeddedFont document font id)
(super-new)
(field [subset (· this font createSubset)]
;; we make `unicode` and `width` fields integer-keyed hashes not lists
;; because they offer better random access and growability

@ -27,7 +27,6 @@
(check-false (and (is-mark? #x2ee) #t)))
(define-subclass object% (Glyph id codePoints font)
(super-new)
(field [_font font]
[isMark (andmap is-mark? codePoints)]
[isLigature (> (length codePoints) 1)]
@ -58,11 +57,9 @@
(define-subclass Glyph (CFFGlyph)
(super-new)
(error 'cff-glyph-unimplemented))
(define-subclass Glyph (TTFGlyph)
(super-new)
)

@ -10,7 +10,6 @@
script ; The script that was requested for shaping. This was either passed in or detected automatically.
language) ; The language requested for shaping, as passed in. If `null`, the default language for the script was used.
(super-new)
;; An array of GlyphPosition objects for each glyph in the run
(field [positions #f])

@ -3,7 +3,6 @@
(provide LayoutEngine)
(define-subclass object% (LayoutEngine font)
(super-new)
(field [unicodeLayoutEngine #f]
[kernProcessor #f]
[engine

@ -6,7 +6,6 @@
;; https://github.com/devongovett/fontkit/blob/master/src/subset/Subset.js
(define-subclass object% (Subset font)
(super-new)
(field [glyphs empty] ; list of glyph ids in the subset
[mapping (mhash)] ; mapping of glyph ids to indexes in `glyphs`
)
@ -28,7 +27,6 @@
(define-subclass Subset (CFFSubset)
(super-new)
(error 'cff-subset-unimplemented))
@ -36,7 +34,6 @@
;; https://github.com/devongovett/fontkit/blob/master/src/subset/TTFSubset.js
(define-subclass Subset (TTFSubset)
(super-new)
(field [glyphEncoder (make-object TTFGlyphEncoder)])
(field [glyf #f]
[offset #f]
@ -68,7 +65,7 @@
(for ([gid (in-list (· this glyphs))])
(send this _addGlyph gid))
(define maxp (cloneDeep (· this font maxp)))
#;(define maxp (cloneDeep (· this font maxp)))
(unfinished)
)

@ -2,8 +2,6 @@
(provide TTFGlyphEncoder)
(define-subclass object% (TTFGlyphEncoder)
(super-new)
(as-methods
encodeSimple
_encodePoint))

@ -7,6 +7,8 @@
(super-new)
(abstract decode)
(abstract encode)
(define/public (process . args)
(void))
#;(abstract size)))

@ -13,10 +13,11 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
(for ([(k v) (in-dict assocs)])
(hash-set! fields k v))
(define/override (decode stream [parent #f] [length 0])
(define/overment (decode stream [parent #f] [length 0])
(define res (_setup stream parent length))
(_parseFields stream res fields)
#;(hash-set! (hash-ref res '_props) '_currentOffset (· stream pos))
(send this process res stream)
res)
(define/override (encode stream val [parent #f])

Loading…
Cancel
Save