feat(字体渲染): 加强字体兼容

This commit is contained in:
2026-07-01 14:43:04 +08:00
parent b85dd88ce2
commit e5e8063c4e
+20
View File
@@ -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
}