aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-09-06 11:52:21 +0800
committercrupest <crupest@outlook.com>2021-09-06 11:52:21 +0800
commit16007714fc0ad365c6da52dc58201ba4bc6aa964 (patch)
tree7ce745b2ab79f6ae057d03c18b875a3661eeca1f
parentc504aef3835f71ea22c9e938066f01e69e1c2db3 (diff)
downloadcru-16007714fc0ad365c6da52dc58201ba4bc6aa964.tar.gz
cru-16007714fc0ad365c6da52dc58201ba4bc6aa964.tar.bz2
cru-16007714fc0ad365c6da52dc58201ba4bc6aa964.zip
...
-rw-r--r--include/cru/osx/graphics/quartz/TextLayout.hpp42
-rw-r--r--src/osx/graphics/quartz/CMakeLists.txt2
-rw-r--r--src/osx/graphics/quartz/Font.cpp15
-rw-r--r--src/osx/graphics/quartz/TextLayout.cpp5
-rw-r--r--src/parse/CMakeLists.txt0
5 files changed, 63 insertions, 1 deletions
diff --git a/include/cru/osx/graphics/quartz/TextLayout.hpp b/include/cru/osx/graphics/quartz/TextLayout.hpp
new file mode 100644
index 00000000..bfa2aee3
--- /dev/null
+++ b/include/cru/osx/graphics/quartz/TextLayout.hpp
@@ -0,0 +1,42 @@
+#pragma once
+#include <memory>
+#include "Resource.hpp"
+
+#include "Font.hpp"
+#include "cru/common/Base.hpp"
+#include "cru/platform/graphics/TextLayout.hpp"
+
+namespace cru::platform::graphics::osx::quartz {
+class OsxCTTextLayout : public OsxQuartzResource, public virtual ITextLayout {
+ public:
+ OsxCTTextLayout(IGraphFactory* graphics_factory,
+ std::shared_ptr<OsxCTFont> font, const String& str);
+
+ CRU_DELETE_COPY(OsxCTTextLayout)
+ CRU_DELETE_MOVE(OsxCTTextLayout)
+
+ ~OsxCTTextLayout() override;
+
+ 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(bool includingTrailingSpace = false) override;
+ std::vector<Rect> TextRangeRect(const TextRange& text_range) override;
+ Point TextSinglePoint(Index position, bool trailing) override;
+ TextHitTestResult HitTest(const Point& point) override;
+
+ private:
+ std::shared_ptr<OsxCTFont> font_;
+
+ CTFramesetterRef ct_framesetter_;
+ CTFrameRef ct_frame_;
+};
+} // namespace cru::platform::graphics::osx::quartz
diff --git a/src/osx/graphics/quartz/CMakeLists.txt b/src/osx/graphics/quartz/CMakeLists.txt
index d58b7ecc..c6bb29cb 100644
--- a/src/osx/graphics/quartz/CMakeLists.txt
+++ b/src/osx/graphics/quartz/CMakeLists.txt
@@ -8,6 +8,7 @@ add_library(cru_osx_graphics_quartz SHARED
Geometry.cpp
Painter.cpp
Resource.cpp
+ TextLayout.cpp
)
target_sources(cru_osx_graphics_quartz PUBLIC
${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Brush.hpp
@@ -17,6 +18,7 @@ target_sources(cru_osx_graphics_quartz PUBLIC
${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Geometry.hpp
${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Painter.hpp
${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Resource.hpp
+ ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/TextLayout.hpp
)
target_link_libraries(cru_osx_graphics_quartz PUBLIC cocoa)
target_link_libraries(cru_osx_graphics_quartz PUBLIC cru_osx_base cru_platform_graphics)
diff --git a/src/osx/graphics/quartz/Font.cpp b/src/osx/graphics/quartz/Font.cpp
index 15ef9b21..e6c1dc91 100644
--- a/src/osx/graphics/quartz/Font.cpp
+++ b/src/osx/graphics/quartz/Font.cpp
@@ -1,5 +1,18 @@
#include "cru/osx/graphics/quartz/Font.hpp"
+#include "cru/osx/graphics/quartz/Convert.hpp"
+#include "cru/osx/graphics/quartz/Resource.hpp"
+
namespace cru::platform::graphics::osx::quartz {
-
+OsxCTFont::OsxCTFont(IGraphFactory* graphics_factory, const String& name,
+ float size)
+ : OsxQuartzResource(graphics_factory) {
+ CFStringRef n = Convert(name);
+
+ ct_font_ = CTFontCreateWithName(n, size, nullptr);
+
+ CFRelease(n);
}
+
+OsxCTFont::~OsxCTFont() { CFRelease(ct_font_); }
+} // namespace cru::platform::graphics::osx::quartz
diff --git a/src/osx/graphics/quartz/TextLayout.cpp b/src/osx/graphics/quartz/TextLayout.cpp
new file mode 100644
index 00000000..bd0562cb
--- /dev/null
+++ b/src/osx/graphics/quartz/TextLayout.cpp
@@ -0,0 +1,5 @@
+#include "cru/osx/graphics/quartz/TextLayout.hpp"
+
+namespace cru::platform::graphics::osx::quartz {
+
+}
diff --git a/src/parse/CMakeLists.txt b/src/parse/CMakeLists.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/parse/CMakeLists.txt