- did a bit of fine tuning to the character replacement mappings:

* prefer accent-less lower case over uppercase letters if an accented lower case letter cannot be found.
* added accent-less mappings for Latin Extended 1 (0x100-0x17f) and some easy to handle characters between 0x200 and 0x220. This should allow to display all Eastern European text without empty gaps for missing letters.
This commit is contained in:
Christoph Oelckers 2019-02-17 13:41:04 +01:00
parent 9102fb86a5
commit 0963156c0a

View file

@ -809,13 +809,14 @@ static bool myislower(int code)
return false;
}
// Returns a character without an accent mark.
// FIXME: Only valid for CP-1252; we should go Unicode at some point.
// Returns a character without an accent mark (or one with a similar looking accent in some cases where direct support is unlikely.
static int stripaccent(int code)
{
if (code < 0x8a)
return code;
if (code < 0x100)
{
if (code == 0x8a) // Latin capital letter S with caron
return 'S';
if (code == 0x8e) // Latin capital letter Z with caron
@ -854,7 +855,21 @@ static int stripaccent(int code)
return 'Y' + (code & 0x20);
if (acode == 0xDE) // Thorn
return 'P' + (code & 0x20); // well, it sort of looks like a 'P'
// fixme: codes above 0x100 not supported yet!
}
else if (code >= 0x100 && code < 0x180)
{
static const char accentless[] = "AaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnnNnOoOoOoOoRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZz ";
return accentless[code -0x100];
}
else if (code >= 0x200 && code < 0x21c)
{
// 0x200-0x217 are probably irrelevant but easy to map to other characters more likely to exist. 0x218-0x21b are relevant for Romanian but also have a fallback within ranges that are more likely to be supported.
static const uint16_t u200map[] = {0xc4, 0xe4, 0xc2, 0xe2, 0xcb, 0xeb, 0xca, 0xea, 0xcf, 0xef, 0xce, 0xee, 0xd6, 0xf6, 0xd4, 0xe4, 'R', 'r', 'R', 'r', 0xdc, 0xfc, 0xdb, 0xfb, 0x15e, 0x15f, 0x162, 0x163};
return u200map[code - 0x200];
}
// skip the rest of Latin characters because none of them are relevant for modern languages.
return code;
}
@ -1442,18 +1457,12 @@ int FFont::GetCharCode(int code, bool needpic) const
{
return code;
}
// Try converting lowercase characters to uppercase.
if (myislower(code))
{
code = upperforlower[code];
if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].TranslatedPic != nullptr))
{
return code;
}
}
// Try stripping accents from accented characters.
int newcode = stripaccent(code);
if (newcode != code)
int originalcode = code;
int newcode;
// Try stripping accents from accented characters. This may repeat to allow multi-step fallbacks.
while ((newcode = stripaccent(code)) != code)
{
code = newcode;
if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].TranslatedPic != nullptr))
@ -1461,6 +1470,14 @@ int FFont::GetCharCode(int code, bool needpic) const
return code;
}
}
if (myislower(code))
{
int upper = upperforlower[code];
// Stripping accents did not help - now try uppercase for lowercase
if (upper != code) return GetCharCode(upper, needpic);
}
return -1;
}