Unicode characters outside the BMP (> 0xFFFF) are now correctly handled on Windows (#366)

This commit is contained in:
Laurent Gomila 2013-05-16 23:38:28 +02:00
parent 11837e9fc8
commit 83ffe11709
2 changed files with 32 additions and 6 deletions

View File

@ -73,7 +73,8 @@ m_icon (NULL),
m_keyRepeatEnabled(true), m_keyRepeatEnabled(true),
m_isCursorIn (false), m_isCursorIn (false),
m_lastSize (0, 0), m_lastSize (0, 0),
m_resizing (false) m_resizing (false),
m_surrogate (0)
{ {
if (m_handle) if (m_handle)
{ {
@ -93,7 +94,8 @@ m_icon (NULL),
m_keyRepeatEnabled(true), m_keyRepeatEnabled(true),
m_isCursorIn (false), m_isCursorIn (false),
m_lastSize (mode.width, mode.height), m_lastSize (mode.width, mode.height),
m_resizing (false) m_resizing (false),
m_surrogate (0)
{ {
// Register the window class at first call // Register the window class at first call
if (windowCount == 0) if (windowCount == 0)
@ -510,10 +512,33 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
{ {
if (m_keyRepeatEnabled || ((lParam & (1 << 30)) == 0)) if (m_keyRepeatEnabled || ((lParam & (1 << 30)) == 0))
{ {
Event event; // Get the code of the typed character
event.type = Event::TextEntered; Uint32 character = static_cast<Uint32>(wParam);
event.text.unicode = static_cast<Uint32>(wParam);
pushEvent(event); // Check if it is the first part of a surrogate pair, or a regular character
if ((character >= 0xD800) && (character <= 0xDBFF))
{
// First part of a surrogate pair: store it and wait for the second one
m_surrogate = static_cast<Uint16>(character);
}
else
{
// Check if it is the second part of a surrogate pair, or a regular character
if ((character >= 0xDC00) && (character <= 0xDFFF))
{
// Convert the UTF-16 surrogate pair to a single UTF-32 value
Uint16 utf16[] = {m_surrogate, static_cast<Uint16>(character)};
sf::Utf16::toUtf32(utf16, utf16 + 2, &character);
m_surrogate = 0;
}
// Send a TextEntered event
Event event;
event.type = Event::TextEntered;
event.text.unicode = character;
pushEvent(event);
}
} }
break; break;
} }

View File

@ -238,6 +238,7 @@ private :
bool m_isCursorIn; ///< Is the mouse cursor in the window's area ? bool m_isCursorIn; ///< Is the mouse cursor in the window's area ?
Vector2u m_lastSize; ///< The last handled size of the window Vector2u m_lastSize; ///< The last handled size of the window
bool m_resizing; ///< Is the window being resized ? bool m_resizing; ///< Is the window being resized ?
Uint16 m_surrogate; ///< First half of the surrogate pair, in case we're receiving a Unicode character in two events
}; };
} // namespace priv } // namespace priv