aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-10-20 19:15:53 +0800
committercrupest <crupest@outlook.com>2021-10-20 19:15:53 +0800
commite0e786729df8114555fa3af9fffe256b067ea823 (patch)
treedd5fff0d1113be29c6647b3320f5404a9adce172 /src
parent3168b19e9ad1798d5b45c34b3f37ba496f5da66a (diff)
downloadcru-e0e786729df8114555fa3af9fffe256b067ea823.tar.gz
cru-e0e786729df8114555fa3af9fffe256b067ea823.tar.bz2
cru-e0e786729df8114555fa3af9fffe256b067ea823.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/osx/graphics/quartz/TextLayout.cpp16
1 files changed, 12 insertions, 4 deletions
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;
}