AsyncDisplayKit icon indicating copy to clipboard operation
AsyncDisplayKit copied to clipboard

[ASTextNode] italic text clipping bug

Open Yue-Wang-Google opened this issue 10 years ago • 11 comments

ASDK render graphic context (which text kit draws on) into a uiimage, and that may cause text to be clipped if it's outside of view's bounds.

For instance, the left side is clipped in the following italic text screen shot 2016-07-27 at 4 26 31 pm

Yue-Wang-Google avatar Jul 27 '16 23:07 Yue-Wang-Google

@Yue-Wang-Google On what version are you on? Is it master?

maicki avatar Jul 28 '16 17:07 maicki

The problem appears on all versions. it's on 1.9.8, and on an internal cut dated back from March. You can use any word start with italic "j" to reproduce the problem.

It's not a textnode specific problem. It's how ASDK render things internally --- The graphic context will be convert to a UIImage with the same size of the node, from which process it got clipped.

Yue-Wang-Google avatar Jul 28 '16 18:07 Yue-Wang-Google

@Yue-Wang-Google I built a reproduction case and it appears that the UIImage that ASDK generates is the same size (rounded to pixels up) as the size returned by usedRectForTextContainer: (called on NSLayoutManager). This is still obviously an issue, just trying to confirm that I'm working on the same bug you're reporting :)

garrettmoon avatar Aug 10 '16 20:08 garrettmoon

Specifically, NSLayoutManager is reporting an incorrect size for italicized text.

garrettmoon avatar Aug 10 '16 20:08 garrettmoon

yes. that's the bug I was reporting.

usedRectForTextContainer: does not do glyph generation. So I assume it can't be used to calculate image bounds, which is different from typographic bounds.

Yue-Wang-Google avatar Aug 10 '16 20:08 Yue-Wang-Google

Got it, thank you. We'll need to figure out another way to generate the image bounds.

garrettmoon avatar Aug 10 '16 23:08 garrettmoon

@Yue-Wang-Google the plot thickens: this is the exact same behavior of a UILabel even with clipsToBounds set to NO.

simulator screen shot aug 11 2016 10 30 07 am

Other's appear to attempt to workaround the issue in UILabel: http://stackoverflow.com/questions/20985085/uilabel-clipping-italic-oblique-text-at-left-and-right-edges-of-content-ios

garrettmoon avatar Aug 11 '16 17:08 garrettmoon

I bet this is a bug in NSLayoutManager, since this is drawing happening inside of it. Another one - is the height ascender/descender underestimation where NSLayoutManager actually returns the incorrect height (usually cutoff by half a point), as can be observed in #637

nlutsenko avatar Aug 11 '16 19:08 nlutsenko

This makes me think this #2000 may be necessary. I'll look into that to see if it can address the issue.

garrettmoon avatar Aug 11 '16 19:08 garrettmoon

@nlutsenko I'm not sure they perceive it as a bug – I think it's meant to return the sizing of a view for layout and alignment. The actual rendering may exceed its bounds.

garrettmoon avatar Aug 11 '16 19:08 garrettmoon

Resolved via #2062

Adlai-Holler avatar Aug 16 '16 18:08 Adlai-Holler