You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ji...@apache.org on 2019/12/11 12:21:49 UTC

[incubator-weex] branch master updated: [iOS] Fix text italic width not sufficient.

This is an automated email from the ASF dual-hosted git repository.

jianhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new d5fadaf  [iOS] Fix text italic width not sufficient.
     new 0cb851f  Merge pull request #3074 from wqyfavor/fix-italic
d5fadaf is described below

commit d5fadaf1f01021b9176c5cd0438363eb3d7ec9bd
Author: qianyuan.wqy <qi...@taobao.com>
AuthorDate: Wed Dec 11 19:28:22 2019 +0800

    [iOS] Fix text italic width not sufficient.
---
 ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
index c937680..27538dc 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
@@ -1042,9 +1042,14 @@ do {\
     }
     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);