aboutsummaryrefslogtreecommitdiff
path: root/src/win/graph/direct/font.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/win/graph/direct/font.cpp')
-rw-r--r--src/win/graph/direct/font.cpp20
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(