mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
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:
parent
6bc077688e
commit
9ba19e34a2
@ -322,9 +322,9 @@ void WindowImplX11::setTitle(const String& title)
|
||||
|
||||
// Convert to UTF-8 encoding.
|
||||
std::basic_string<sf::Uint8> utf8Title;
|
||||
std::wstring wideTitle = title.toWideString();
|
||||
sf::Utf8::fromWide(wideTitle.begin(), wideTitle.end(), std::back_inserter(utf8Title));
|
||||
sf::Utf32::toUtf8(title.begin(), title.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 useUtf8 = XInternAtom(m_display, "UTF8_STRING", False);
|
||||
XChangeProperty(m_display, m_window, wmName, useUtf8, 8,
|
||||
|
@ -28,6 +28,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Utf.hpp>
|
||||
|
||||
#import <Foundation/Foundation.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);
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user