mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-19 14:30:37 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user