Bugfix/text trunctaion for textnode2#553
Bugfix/text trunctaion for textnode2#553wsdwsd0829 wants to merge 3 commits intoTextureGroup:masterfrom
Conversation
Generated by 🚫 Danger |
Adlai-Holler
left a comment
There was a problem hiding this comment.
I don't believe this is the right fix. Review the comments a few lines up – CoreText will not always return a container size that exactly matches our constrained size, so we need to treat the "gap" there as a range.
Later another narrower width constraint size is tried for same text. This should trigger an new layout calculation while previous cached is sized returned instead
We will only return the previous cached result if the second constrained size falls between the prior constrained size and the value returned by CoreText. So a remeasurement will result in the same value.
What am I not seeing here?
|
Hi I made a sample to reproduce the problem. |
|
@Adlai-Holler @wsdwsd0829 Please follow up on this. Thanks! |
|
@wsdwsd0829 This diff was actually landed incidentally in #918. I've created a followup fix that retains the correctness win but reduces the performance impact. Sorry for taking so long to really dig into this! |

[ASTextLayout layoutWithContainer:container text:text]; is called for same text with different container size for a complete layout pass.
The existing caching mechanism is over confident.
For example "A long string that happened to fit whole screen” is set as layout result when container is full screen size on first round.
Later another narrower width constraint size is tried for same text. This should trigger an new layout calculation while previous cached is sized returned instead;
This fix will only return cached result only when constraint size are same for different layouts.
Another side notes: the truncations rules are remove the last word that caused truncation and apply “…” to the previous word of that word; (This make sense in case last word is less than 2 chars which will cause “…” overflow.) The downside however is that if the last word is long and removed, the result rendered would look much shorter then expected.