microsoft / DirectXTK12

The DirectX Tool Kit (aka DirectXTK12) is a collection of helper classes for writing DirectX 12 code in C++
https://walbourn.github.io/directx-tool-kit-for-directx-12/
MIT License
1.47k stars 393 forks source link

SpriteFont should support UTF-8 strings #45

Closed walbourn closed 5 years ago

walbourn commented 5 years ago

There is momentum to adopting UTF-8 Everywhere which currently makes a it a little difficult to work with SpriteFont that uses wchar_t. The library should be updated with DrawString, MeasureString, and MeasureDrawBounds overloads that take char assuming it's UTF-8 (not ASCII or some other codepage).

walbourn commented 5 years ago

For now the workaround is to do the conversion in your app:

wchar_t temp[1024] = {};
int result = MultiByteToWideChar(CP_UTF8, 0, char-string, -1, temp, _countof(temp));
if (!result)
    throw std::exception("MultiByteToWideChar"):

// Use temp to call SpriteFont->DrawString
walbourn commented 5 years ago

Fixed in this pull request