Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

[Apple Bug] TextKit's calculatedSize is not matching NSAttributedString for CJK languages. #1013

@binchensjtu

Description

@binchensjtu

I found that the height of calculatedSize in ASTextNode is incorrect for Chinese and Japanese.
The test code snippet as below:

NSString *text = @"你好";//Some Chinese characters
NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:17.0]};
ASTextNode *textNode = [[ASTextNode alloc] init];
textNode.attributedString = [[NSAttributedString alloc] initWithString:text attributes:attributes];

CGSize textSize1 = [textNode measure:constrainedSize];
CGSize textSize2 = [text sizeWithAttributes:attributes];

NSLog(@"textSize1: %@", NSStringFromCGSize(textSize1));
NSLog(@"textSize2: %@", NSStringFromCGSize(textSize2));

The output is:

textSize1: {34, 17}
textSize2: {34, 20.287109375}

Pure Chinese characters will lead to the issue. The bounds of text node is tight. The mix of Chinese and alphabets is correct.
The same problem to pure Japanese characters. Haven't test more languages.

The screenshot of pure Chinese character text node and mix character text node.

textnode

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions