|
|
|
@ -65,16 +65,16 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
|
|
|
|
|
(unfinished))
|
|
|
|
|
|
|
|
|
|
;; Parses a single glyph coordinate
|
|
|
|
|
(define/public (_parseGlyphCoord stream prev short same)
|
|
|
|
|
(unless (DecodeStream? stream)
|
|
|
|
|
(raise-argument-error '_parseGlyphCoord "DecodeStream" stream))
|
|
|
|
|
(define/public (_parseGlyphCoord port prev short same)
|
|
|
|
|
(unless (input-port? port)
|
|
|
|
|
(raise-argument-error '_parseGlyphCoord "input port" port))
|
|
|
|
|
(unless (number? prev)
|
|
|
|
|
(raise-argument-error '_parseGlyphCoord "number" prev))
|
|
|
|
|
(unless (and (boolean? short) (boolean? same))
|
|
|
|
|
(raise-argument-error '_parseGlyphCoord "booleans" (list short same)))
|
|
|
|
|
(+ prev (if short
|
|
|
|
|
((if (not same) - +) (send uint8 decode stream))
|
|
|
|
|
(if same 0 (send int16be decode stream)))))
|
|
|
|
|
((if (not same) - +) (decode uint8 port))
|
|
|
|
|
(if same 0 (decode int16be port)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Decodes the glyph data into points for simple glyphs,
|
|
|
|
@ -95,26 +95,26 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
|
|
|
|
|
[(? negative?) (_decodeComposite glyph stream startPos)])
|
|
|
|
|
glyph)))
|
|
|
|
|
|
|
|
|
|
(define/public (_decodeSimple glyph stream)
|
|
|
|
|
(define/public (_decodeSimple glyph port)
|
|
|
|
|
(unless (dict? glyph)
|
|
|
|
|
(raise-argument-error 'TTFGlyph-_decodeSimple "decoded RGlyfHeader" glyph))
|
|
|
|
|
|
|
|
|
|
(unless (DecodeStream? stream)
|
|
|
|
|
(raise-argument-error 'TTFGlyph-_decodeSimple "DecodeStream" stream))
|
|
|
|
|
(unless (input-port? port)
|
|
|
|
|
(raise-argument-error 'TTFGlyph-_decodeSimple "input port" port))
|
|
|
|
|
|
|
|
|
|
;; this is a simple glyph
|
|
|
|
|
(dict-set! glyph 'points empty)
|
|
|
|
|
(define endPtsOfContours (send (+Array uint16be (· glyph numberOfContours)) decode stream))
|
|
|
|
|
(dict-set! glyph 'instructions (send (+Array uint8be uint16be) decode stream))
|
|
|
|
|
(define endPtsOfContours (decode (+Array uint16be (· glyph numberOfContours)) port))
|
|
|
|
|
(dict-set! glyph 'instructions (decode (+Array uint8be uint16be) port))
|
|
|
|
|
(define numCoords (add1 (last endPtsOfContours)))
|
|
|
|
|
|
|
|
|
|
(define flags
|
|
|
|
|
(for*/lists (flags)
|
|
|
|
|
([i (in-naturals)]
|
|
|
|
|
#:break (= (length flags) numCoords)
|
|
|
|
|
[flag (in-value (send uint8 decode stream))]
|
|
|
|
|
[flag (in-value (decode uint8 port))]
|
|
|
|
|
[count (in-range (add1 (if (not (zero? (bitwise-and flag REPEAT)))
|
|
|
|
|
(send uint8 decode stream)
|
|
|
|
|
(decode uint8 port)
|
|
|
|
|
0)))])
|
|
|
|
|
flag))
|
|
|
|
|
|
|
|
|
@ -123,8 +123,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
|
|
|
|
|
(for/fold ([points empty] [px 0] [py 0])
|
|
|
|
|
([(flag i) (in-indexed flags)])
|
|
|
|
|
(define point (+Point (zero? (bitwise-and flag ON_CURVE)) (and (index-of endPtsOfContours i) #t) 0 0))
|
|
|
|
|
(define next-px (_parseGlyphCoord stream px (not (zero? (bitwise-and flag X_SHORT_VECTOR))) (not (zero? (bitwise-and flag SAME_X)))))
|
|
|
|
|
(define next-py (_parseGlyphCoord stream py (not (zero? (bitwise-and flag Y_SHORT_VECTOR))) (not (zero? (bitwise-and flag SAME_Y)))))
|
|
|
|
|
(define next-px (_parseGlyphCoord port px (not (zero? (bitwise-and flag X_SHORT_VECTOR))) (not (zero? (bitwise-and flag SAME_X)))))
|
|
|
|
|
(define next-py (_parseGlyphCoord port py (not (zero? (bitwise-and flag Y_SHORT_VECTOR))) (not (zero? (bitwise-and flag SAME_Y)))))
|
|
|
|
|
(set-field! x point next-px)
|
|
|
|
|
(set-field! y point next-py)
|
|
|
|
|
(values (cons point points) next-px next-py)))
|
|
|
|
|