Trim unsupported unicode for now, since they mess with input

develop
kaetemi 4 years ago
parent 3b6e27e800
commit bb564a6302

@ -146,8 +146,10 @@ void CFontManager::computeString (NLMISC::CUtfStringView sv,
{ {
// Creating font // Creating font
k.Char = *it; k.Char = *it;
if (k.Char < 0x20) if (k.Char < 0x20) // Control Characters
k.Char += 0x2400; k.Char += 0x2400;
if (k.Char == 0x7F) // DEL
k.Char = 0x2421;
k.FontGenerator = fontGen; k.FontGenerator = fontGen;
k.Size = fontSize; k.Size = fontSize;
k.Embolden = embolden; k.Embolden = embolden;

@ -54,6 +54,36 @@ namespace NLGUI
CGroupEditBox *CGroupEditBox::_MenuFather = NULL; CGroupEditBox *CGroupEditBox::_MenuFather = NULL;
CGroupEditBox::IComboKeyHandler* CGroupEditBox::comboKeyHandler = NULL; CGroupEditBox::IComboKeyHandler* CGroupEditBox::comboKeyHandler = NULL;
// For now, just trim unsupported codepoints to make emoji fallback to text form
static bool supportedCodepoint(u32char c)
{
if (c >= 0xFE00 && c < 0xFE10)
return false; // Variation Selectors
else if (c >= 0xE0100 && c < 0xE01F0)
return false; // Variation Selectors Supplement
else if (c >= 0x200B && c < 0x2010)
return false; // ZERO WIDTH JOINER, etcetera
else if (c >= 0x2028 && c < 0x202F)
return false; // PARAGRAPH SEPARATOR, etcetera
else if (c >= 0x2060 && c < 0x2070)
return false; // WORD JOINER, etcetera
else if (c == 0xFEFF)
return false; // BOM
return true;
}
// For now, just trim unsupported codepoints to make emoji fallback to text form
static ::u32string trimUnsupported(const ::u32string str)
{
::u32string res;
res.reserve(str.size());
for (::u32string::const_iterator it(str.begin()), end(str.end()); it != end; ++it)
{
if (supportedCodepoint(*it))
res.push_back(*it);
}
return res;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
NLMISC_REGISTER_OBJECT(CViewBase, CGroupEditBox, std::string, "edit_box"); NLMISC_REGISTER_OBJECT(CViewBase, CGroupEditBox, std::string, "edit_box");
@ -850,7 +880,8 @@ namespace NLGUI
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void CGroupEditBox::writeString(const std::string &str16, bool replace, bool atEnd) void CGroupEditBox::writeString(const std::string &str16, bool replace, bool atEnd)
{ {
::u32string str = CUtfStringView(str16).toUtf32(); // For now, just trim unsupported codepoints to make emoji fallback to text form
::u32string str = trimUnsupported(CUtfStringView(str16).toUtf32());
sint length = (sint)str.length(); sint length = (sint)str.length();
::u32string toAppend; ::u32string toAppend;
@ -1111,6 +1142,7 @@ namespace NLGUI
u32char c = isKeyRETURN ? '\n' : rEDK.getChar(); u32char c = isKeyRETURN ? '\n' : rEDK.getChar();
if (isFiltered(c)) return; if (isFiltered(c)) return;
if (!supportedCodepoint(c)) return; // For now, just trim unsupported codepoints to make emoji fallback to text form
switch(_EntryType) switch(_EntryType)
{ {
case Integer: case Integer:

Loading…
Cancel
Save