- adapted font system to properly handle Turkish.

Those i's are really messy, especially when dealing with allcaps or pure lowercase fonts.
This commit is contained in:
Christoph Oelckers 2023-03-31 17:40:19 +02:00 committed by nashmuhandes
commit f6affef791
9 changed files with 46 additions and 12 deletions

View file

@ -752,7 +752,23 @@ int FFont::GetCharCode(int code, bool needpic) const
// regular chars turn negative when the 8th bit is set.
code &= 255;
}
if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].OriginalPic != nullptr))
if (special_i && needpic)
{
// We need one special case for Turkish: If we have a lowercase-only font (like Raven's) and want to print the capital I, it must map to the dotless ı, because its own glyph will be the dotted i.
// This checks if the font has no small i, but does define the small dotless ı.
if (!MixedCase && code == 'I' && LastChar >= 0x131 && Chars['i' - FirstChar].OriginalPic == nullptr && Chars[0x131 - FirstChar].OriginalPic != nullptr)
{
return 0x131;
}
// a similar check is needed for the small i in allcaps fonts. Here we cannot simply remap to an existing character, so the small dotted i must be placed at code point 0080.
if (code == 'i' && LastChar >= 0x80 && Chars[0x80 - FirstChar].OriginalPic != nullptr)
{
return 0x131;
}
}
if (code >= FirstChar && code <= LastChar && Chars[code - FirstChar].OriginalPic != nullptr)
{
return code;
}
@ -766,7 +782,7 @@ int FFont::GetCharCode(int code, bool needpic) const
if (myislower(code))
{
code = upperforlower[code];
if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].OriginalPic != nullptr))
if (code >= FirstChar && code <= LastChar && Chars[code - FirstChar].OriginalPic != nullptr)
{
return code;
}
@ -775,7 +791,7 @@ int FFont::GetCharCode(int code, bool needpic) const
while ((newcode = stripaccent(code)) != code)
{
code = newcode;
if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].OriginalPic != nullptr))
if (code >= FirstChar && code <= LastChar && Chars[code - FirstChar].OriginalPic != nullptr)
{
return code;
}
@ -789,7 +805,7 @@ int FFont::GetCharCode(int code, bool needpic) const
while ((newcode = stripaccent(code)) != code)
{
code = newcode;
if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].OriginalPic != nullptr))
if (code >= FirstChar && code <= LastChar && Chars[code - FirstChar].OriginalPic != nullptr)
{
return code;
}
@ -800,14 +816,14 @@ int FFont::GetCharCode(int code, bool needpic) const
{
int upper = upperforlower[code];
// Stripping accents did not help - now try uppercase for lowercase
if (upper != code) return GetCharCode(upper, needpic);
if (upper != code) return GetCharCode(upper, true);
}
// Same for the uppercase character. Since we restart at the accented version this must go through the entire thing again.
while ((newcode = stripaccent(code)) != code)
{
code = newcode;
if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].OriginalPic != nullptr))
if (code >= FirstChar && code <= LastChar && Chars[code - FirstChar].OriginalPic != nullptr)
{
return code;
}
@ -907,7 +923,7 @@ bool FFont::CanPrint(const uint8_t *string) const
}
else if (chr != '\n')
{
int cc = GetCharCode(chr, true);
int cc = GetCharCode(chr, false);
if (chr != cc && myiswalpha(chr) && cc != getAlternative(chr))
{
return false;