diff options
author | crupest <crupest@outlook.com> | 2020-10-30 00:07:57 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-30 00:07:57 +0800 |
commit | 6aa2201797a9ed64ce0178215ae941d0c5f09579 (patch) | |
tree | 9a74ee8d9f616afbe693ef7825a71474850831b5 /include/cru/win/graphics/direct/TextLayout.hpp | |
parent | b4cb4fb7552d35c267bdb66913e4c822f16346ab (diff) | |
download | cru-6aa2201797a9ed64ce0178215ae941d0c5f09579.tar.gz cru-6aa2201797a9ed64ce0178215ae941d0c5f09579.tar.bz2 cru-6aa2201797a9ed64ce0178215ae941d0c5f09579.zip |
...
Diffstat (limited to 'include/cru/win/graphics/direct/TextLayout.hpp')
-rw-r--r-- | include/cru/win/graphics/direct/TextLayout.hpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/include/cru/win/graphics/direct/TextLayout.hpp b/include/cru/win/graphics/direct/TextLayout.hpp new file mode 100644 index 00000000..3320431f --- /dev/null +++ b/include/cru/win/graphics/direct/TextLayout.hpp @@ -0,0 +1,55 @@ +#pragma once +#include "ComResource.hpp" +#include "Resource.hpp" + +#include "cru/platform/graphics/TextLayout.hpp" + +#include <limits> +#include <memory> + +namespace cru::platform::graphics::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::u16string text); + + CRU_DELETE_COPY(DWriteTextLayout) + CRU_DELETE_MOVE(DWriteTextLayout) + + ~DWriteTextLayout() override; + + public: + IDWriteTextLayout* GetComInterface() const override { + return text_layout_.Get(); + } + + public: + std::u16string GetText() override; + std::u16string_view GetTextView() override; + void SetText(std::u16string 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(Index position, bool trailing) override; + TextHitTestResult HitTest(const Point& point) override; + + private: + std::u16string text_; + std::shared_ptr<DWriteFont> font_; + float max_width_ = std::numeric_limits<float>::max(); + float max_height_ = std::numeric_limits<float>::max(); + Microsoft::WRL::ComPtr<IDWriteTextLayout> text_layout_; +}; +} // namespace cru::platform::graphics::win::direct |