You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
4.7 KiB
Racket
81 lines
4.7 KiB
Racket
8 years ago
|
#lang fontkit/racket
|
||
|
(require restructure)
|
||
|
(provide (all-defined-out))
|
||
|
|
||
|
#|
|
||
|
approximates
|
||
|
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
|
||
|
(dictify 'typoAscender int16be
|
||
|
'typoDescender int16be
|
||
|
'typoLineGap int16be
|
||
|
'winAscent uint16be
|
||
|
'winDescent uint16be
|
||
|
'codePageRange (+Array uint32be 2)))
|
||
|
|
||
|
(define type-2-extra
|
||
|
(dictify 'xHeight int16be
|
||
|
'capHeight int16be
|
||
|
'defaultChar uint16be
|
||
|
'breakChar uint16be
|
||
|
'maxContent uint16be))
|
||
|
|
||
|
(define type-5-extra
|
||
|
(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)))))
|
||
|
|
||
|
(test-module
|
||
|
(define ip (open-input-file charter-path))
|
||
|
(define dir (deserialize (read (open-input-file charter-directory-path))))
|
||
|
(define offset (· dir tables OS/2 offset))
|
||
|
(define len (· dir tables OS/2 length))
|
||
|
(check-equal? offset 360)
|
||
|
(check-equal? len 96)
|
||
|
(define ds (+DecodeStream (peek-bytes len offset ip)))
|
||
|
(define version (send uint16be decode ds))
|
||
|
(send OS/2 force-version! version)
|
||
|
(define table-data (send OS/2 decode ds))
|
||
|
(check-equal? (· table-data panose) '(2 0 5 3 6 0 0 2 0 4))
|
||
|
(check-equal? (· table-data sFamilyClass) 0))
|