fallback for older OS/2 tables

the capHeight and xHeight fields were introduced in the version 4 OS/2 table. Ancient fonts may have an earlier version of the table, and thus be missing these fields.
main
Matthew Butterick 2 years ago
parent d6e4b81675
commit fcfebb70bf

@ -67,14 +67,14 @@ https://github.com/mbutterick/fontkit/blob/master/src/TTFFont.js
(define (font-italic-angle font) (hash-ref (get-post-table font) 'italicAngle))
(define (font-cap-height font)
(if (has-table? font #"OS/2")
(hash-ref (get-OS/2-table font) 'capHeight)
(font-ascent font)))
(cond
[(and (has-table? font #"OS/2") (hash-ref (get-OS/2-table font) 'capHeight #false))]
[else (font-ascent font)]))
(define (font-x-height font)
(if (has-table? font #"OS/2")
(hash-ref (get-OS/2-table font) 'xHeight)
0))
(cond
[(has-table? font #"OS/2") (hash-ref (get-OS/2-table font) 'xHeight #false)]
[else 0]))
(define (font-bbox font)
(define head-table (get-head-table font))

Loading…
Cancel
Save