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

ASTextNode sizing issue for CJK language(caused by TextKit bug, and there's a quick fix) #2894

Closed
yxztj opened this issue Jan 13, 2017 · 2 comments
Labels

Comments

@yxztj
Copy link
Contributor

yxztj commented Jan 13, 2017

This should be a TextKit bug, based on which ASTextNode is built.

To repro:

  1. add a simple UILabel and a ASTextNode
  2. fill them with the same attributedString
  3. overlap each other and see if them coincide, which they should

Repro

(I've created a sample project, render the string is UILabel in blue and ASTextNode in black. Each view has a border with the same color as their content)
Everything looks good for English:
screen shot 2017-01-13 at 9 42 49 am
The UILabel and ASTextNode coincide completely. Since the black ASTextNode is drawn upon the blue UILabel, we can barely see the latter one.

When it comes to Chinese, we can see that the 2 strings don't fully coincide. The blue one goes a little bit down, and has a larger frame than black one.
screen shot 2017-01-13 at 9 39 44 am

The same goes for Korean:
screen shot 2017-01-13 at 9 39 24 am

The black frame is 6pt short in height if you print in console, while the height of blue frame exactly matches lineHeight property of the font. So the black frame is wrong, seems it incorrectly matches the pointSize of the font.
For English string, both blue and black frame matches lineHeight of the font.

Quick Fix

Fortunately if you add a "useless" line of code right after [_textStorage addLayoutManager] in ASTextKitContext.mm, all issues go away:

[_textStorage setAttributedString:attributedString];

_testStorage should have just been initialized with the attributedString provided, so setting the same string again should be useless. But it does magically fix the sizing issue:
screen shot 2017-01-13 at 9 55 27 am

Sadly Apple has been ignoring my bug report for months.

Also the issue looks very similar to #1013 , hope the fix also applies to that.
Please let me know if you need any additional information, or you prefer a PR.

@appleguy
Copy link
Contributor

@yxztj thanks for the sample project and the fix! I'm really surprised this actually makes a difference, but it looks like your new implementation is strictly better / more correct if there is some kind of undocumented order-of-operations dependency in the Apple frameworks about this.

It's great to have this issue linked directly in the source code, as it provides a concise summary of why the code structure is important to maintain.

@yxztj
Copy link
Contributor Author

yxztj commented Feb 16, 2017

@appleguy Thanks. Yes I guess the order of execution matters when displaying CJK languages.

Since #3026 has been merged, I'm closing it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants