From fcfebb70bf76916136e8fc84e9b7f20b870bb0b4 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 7 Jun 2022 10:43:43 -0700 Subject: [PATCH] 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. --- fontland/fontland/font.rkt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fontland/fontland/font.rkt b/fontland/fontland/font.rkt index d85537f5..efe60f4b 100644 --- a/fontland/fontland/font.rkt +++ b/fontland/fontland/font.rkt @@ -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))