From 7351020a582d70a1495249fba87d342c8a1fb634 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 10 Apr 2019 19:42:46 +0800 Subject: Refactor. --- src/win/graph/win_font.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/win/graph/win_font.cpp (limited to 'src/win/graph/win_font.cpp') diff --git a/src/win/graph/win_font.cpp b/src/win/graph/win_font.cpp new file mode 100644 index 00000000..0eb5e6b2 --- /dev/null +++ b/src/win/graph/win_font.cpp @@ -0,0 +1,28 @@ +#include "cru/win/graph/win_font.hpp" + +#include "cru/win/exception.hpp" +#include "cru/win/graph/graph_manager.hpp" + +#include +#include +#include + +namespace cru::win::graph { +WinFontDescriptor::WinFontDescriptor(GraphManager* graph_manager, + const std::wstring_view& font_family, + float font_size) { + assert(graph_manager); + std::array buffer; + if (!::GetUserDefaultLocaleName(buffer.data(), buffer.size())) + throw Win32Error(::GetLastError(), "Failed to get locale."); + + ThrowIfFailed(graph_manager->GetDWriteFactory()->CreateTextFormat( + font_family.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( + text_format_->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER)); +} +} // namespace cru::win::graph -- cgit v1.2.3