Simplified UTF-8 encoding procedure for X11 window title.

- Instead of first converting to a wide string and converting that to
  UTF-8, now convert to UTF-8 directly using sf::Utf32::toUtf8.
- Modify OS X sf::String to NSString helper to work for big-endian
  architectures (like OS X 10.5 on PowerPC) as well.
This commit is contained in:
Shiz 2013-02-12 17:44:01 +01:00
parent 6bc077688e
commit 9ba19e34a2
2 changed files with 14 additions and 3 deletions

View File

@ -322,9 +322,9 @@ void WindowImplX11::setTitle(const String& title)
// Convert to UTF-8 encoding. // Convert to UTF-8 encoding.
std::basic_string<sf::Uint8> utf8Title; std::basic_string<sf::Uint8> utf8Title;
std::wstring wideTitle = title.toWideString(); sf::Utf32::toUtf8(title.begin(), title.end(), std::back_inserter(utf8Title));
sf::Utf8::fromWide(wideTitle.begin(), wideTitle.end(), std::back_inserter(utf8Title));
// Set the _NET_WM_NAME atom, which specifies a UTF-8 encoded window title.
Atom wmName = XInternAtom(m_display, "_NET_WM_NAME", False); Atom wmName = XInternAtom(m_display, "_NET_WM_NAME", False);
Atom useUtf8 = XInternAtom(m_display, "UTF8_STRING", False); Atom useUtf8 = XInternAtom(m_display, "UTF8_STRING", False);
XChangeProperty(m_display, m_window, wmName, useUtf8, 8, XChangeProperty(m_display, m_window, wmName, useUtf8, 8,

View File

@ -28,6 +28,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/Utf.hpp> #include <SFML/System/Utf.hpp>
#import <Foundation/Foundation.h>
#import <SFML/Window/OSX/cpp_objc_conversion.h> #import <SFML/Window/OSX/cpp_objc_conversion.h>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -45,7 +46,17 @@ NSString* sfStringToNSString(sf::String const& string)
{ {
sf::Uint32 length = string.getSize() * sizeof(sf::Uint32); sf::Uint32 length = string.getSize() * sizeof(sf::Uint32);
const void* data = reinterpret_cast<const void*>(string.getData()); const void* data = reinterpret_cast<const void*>(string.getData());
NSString* str = [[NSString alloc] initWithBytes:data length:length encoding:NSUTF32LittleEndianStringEncoding];
NSStringEncoding sfEncoding;
if (NSHostByteOrder() == NS_LittleEndian)
{
sfEncoding = NSUTF32LittleEndianStringEncoding;
}
else
{
sfEncoding = NSUTF32BigEndianStringEncoding;
}
NSString* str = [[NSString alloc] initWithBytes:data length:length encoding:sfEncoding];
return str; return str;
} }