From e69911a8b161b81ce3f7b209175766da2b7b3d4b Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 12 Dec 2019 19:53:17 +0800 Subject: ... --- src/win/graph/direct/text_layout.cpp | 47 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'src/win/graph/direct/text_layout.cpp') diff --git a/src/win/graph/direct/text_layout.cpp b/src/win/graph/direct/text_layout.cpp index 23a14b2a..a1750799 100644 --- a/src/win/graph/direct/text_layout.cpp +++ b/src/win/graph/direct/text_layout.cpp @@ -1,46 +1,49 @@ #include "cru/win/graph/direct/text_layout.hpp" +#include "cru/platform/check.hpp" #include "cru/win/graph/direct/exception.hpp" +#include "cru/win/graph/direct/factory.hpp" +#include "cru/win/graph/direct/font.hpp" +#include "cru/win/string.hpp" #include #include namespace cru::platform::graph::win::direct { -DWriteTextLayout::DWriteTextLayout(IDirectFactory* factory, - std::shared_ptr font, - std::wstring text) - : text_(std::move(text)) { - assert(factory); +DWriteTextLayout::DWriteTextLayout(DirectGraphFactory* factory, + std::shared_ptr font, + std::string text) + : DirectGraphResource(factory), text_(std::move(text)) { assert(font); - assert(IsDirectResource(font.get())); - factory_ = factory; - font_ = std::static_pointer_cast(font); + font_ = CheckPlatform(font, GetPlatformId()); + + w_text_ = cru::platform::win::ToUtf16String(text_); ThrowIfFailed(factory->GetDWriteFactory()->CreateTextLayout( - text_.c_str(), static_cast(text_.size()), + w_text_.c_str(), static_cast(w_text_.size()), font_->GetComInterface(), max_width_, max_height_, &text_layout_)); } -std::wstring DWriteTextLayout::GetText() { return text_; } +DWriteTextLayout::~DWriteTextLayout() = default; + +std::string DWriteTextLayout::GetText() { return text_; } -void DWriteTextLayout::SetText(std::wstring new_text) { +void DWriteTextLayout::SetText(std::string new_text) { text_.swap(new_text); - ThrowIfFailed(factory_->GetDWriteFactory()->CreateTextLayout( - text_.c_str(), static_cast(text_.size()), + w_text_ = cru::platform::win::ToUtf16String(text_); + ThrowIfFailed(GetDirectFactory()->GetDWriteFactory()->CreateTextLayout( + w_text_.c_str(), static_cast(w_text_.size()), font_->GetComInterface(), max_width_, max_height_, &text_layout_)); } -std::shared_ptr DWriteTextLayout::GetFont() { - return std::static_pointer_cast(font_); +std::shared_ptr DWriteTextLayout::GetFont() { + return std::dynamic_pointer_cast(font_); } -void DWriteTextLayout::SetFont(std::shared_ptr font) { - assert(IsDirectResource(font.get())); - auto f = std::static_pointer_cast(font); - - f.swap(font_); - ThrowIfFailed(factory_->GetDWriteFactory()->CreateTextLayout( - text_.c_str(), static_cast(text_.size()), +void DWriteTextLayout::SetFont(std::shared_ptr font) { + font_ = CheckPlatform(font, GetPlatformId()); + ThrowIfFailed(GetDirectFactory()->GetDWriteFactory()->CreateTextLayout( + w_text_.c_str(), static_cast(w_text_.size()), font_->GetComInterface(), max_width_, max_height_, &text_layout_)); } -- cgit v1.2.3