Skip to content

Commit

Permalink
[iOS] Fix text italic width not sufficient.
Browse files Browse the repository at this point in the history
  • Loading branch information
qianyuan.wqy committed Dec 11, 2019
1 parent 0ea76d5 commit d5fadaf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,14 @@ - (CGSize)calculateTextHeightWithWidth:(CGFloat)aWidth
}
aWidth = [attributedStringCpy boundingRectWithSize:CGSizeMake(aWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size.width;

/* If font style is italic, we add a little extra width to text.
About textSize * tanf(16deg) / 2
*/
CGFloat italicFix = _fontStyle == WXTextStyleItalic ? _fontSize * tanf(16 * (CGFloat)M_PI / 180) / 2.0f : 0.f;

/* Must get ceil of aWidth. Or core text may not return correct bounds.
Maybe aWidth without ceiling triggered some critical conditions. */
aWidth = ceil(aWidth);
aWidth = ceil(aWidth + italicFix);
CTFramesetterRef ctframesetterRef = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(attributedStringCpy));
suggestSize = CTFramesetterSuggestFrameSizeWithConstraints(ctframesetterRef, CFRangeMake(0, 0), NULL, CGSizeMake(aWidth, MAXFLOAT), NULL);

Expand Down

0 comments on commit d5fadaf

Please sign in to comment.