Skip to content

Commit

Permalink
Merge pull request #375 from JohnTsaii/fix_#365
Browse files Browse the repository at this point in the history
fix #365
  • Loading branch information
jingcheng1988 authored Apr 14, 2023
2 parents 880b023 + 9bc6eee commit 8ae4ae7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions GaiaXiOS/GaiaXiOS/Component/Node/GXTextNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,9 @@ - (CGSize)labelSizeForFont:(UIFont *)font
} else if (lineNum == 1) {
// 等于1行时,动态计算宽度
CTLineRef lineRef = (__bridge CTLineRef)[linesRef firstObject];
width = CTLineGetTypographicBounds(lineRef, NULL, NULL, NULL);

// 通过kCTLineBoundsIncludeLanguageExtents来确保不同的语言都有足够的空间
CGRect rect = CTLineGetBoundsWithOptions(lineRef, kCTLineBoundsIncludeLanguageExtents);
width = rect.size.width;
} else {
// 大于1行时,行宽直接用最大宽度
width = maxWidth;
Expand Down Expand Up @@ -503,9 +504,7 @@ - (CGSize)labelSizeForFont:(UIFont *)font
//增加段落 & font属性
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
[attrStr addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, text.length)];
[attrStr addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, text.length)];

[attrStr addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, text.length)];
// 计算FrameRef
CTFramesetterRef frameSetterRef = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)attrStr);
CGMutablePathRef pathRef = CGPathCreateMutable();
Expand Down

0 comments on commit 8ae4ae7

Please sign in to comment.