aboutsummaryrefslogtreecommitdiff
path: root/src/osx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-09-07 14:52:09 +0800
committercrupest <crupest@outlook.com>2021-09-07 14:52:09 +0800
commit700751108257a00ab1a6134fe0ca570acb3269a8 (patch)
tree76fe84ae85680e33e3e54c90eb35f67f8106e863 /src/osx
parentbd44f9bc59c7fc2a8d2715d23368926aef5c5c32 (diff)
downloadcru-700751108257a00ab1a6134fe0ca570acb3269a8.tar.gz
cru-700751108257a00ab1a6134fe0ca570acb3269a8.tar.bz2
cru-700751108257a00ab1a6134fe0ca570acb3269a8.zip
...
Diffstat (limited to 'src/osx')
-rw-r--r--src/osx/graphics/quartz/TextLayout.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/osx/graphics/quartz/TextLayout.cpp b/src/osx/graphics/quartz/TextLayout.cpp
index 6b183fa7..08495634 100644
--- a/src/osx/graphics/quartz/TextLayout.cpp
+++ b/src/osx/graphics/quartz/TextLayout.cpp
@@ -1,6 +1,7 @@
#include "cru/osx/graphics/quartz/TextLayout.hpp"
#include "cru/osx/graphics/quartz/Convert.hpp"
#include "cru/osx/graphics/quartz/Resource.hpp"
+#include "cru/platform/Check.hpp"
namespace cru::platform::graphics::osx::quartz {
OsxCTTextLayout::OsxCTTextLayout(IGraphFactory* graphics_factory,
@@ -16,13 +17,48 @@ OsxCTTextLayout::OsxCTTextLayout(IGraphFactory* graphics_factory,
RecreateFrame();
}
+void OsxCTTextLayout::SetFont(std::shared_ptr<IFont> font) {
+ font_ = CheckPlatform<OsxCTFont>(font, GetPlatformId());
+ CFRelease(ct_framesetter_);
+ CFRelease(ct_frame_);
+ RecreateFrame();
+}
+
void OsxCTTextLayout::SetText(String new_text) {
text_ = std::move(new_text);
CFRelease(cf_text_);
cf_text_ = Convert(text_);
+ CFRelease(ct_framesetter_);
+ CFRelease(ct_frame_);
+ RecreateFrame();
+}
+
+void OsxCTTextLayout::SetMaxWidth(float max_width) {
+ max_width_ = max_width;
+ CFRelease(ct_framesetter_);
+ CFRelease(ct_frame_);
+ RecreateFrame();
+}
+
+void OsxCTTextLayout::SetMaxHeight(float max_height) {
+ max_height_ = max_height;
+ CFRelease(ct_framesetter_);
+ CFRelease(ct_frame_);
RecreateFrame();
}
+Rect OsxCTTextLayout::GetTextBounds(bool includingTrailingSpace) {
+ auto lines = CTFrameGetLines(ct_frame_);
+
+ const auto line_count = CFArrayGetCount(lines);
+
+ for (int i = 0; i < line_count; i++) {
+ auto line = CFArrayGetValueAtIndex(lines, i);
+
+ // TODO: To be continued!
+ }
+}
+
void OsxCTTextLayout::RecreateFrame() {
auto attributed_string = CFAttributedStringCreateMutable(nullptr, 0);
CFAttributedStringReplaceString(attributed_string, CFRangeMake(0, 0),