rename prefixes

main
Matthew Butterick 6 years ago
parent d6fff41bb8
commit 1ce1956eef

@ -14,10 +14,10 @@
https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
|#
(define table-entry (+xstruct
'tag (+xsymbol #:length 4)
(define table-entry (x:struct
'tag (x:symbol #:length 4)
'checkSum uint32be
'offset (+xpointer #:offset-type uint32be
'offset (x:pointer #:offset-type uint32be
#:type 'void
#:relative-to 'global)
'length uint32be))
@ -40,7 +40,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
(define table-codec (hash-ref table-codecs tag))
(mhash 'tag (unescape-tag tag)
'checkSum 0
'offset (+xvoid-pointer table-codec table)
'offset (x:void-pointer table-codec table)
'length (size table-codec table))))
(define numTables (length tables))
(define searchRange (* (floor (log numTables 2)) 16))
@ -53,14 +53,14 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js
'rangeShift (- (* numTables 16) searchRange))
this-val)
(define Directory (+xstruct #:pre-encode directory-pre-encode
(define Directory (x:struct #:pre-encode directory-pre-encode
#:post-decode directory-post-decode
'tag (+xsymbol #:length 4)
'tag (x:symbol #:length 4)
'numTables uint16be
'searchRange uint16be
'entrySelector uint16be
'rangeShift uint16be
'tables (+xarray #:type table-entry #:length 'numTables)))
'tables (x:array #:type table-entry #:length 'numTables)))
(define (directory-decode ip [options (mhash)])
(decode Directory ip))

@ -96,9 +96,9 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
(struct hb-position (xad yad xoff yoff etc) #:transparent)
(struct hb-layout (hb-gids hb-clusters hb-positions) #:transparent)
(define hb-output (+xstruct 'hb-gids (+xarray #:type uint16 #:length uint16)
'hb-clusters (+xarray #:type (+xarray #:type uint16 #:length uint16) #:length uint16)
'hb-positions (+xarray #:type (+xarray #:type uint16 #:length 5) #:length uint16)))
(define hb-output (x:struct 'hb-gids (x:array #:type uint16 #:length uint16)
'hb-clusters (x:array #:type (x:array #:type uint16 #:length uint16) #:length uint16)
'hb-positions (x:array #:type (x:array #:type uint16 #:length 5) #:length uint16)))
(define (hb-layout->glyphrun font hbr)
(match hbr
@ -125,9 +125,9 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
(define layout-cache (make-hasheqv))
(define hb-input (+xstruct 'font-crc uint32
'codepoints (+xarray #:type uint16)
'userFeatures (+xarray #:type (+xstring #:length uint8))))
(define hb-input (x:struct 'font-crc uint32
'codepoints (x:array #:type uint16)
'userFeatures (x:array #:type (x:string #:length uint8))))
(define (layout-cache-key font-crc codepoints user-features . _)
(crc32c-bytes (encode hb-input (dictify

@ -11,5 +11,5 @@ https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFFont.js
;; the CFFFont object acts as the decoder for the `CFF ` table.
;; no CFF support yet
(define CFF_ (+xbuffer))
(define CFF_ (x:buffer))

@ -17,7 +17,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/OS2.js
'typoLineGap int16be
'winAscent uint16be
'winDescent uint16be
'codePageRange (+xarray #:type uint32be #:length 2)))
'codePageRange (x:array #:type uint32be #:length 2)))
(define type-2
(dictify 'xHeight int16be
@ -30,14 +30,14 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/OS2.js
(dictify 'usLowerOpticalPointSize uint16be
'usUpperOpticalPointSize uint16be))
(+xversioned-struct
(x:versioned-struct
uint16be
(dictify
'header (dictify 'xAvgCharWidth int16be ;; average weighted advance width of lower case letters and space
'usWeightClass uint16be ;; visual weight of stroke in glyphs
'usWidthClass uint16be ;; relative change from the normal aspect ratio (width to height ratio)
;; Indicates font embedding licensing rights
'fsType (+xbitfield #:type uint16be
'fsType (x:bitfield #:type uint16be
#:flags '(null noEmbedding viewOnly editable null null null null noSubsetting bitmapOnly))
'ySubscriptXSize int16be ;; recommended horizontal size in pixels for subscripts
'ySubscriptYSize int16be ;; recommended vertical size in pixels for subscripts
@ -50,11 +50,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/OS2.js
'yStrikeoutSize int16be ;; width of the strikeout stroke
'yStrikeoutPosition int16be ;; position of the strikeout stroke relative to the baseline
'sFamilyClass int16be ;; classification of font-family design
'panose (+xarray #:type uint8 #:length 10) ;; describe the visual characteristics of a given typeface
'ulCharRange (+xarray #:type uint32be #:length 4)
'vendorID (+xsymbol #:length 4) ;; four character identifier for the font vendor
'panose (x:array #:type uint8 #:length 10) ;; describe the visual characteristics of a given typeface
'ulCharRange (x:array #:type uint32be #:length 4)
'vendorID (x:symbol #:length 4) ;; four character identifier for the font vendor
;; bit field containing information about the font
'fsSelection (+xbitfield #:type uint16
'fsSelection (x:bitfield #:type uint16
#:flags '(italic underscore negative outlined strikeout bold regular useTypoMetrics wws oblique))
'usFirstCharIndex uint16be ;; The minimum Unicode index in this font
'usLastCharIndex uint16be) ;; The maximum Unicode index in this font

@ -11,7 +11,7 @@ approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/cvt.js
|#
(define cvt_ (+xstruct 'controlValues (+xarray #:type int16be)))
(define cvt_ (x:struct 'controlValues (x:array #:type int16be)))
(module+ test
(require rackunit racket/serialize

@ -12,7 +12,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/fpgm.js
;; These instructions are known as the font program. The main use of this table
;; is for the definition of functions that are used in many different glyph programs.
(define fpgm (+xstruct 'instructions (+xarray #:type uint8)))
(define fpgm (x:struct 'instructions (x:array #:type uint8)))
(module+ test
(require rackunit racket/serialize racket/dict

@ -8,7 +8,7 @@ approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/glyf.js
|#
(define glyf (+xarray #:type (+xbuffer)))
(define glyf (x:array #:type (x:buffer)))
(test-module
(require sugar/unstable/js

@ -11,20 +11,20 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/head.js
|#
(define head (+xstruct
(define head (x:struct
'version int32be ;; 0x00010000 (version 1.0)
'revision int32be ;; set by font manufacturer
'checkSumAdjustment uint32be
'magicNumber uint32be ;; set to 0x5F0F3CF5
'flags uint16be
'unitsPerEm uint16be ;; range from 64 to 16384
'created (+xarray #:type int32be #:length 2)
'modified (+xarray #:type int32be #:length 2)
'created (x:array #:type int32be #:length 2)
'modified (x:array #:type int32be #:length 2)
'xMin int16be ;; for all glyph bounding boxes
'yMin int16be ;; for all glyph bounding boxes
'xMax int16be ;; for all glyph bounding boxes
'yMax int16be ;; for all glyph bounding boxes
'macStyle (+xbitfield #:type uint16be
'macStyle (x:bitfield #:type uint16be
#:flags '(bold italic underline outline shadow condensed extended))
'lowestRecPPEM uint16be ;; smallest readable size in pixels
'fontDirectionHint int16be

@ -5,7 +5,7 @@
xenomorph)
(provide (all-defined-out))
(define hhea (+xstruct
(define hhea (x:struct
(dictify
'version int32be
'ascent int16be ;; Distance from baseline of highest ascender
@ -18,7 +18,7 @@
'caretSlopeRise int16be ;; Used to calculate the slope of the cursor (rise/run); 1 for vertical
'caretSlopeRun int16be ;; 0 for vertical
'caretOffset int16be ;; Set to 0 for non-slanted fonts
'reserved (+xarray #:type int16be #:length 4)
'reserved (x:array #:type int16be #:length 4)
'metricDataFormat int16be ;; 0 for current format
'numberOfMetrics uint16be ;; Number of advance widths in 'hmtx' table
)))

@ -10,20 +10,20 @@ approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/hmtx.js
|#
(define hmtx-entry (+xstruct 'advance uint16be 'bearing int16be))
(define hmtx-entry (x:struct 'advance uint16be 'bearing int16be))
(define hmtx (+xstruct 'metrics (+xlazy-array #:type hmtx-entry
(define hmtx (x:struct 'metrics (x:lazy-array #:type hmtx-entry
#:length (λ (arr) (· arr parent hhea numberOfMetrics)))
'bearings (+xlazy-array #:type int16be
'bearings (x:lazy-array #:type int16be
#:length (λ (arr) (- (· arr parent maxp numGlyphs)
(· arr parent hhea numberOfMetrics))))))
(module+ test
(require rackunit racket/serialize racket/stream)
;; same as hmtx but doesn't require resolution of function to get length
(define hmtx-test (+xstruct
'metrics (+xlazy-array hmtx-entry (λ (t) 229))
'bearing (+xlazy-array int16be (λ (t) 0))))
(define hmtx-test (x:struct
'metrics (x:lazy-array hmtx-entry (λ (t) 229))
'bearing (x:lazy-array int16be (λ (t) 0))))
(define ip (open-input-file charter-path))
(define dir (deserialize (read (open-input-file charter-directory-path))))
(define hmtx-offset (· dir tables hmtx offset))

@ -36,22 +36,22 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js
(dict-update! val 'offsets (λ (offsets) (map (λ (x) (* 2 x)) offsets))))
val)
(define loca (+xversioned-struct
(define loca (x:versioned-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)))))
0 (dictify 'offsets (x:array #:type uint16be))
1 (dictify 'offsets (x:array #:type uint32be)))))
(define loca-v0 (+xversioned-struct
(define loca-v0 (x:versioned-struct
#:pre-encode loca-pre-encode
#:post-decode loca-post-decode
0
(dictify
0 (dictify 'offsets (+xarray #:type uint16be))
1 (dictify 'offsets (+xarray #:type uint32be)))))
0 (dictify 'offsets (x:array #:type uint16be))
1 (dictify 'offsets (x:array #:type uint32be)))))
(module+ test
(require rackunit racket/serialize)
@ -66,6 +66,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/loca.js
(check-equal? offset 38692)
(check-equal? len 460)
(define offset-bytes (peek-bytes len offset ip))
(define offsets (map (λ (x) (* 2 x)) (decode (+xarray uint16be) offset-bytes)))
(define offsets (map (λ (x) (* 2 x)) (decode (x:array uint16be) offset-bytes)))
(check-equal? (length offsets) 230)
(check-equal? offsets '(0 0 0 136 296 500 864 1168 1548 1628 1716 1804 1944 2048 2128 2176 2256 2312 2500 2596 2788 3052 3168 3396 3624 3732 4056 4268 4424 4564 4640 4728 4804 5012 5384 5532 5808 6012 6212 6456 6672 6916 7204 7336 7496 7740 7892 8180 8432 8648 8892 9160 9496 9764 9936 10160 10312 10536 10780 10992 11148 11216 11272 11340 11404 11444 11524 11820 12044 12216 12488 12728 12932 13324 13584 13748 13924 14128 14232 14592 14852 15044 15336 15588 15776 16020 16164 16368 16520 16744 16984 17164 17320 17532 17576 17788 17896 18036 18284 18552 18616 18988 19228 19512 19712 19796 19976 20096 20160 20224 20536 20836 20876 21000 21200 21268 21368 21452 21532 21720 21908 22036 22244 22664 22872 22932 22992 23088 23220 23268 23372 23440 23600 23752 23868 23988 24084 24184 24224 24548 24788 25012 25292 25716 25884 26292 26396 26540 26796 27172 27488 27512 27536 27560 27584 27912 27936 27960 27984 28008 28032 28056 28080 28104 28128 28152 28176 28200 28224 28248 28272 28296 28320 28344 28368 28392 28416 28440 28464 28488 28512 28536 28560 28968 28992 29016 29040 29064 29088 29112 29136 29160 29184 29208 29232 29256 29280 29304 29328 29352 29376 29400 29424 29448 29472 29496 29520 29824 30164 30220 30652 30700 30956 31224 31248 31332 31488 31636 31916 32104 32176 32484 32744 32832 32956 33248 33664 33884 34048 34072)))

@ -5,7 +5,7 @@
"../helper.rkt")
(provide (all-defined-out))
(define maxp (+xstruct
(define maxp (x:struct
'version int32be
'numGlyphs uint16be ;; The number of glyphs in the font
'maxPoints uint16be ;; Maximum points in a non-composite glyph

@ -11,7 +11,7 @@ approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/post.js
|#
(define post (+xversioned-struct
(define post (x:versioned-struct
fixed32be
(dictify
'header (dictify 'italicAngle fixed32be ;; Italic angle in counter-clockwise degrees from the vertical.
@ -25,13 +25,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/post.js
1 null
2 (dictify 'numberOfGlyphs uint16be
'glyphNameIndex (+xarray #:type uint16be #:length 'numberOfGlyphs)
'names (+xarray (+xstring #:length uint8))
'glyphNameIndex (x:array #:type uint16be #:length 'numberOfGlyphs)
'names (x:array (x:string #:length uint8))
)
2.5 (dictify 'numberOfGlyphs uint16be
'offsets (+xarray #:type uint8))
'offsets (x:array #:type uint8))
3 null
4 (dictify 'map (+xarray #:type uint32be #:length (λ (t) (· t parent maxp numGlyphs)))))))
4 (dictify 'map (x:array #:type uint32be #:length (λ (t) (· t parent maxp numGlyphs)))))))
(module+ test
(require rackunit racket/serialize racket/class)

@ -9,7 +9,7 @@ approximates
https://github.com/mbutterick/fontkit/blob/master/src/tables/prep.js
|#
(define prep (+xstruct 'controlValueProgram (+xarray #:type uint8)))
(define prep (x:struct 'controlValueProgram (x:array #:type uint8)))
(module+ test
(require rackunit racket/dict racket/serialize sugar/unstable/port)

@ -19,7 +19,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
;; The header for both simple and composite glyphs
(define GlyfHeader (+xstruct 'numberOfContours int16be ;; if negative, this is a composite glyph
(define GlyfHeader (x:struct 'numberOfContours int16be ;; if negative, this is a composite glyph
'xMin int16be
'yMin int16be
'xMax int16be
@ -122,8 +122,8 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/TTFGlyph.js
;; this is a simple glyph
(dict-set! glyph-data 'points empty)
(define endpts-of-contours (decode (+xarray #:type uint16be #:length (· glyph-data numberOfContours)) port))
(dict-set! glyph-data 'instructions (decode (+xarray #:type uint8be #:length uint16be) port))
(define endpts-of-contours (decode (x:array #:type uint16be #:length (· glyph-data numberOfContours)) port))
(dict-set! glyph-data 'instructions (decode (x:array #:type uint8be #:length uint16be) port))
(define num-coords (add1 (last endpts-of-contours)))
(define flags

Loading…
Cancel
Save