From af9d77dc986a99ba8085f980e6ad7b28277008ad Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 3 Jul 2017 08:48:41 -0700 Subject: [PATCH] use 'header --- pitfall/fontkit/GPOS.rkt | 12 +++--- pitfall/fontkit/OS2.rkt | 74 +++++++++++++++++------------------ pitfall/fontkit/directory.rkt | 16 ++++---- pitfall/fontkit/post.rkt | 48 +++++++++++------------ 4 files changed, 71 insertions(+), 79 deletions(-) diff --git a/pitfall/fontkit/GPOS.rkt b/pitfall/fontkit/GPOS.rkt index 8db1c987..e72b1914 100644 --- a/pitfall/fontkit/GPOS.rkt +++ b/pitfall/fontkit/GPOS.rkt @@ -185,15 +185,13 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/GPOS.js ;; Fix circular reference (ref*-set! GPOSLookup 'versions 9 'extension 'type GPOSLookup) -(define gpos-common-dict (dictify 'scriptList (+Pointer uint16be ScriptList) - 'featureList (+Pointer uint16be FeatureList) - 'lookupList (+Pointer uint16be (LookupList GPOSLookup)))) - (define-subclass VersionedStruct (GPOS-MainVersionedStruct)) (define GPOS (+GPOS-MainVersionedStruct uint32be (dictify - #x00010000 gpos-common-dict - ;; ignore variations - #;#x00010001 #;(append gpos-common-dict (dictify 'featureVariations (+Pointer uint32be FeatureVariations)))))) + 'header (dictify 'scriptList (+Pointer uint16be ScriptList) + 'featureList (+Pointer uint16be FeatureList) + 'lookupList (+Pointer uint16be (LookupList GPOSLookup))) + #x00010000 (dictify) + #;#x00010001 #;(+Pointer uint32be FeatureVariations)))) (test-module) \ No newline at end of file diff --git a/pitfall/fontkit/OS2.rkt b/pitfall/fontkit/OS2.rkt index 4e4e90a1..3eb73cf8 100644 --- a/pitfall/fontkit/OS2.rkt +++ b/pitfall/fontkit/OS2.rkt @@ -10,33 +10,7 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/OS2.js (define-subclass VersionedStruct (ROS/2)) (define OS/2 (let () - (define header-fields - (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 (+Bitfield uint16be '(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 - 'ySubscriptXOffset int16be ;; recommended horizontal offset for subscripts - 'ySubscriptYOffset int16be ;; recommended vertical offset form the baseline for subscripts - 'ySuperscriptXSize int16be ;; recommended horizontal size in pixels for superscripts - 'ySuperscriptYSize int16be ;; recommended vertical size in pixels for superscripts - 'ySuperscriptXOffset int16be ;; recommended horizontal offset for superscripts - 'ySuperscriptYOffset int16be ;; recommended vertical offset from the baseline for superscripts - '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 (+Array uint8 10) ;; describe the visual characteristics of a given typeface - 'ulCharRange (+Array uint32be 4) - 'vendorID (+String 4) ;; four character identifier for the font vendor - ;; bit field containing information about the font - 'fsSelection (+Bitfield uint16 '(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 - )) - - (define type-1-extra + (define type-1 (dictify 'typoAscender int16be 'typoDescender int16be 'typoLineGap int16be @@ -44,26 +18,50 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/OS2.js 'winDescent uint16be 'codePageRange (+Array uint32be 2))) - (define type-2-extra + (define type-2 (dictify 'xHeight int16be 'capHeight int16be 'defaultChar uint16be 'breakChar uint16be 'maxContent uint16be)) - (define type-5-extra + (define type-5 (dictify 'usLowerOpticalPointSize uint16be 'usUpperOpticalPointSize uint16be)) - (make-object ROS/2 - uint16be - (dictify - 0 (append header-fields null) - 1 (append header-fields type-1-extra) - 2 (append header-fields type-1-extra type-2-extra) - 3 (append header-fields type-1-extra type-2-extra) - 4 (append header-fields type-1-extra type-2-extra) - 5 (append header-fields type-1-extra type-2-extra type-5-extra))))) + (+ROS/2 + 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 (+Bitfield uint16be '(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 + 'ySubscriptXOffset int16be ;; recommended horizontal offset for subscripts + 'ySubscriptYOffset int16be ;; recommended vertical offset form the baseline for subscripts + 'ySuperscriptXSize int16be ;; recommended horizontal size in pixels for superscripts + 'ySuperscriptYSize int16be ;; recommended vertical size in pixels for superscripts + 'ySuperscriptXOffset int16be ;; recommended horizontal offset for superscripts + 'ySuperscriptYOffset int16be ;; recommended vertical offset from the baseline for superscripts + '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 (+Array uint8 10) ;; describe the visual characteristics of a given typeface + 'ulCharRange (+Array uint32be 4) + 'vendorID (+String 4) ;; four character identifier for the font vendor + ;; bit field containing information about the font + 'fsSelection (+Bitfield uint16 '(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 + + 0 null + 1 type-1 + 2 (append type-1 type-2) + 3 (append type-1 type-2) + 4 (append type-1 type-2) + 5 (append type-1 type-2 type-5))))) (test-module (define ip (open-input-file charter-path)) diff --git a/pitfall/fontkit/directory.rkt b/pitfall/fontkit/directory.rkt index c755dfe9..3f2547e1 100644 --- a/pitfall/fontkit/directory.rkt +++ b/pitfall/fontkit/directory.rkt @@ -7,7 +7,6 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js |# - (define TableEntry (+Struct (dictify 'tag (+String 4) 'checkSum uint32be @@ -30,10 +29,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js (define/override (preEncode this-val stream) (define tables (for/list ([(tag table) (in-hash (· this-val tables))]) + (define table-codec (hash-ref table-codecs tag)) (mhash 'tag (unescape-tag tag) 'checkSum 0 - 'offset (+VoidPointer (hash-ref table-codecs tag) table) - 'length (send (hash-ref table-codecs tag) size table)))) + 'offset (+VoidPointer table-codec table) + 'length (send table-codec size table)))) (define numTables (length tables)) (define searchRange (* (floor (log numTables 2)) 16)) @@ -47,11 +47,11 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/directory.js 'rangeShift (- (* numTables 16) searchRange)))) (define Directory (+RDirectory (dictify 'tag (+String 4) - 'numTables uint16be - 'searchRange uint16be - 'entrySelector uint16be - 'rangeShift uint16be - 'tables (+Array TableEntry 'numTables)))) + 'numTables uint16be + 'searchRange uint16be + 'entrySelector uint16be + 'rangeShift uint16be + 'tables (+Array TableEntry 'numTables)))) (define (directory-decode ip [options (mhash)]) diff --git a/pitfall/fontkit/post.rkt b/pitfall/fontkit/post.rkt index 6ffaa002..3e40eac1 100644 --- a/pitfall/fontkit/post.rkt +++ b/pitfall/fontkit/post.rkt @@ -10,32 +10,28 @@ https://github.com/mbutterick/fontkit/blob/master/src/tables/post.js (define-subclass VersionedStruct (Rpost)) -(define post (let () - (define header-fields - (dictify 'italicAngle fixed32be ;; Italic angle in counter-clockwise degrees from the vertical. - 'underlinePosition int16be ;; Suggested distance of the top of the underline from the baseline - 'underlineThickness int16be ;; Suggested values for the underline thickness - 'isFixedPitch uint32be ;; Whether the font is monospaced - 'minMemType42 uint32be ;; Minimum memory usage when a TrueType font is downloaded as a Type 42 font - 'maxMemType42 uint32be ;; Maximum memory usage when a TrueType font is downloaded as a Type 42 font - 'minMemType1 uint32be ;; Minimum memory usage when a TrueType font is downloaded as a Type 1 font - 'maxMemType1 uint32be ;; Maximum memory usage when a TrueType font is downloaded as a Type 1 font - )) - - - (make-object Rpost - fixed32be - (dictify - 1 (append header-fields null) - 2 (append header-fields (dictify 'numberOfGlyphs uint16be - 'glyphNameIndex (+Array uint16be 'numberOfGlyphs) - ;; this field causes problems due to deficiency in String class - ;; 'names (+Array (+String uint8)) - )) - 2.5 (append header-fields (dictify 'numberOfGlyphs uint16be - 'offsets (+Array uint8))) - 3 (append header-fields null) - 4 (append header-fields (dictify 'map (+Array uint32be (λ (t) (· t parent maxp numGlyphs))))))))) +(define post (make-object Rpost + fixed32be + (dictify + 'header (dictify 'italicAngle fixed32be ;; Italic angle in counter-clockwise degrees from the vertical. + 'underlinePosition int16be ;; Suggested distance of the top of the underline from the baseline + 'underlineThickness int16be ;; Suggested values for the underline thickness + 'isFixedPitch uint32be ;; Whether the font is monospaced + 'minMemType42 uint32be ;; Minimum memory usage when a TrueType font is downloaded as a Type 42 font + 'maxMemType42 uint32be ;; Maximum memory usage when a TrueType font is downloaded as a Type 42 font + 'minMemType1 uint32be ;; Minimum memory usage when a TrueType font is downloaded as a Type 1 font + 'maxMemType1 uint32be) ;; Maximum memory usage when a TrueType font is downloaded as a Type 1 font + + 1 null + 2 (dictify 'numberOfGlyphs uint16be + 'glyphNameIndex (+Array uint16be 'numberOfGlyphs) + ;; this field causes problems due to deficiency in String class + ;; 'names (+Array (+String uint8)) + ) + 2.5 (dictify 'numberOfGlyphs uint16be + 'offsets (+Array uint8)) + 3 null + 4 (dictify 'map (+Array uint32be (λ (t) (· t parent maxp numGlyphs))))))) (test-module (define ip (open-input-file charter-path))