aboutsummaryrefslogtreecommitdiff
path: root/include/cru/win/graph/direct/TextLayout.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/win/graph/direct/TextLayout.hpp')
-rw-r--r--include/cru/win/graph/direct/TextLayout.hpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/include/cru/win/graph/direct/TextLayout.hpp b/include/cru/win/graph/direct/TextLayout.hpp
new file mode 100644
index 00000000..1a378ed4
--- /dev/null
+++ b/include/cru/win/graph/direct/TextLayout.hpp
@@ -0,0 +1,54 @@
+#pragma once
+#include "ComResource.hpp"
+#include "Resource.hpp"
+
+#include "cru/platform/graph/TextLayout.hpp"
+
+#include <memory>
+
+namespace cru::platform::graph::win::direct {
+class DWriteFont;
+
+class DWriteTextLayout : public DirectGraphResource,
+ public virtual ITextLayout,
+ public virtual IComResource<IDWriteTextLayout> {
+ public:
+ DWriteTextLayout(DirectGraphFactory* factory, std::shared_ptr<IFont> font,
+ std::string text);
+
+ CRU_DELETE_COPY(DWriteTextLayout)
+ CRU_DELETE_MOVE(DWriteTextLayout)
+
+ ~DWriteTextLayout() override;
+
+ public:
+ IDWriteTextLayout* GetComInterface() const override {
+ return text_layout_.Get();
+ }
+
+ public:
+ std::string GetText() override;
+ void SetText(std::string new_text) override;
+
+ std::shared_ptr<IFont> GetFont() override;
+ void SetFont(std::shared_ptr<IFont> font) override;
+
+ void SetMaxWidth(float max_width) override;
+ void SetMaxHeight(float max_height) override;
+
+ Rect GetTextBounds() override;
+ // Return empty vector if text_range.count is 0. Text range could be in
+ // reverse direction, it should be normalized first in implementation.
+ std::vector<Rect> TextRangeRect(const TextRange& text_range) override;
+ Point TextSinglePoint(gsl::index position, bool trailing) override;
+ TextHitTestResult HitTest(const Point& point) override;
+
+ private:
+ std::string text_;
+ std::wstring w_text_;
+ std::shared_ptr<DWriteFont> font_;
+ float max_width_ = 10000.0f;
+ float max_height_ = 10000.0f;
+ Microsoft::WRL::ComPtr<IDWriteTextLayout> text_layout_;
+};
+} // namespace cru::platform::graph::win::direct