From e0e786729df8114555fa3af9fffe256b067ea823 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 20 Oct 2021 19:15:53 +0800 Subject: ... --- src/osx/graphics/quartz/TextLayout.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/osx/graphics/quartz/TextLayout.cpp') 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; } -- cgit v1.2.3