diff options
author | crupest <crupest@outlook.com> | 2019-12-12 19:53:17 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-12-12 19:53:17 +0800 |
commit | e69911a8b161b81ce3f7b209175766da2b7b3d4b (patch) | |
tree | 76b1f4b6f9f5ad6111578771be783ee456aeb912 /src/win/graph/direct/font.cpp | |
parent | 154b5b838edfdcef93cd0a33c013ad7f5f9d7337 (diff) | |
download | cru-e69911a8b161b81ce3f7b209175766da2b7b3d4b.tar.gz cru-e69911a8b161b81ce3f7b209175766da2b7b3d4b.tar.bz2 cru-e69911a8b161b81ce3f7b209175766da2b7b3d4b.zip |
...
Diffstat (limited to 'src/win/graph/direct/font.cpp')
-rw-r--r-- | src/win/graph/direct/font.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/win/graph/direct/font.cpp b/src/win/graph/direct/font.cpp index 5d7b4483..8e881f84 100644 --- a/src/win/graph/direct/font.cpp +++ b/src/win/graph/direct/font.cpp @@ -1,25 +1,29 @@ #include "cru/win/graph/direct/font.hpp" -#include "cru/win/exception.hpp" #include "cru/win/graph/direct/exception.hpp" +#include "cru/win/graph/direct/factory.hpp" +#include "cru/win/string.hpp" #include <array> #include <cassert> #include <utility> namespace cru::platform::graph::win::direct { -DWriteFont::DWriteFont(IDirectFactory* factory, - const std::wstring_view& font_family, float font_size) { - assert(factory); +DWriteFont::DWriteFont(DirectGraphFactory* factory, + const std::string_view& font_family, float font_size) + : DirectGraphResource(factory) { + // Get locale std::array<wchar_t, LOCALE_NAME_MAX_LENGTH> buffer; if (!::GetUserDefaultLocaleName(buffer.data(), static_cast<int>(buffer.size()))) - throw platform::win::Win32Error(::GetLastError(), "Failed to get locale."); + throw platform::win::Win32Error( + ::GetLastError(), "Failed to get locale when create dwrite font."); + + const std::wstring&& wff = cru::platform::win::ToUtf16String(font_family); ThrowIfFailed(factory->GetDWriteFactory()->CreateTextFormat( - font_family.data(), nullptr, DWRITE_FONT_WEIGHT_NORMAL, - DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, font_size, - buffer.data(), &text_format_)); + wff.data(), nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, + DWRITE_FONT_STRETCH_NORMAL, font_size, buffer.data(), &text_format_)); ThrowIfFailed(text_format_->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER)); ThrowIfFailed( |