From 7b2a90be0d80e69ed94137f4a0b885898e8bbb99 Mon Sep 17 00:00:00 2001 From: John Tsai Date: Wed, 17 May 2023 14:57:31 +0800 Subject: [PATCH] Fix text padding (#399) * refactor: kCTLineBoundsIncludeLanguageExtents lead text padding too much replace with origin implement * refactor: use CTLineGetBoundsWithOptions function to implement text width calculate --- GaiaXiOS/GaiaXiOS/Component/Node/GXTextNode.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/GaiaXiOS/GaiaXiOS/Component/Node/GXTextNode.m b/GaiaXiOS/GaiaXiOS/Component/Node/GXTextNode.m index 5cee1d450..3840a2396 100644 --- a/GaiaXiOS/GaiaXiOS/Component/Node/GXTextNode.m +++ b/GaiaXiOS/GaiaXiOS/Component/Node/GXTextNode.m @@ -452,8 +452,10 @@ - (CGSize)labelSizeForFont:(UIFont *)font // 等于1行时,动态计算宽度 CTLineRef lineRef = (__bridge CTLineRef)[linesRef firstObject]; // 通过kCTLineBoundsIncludeLanguageExtents来确保不同的语言都有足够的空间 - CGRect rect = CTLineGetBoundsWithOptions(lineRef, kCTLineBoundsIncludeLanguageExtents); - width = rect.size.width; + CGRect rect = CTLineGetBoundsWithOptions(lineRef, + kCTLineBoundsExcludeTypographicLeading| + kCTLineBoundsExcludeTypographicShifts); + width = rect.size.width; } else { // 大于1行时,行宽直接用最大宽度 width = maxWidth;