fix: t6 font crash (#881)

* fix: make sure t6 always has at least one kerning pair

* chore: ignore nonesense kerning pairs when dumping
This commit is contained in:
Jan
2026-07-05 23:17:34 +02:00
committed by GitHub
parent a8bb7d5599
commit 5564db4f5a
2 changed files with 31 additions and 7 deletions
+11 -4
View File
@@ -306,14 +306,21 @@ namespace
}
SortKerningPairs(font);
if (!EnsureFontContainsGlyphsOfKerningPairs(font))
return false;
}
else
{
font.kerningPairs = nullptr;
// The game is bugged here and accesses the kerning pairs even when kerningPairsCount is set to 0.
// It always checks the first entry so we add a nonsense entry here that never matches
// to ensure that no kerning is applied on randomly matching bytes.
font.kerningPairsCount = 1;
font.kerningPairs = m_memory.Alloc<KerningPairs>(1);
font.kerningPairs[0].wFirst = 0;
font.kerningPairs[0].wSecond = 0;
font.kerningPairs[0].iKernAmount = 0;
}
if (!EnsureFontContainsGlyphsOfKerningPairs(font))
return false;
#endif
return true;
+20 -3
View File
@@ -61,6 +61,20 @@ namespace
}
#ifdef FEATURE_T6
bool HasActualKerningPairs(const Font_s& font)
{
if (font.kerningPairs == nullptr)
return false;
if (font.kerningPairsCount > 1)
return true;
if (font.kerningPairsCount == 0)
return false;
const auto& firstKerningPair = font.kerningPairs[0];
return firstKerningPair.wFirst != 0 || firstKerningPair.wSecond != 0 || firstKerningPair.iKernAmount != 0;
}
void CreateJsonKerningPair(JsonKerningPair& jKerningPair, const KerningPairs& kerningPair)
{
jKerningPair.firstLetter = kerningPair.wFirst;
@@ -91,9 +105,12 @@ namespace
CreateJsonGlyph(jFont.glyphs[i], font.glyphs[i]);
#ifdef FEATURE_T6
jFont.kerningPairs.resize(font.kerningPairsCount);
for (auto i = 0; i < font.kerningPairsCount; i++)
CreateJsonKerningPair(jFont.kerningPairs[i], font.kerningPairs[i]);
if (HasActualKerningPairs(font))
{
jFont.kerningPairs.resize(font.kerningPairsCount);
for (auto i = 0; i < font.kerningPairsCount; i++)
CreateJsonKerningPair(jFont.kerningPairs[i], font.kerningPairs[i]);
}
#endif
}