From e5e8063c4ed92491a650c5f8e3aef6d59dd35842 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Wed, 1 Jul 2026 14:43:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=AD=97=E4=BD=93=E6=B8=B2=E6=9F=93):=20?= =?UTF-8?q?=E5=8A=A0=E5=BC=BA=E5=AD=97=E4=BD=93=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdgo_font_ttf.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ofdgo_font_ttf.go b/ofdgo_font_ttf.go index bcc70b1..e282c67 100644 --- a/ofdgo_font_ttf.go +++ b/ofdgo_font_ttf.go @@ -97,6 +97,26 @@ func fixTrueType(data []byte, fixCmap, fixName bool) (bool, []byte, map[rune]uin if numGlyphs == 0 { numGlyphs = 255 } + if !missingHhea && !missingHmtx { + hhea := existingTables["hhea"] + hmtx := existingTables["hmtx"] + if len(hhea) < 36 { + missingHhea = true + } else { + numMetrics := binary.BigEndian.Uint16(hhea[34:36]) + if numMetrics == 0 || numMetrics > numGlyphs { + missingHhea = true + } else { + expectHmtx := int(numMetrics)*4 + int(numGlyphs-numMetrics)*2 + if len(hmtx) < expectHmtx { + missingHmtx = true + } else if len(hmtx) > expectHmtx { + existingTables["hmtx"] = hmtx[:expectHmtx] + malformedDirectory = true + } + } + } + } if !missingPost && hasBadPostTable(existingTables["post"], numGlyphs, !isCFFSfnt) { missingPost = true }