aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/osx/graphics/quartz/TextLayout.hpp1
-rw-r--r--src/osx/graphics/quartz/TextLayout.cpp16
2 files changed, 13 insertions, 4 deletions
diff --git a/include/cru/osx/graphics/quartz/TextLayout.hpp b/include/cru/osx/graphics/quartz/TextLayout.hpp
index 87932423..03b1b1cb 100644
--- a/include/cru/osx/graphics/quartz/TextLayout.hpp
+++ b/include/cru/osx/graphics/quartz/TextLayout.hpp
@@ -51,6 +51,7 @@ class OsxCTTextLayout : public OsxQuartzResource, public virtual ITextLayout {
CFMutableAttributedStringRef cf_attributed_text_;
CTFramesetterRef ct_framesetter_ = nullptr;
+ float suggest_height_;
CTFrameRef ct_frame_ = nullptr;
int line_count_;
std::vector<CGPoint> line_origins_;
diff --git a/src/osx/graphics/quartz/TextLayout.cpp b/src/osx/graphics/quartz/TextLayout.cpp
index 7ce03a5e..dd6b908d 100644
--- a/src/osx/graphics/quartz/TextLayout.cpp
+++ b/src/osx/graphics/quartz/TextLayout.cpp
@@ -198,9 +198,18 @@ void OsxCTTextLayout::RecreateFrame() {
CTFramesetterCreateWithAttributedString(cf_attributed_text_);
Ensures(ct_framesetter_);
+ CFRange fit_range;
+
+ suggest_height_ =
+ CTFramesetterSuggestFrameSizeWithConstraints(
+ ct_framesetter_,
+ CFRangeMake(0, CFAttributedStringGetLength(cf_attributed_text_)),
+ nullptr, CGSizeMake(max_width_, max_height_), &fit_range)
+ .height;
+
auto path = CGPathCreateMutable();
Ensures(path);
- CGPathAddRect(path, nullptr, CGRectMake(0, 0, max_width_, max_height_));
+ CGPathAddRect(path, nullptr, CGRectMake(0, 0, max_width_, suggest_height_));
CFMutableDictionaryRef dictionary =
CFDictionaryCreateMutable(nullptr, 0, &kCFTypeDictionaryKeyCallBacks,
@@ -228,7 +237,7 @@ void OsxCTTextLayout::RecreateFrame() {
CTFrameRef OsxCTTextLayout::CreateFrameWithColor(const Color& color) {
auto path = CGPathCreateMutable();
- CGPathAddRect(path, nullptr, CGRectMake(0, 0, max_width_, max_height_));
+ CGPathAddRect(path, nullptr, CGRectMake(0, 0, max_width_, suggest_height_));
CGColorRef cg_color =
CGColorCreateGenericRGB(color.GetFloatRed(), color.GetFloatGreen(),
@@ -241,11 +250,10 @@ CTFrameRef OsxCTTextLayout::CreateFrameWithColor(const Color& color) {
auto frame = CTFramesetterCreateFrame(
ct_framesetter_,
CFRangeMake(0, CFAttributedStringGetLength(cf_attributed_text_)), path,
- dictionary);
+ nullptr);
Ensures(frame);
CGPathRelease(path);
- CFRelease(dictionary);
return frame;
}