Re: NSAttributedString + NSLayoutManager versus Core Text

Graham Cox

OK, as usual after writing a lengthy question, it helps focus the mind on what’s really going on, and minutes later the solution materialises.

NSTextContainer has a property called lineFragmentPadding. For some inexplicable reason, this value defaults to 5, rather than 0. Why 5 would be what you want I can’t think, but setting it to 0 solves my problem.

Still, if anyone’s in the mood to offer a Core Text solution to this overall problem, I’d be happy to hear it.


On 23 Nov 2019, at 12:11 pm, Graham Cox <graham@...> wrote:

However, the way NSAttributedString actually draws is strange - text is always offset to the right of the origin of the rectangle that you want to draw it into. It’s only a few pixels, but it’s more than enough to misplace the text especially with small font sizes. The offset seems to vary with font also. Because the text container has the size of the rectangle, this offset means that text is typically clipped or wrapped by the right edge when it should not be, because the whole string was drawn too far right. I can fudge the origin, but then I change the font and those numbers are wrong.

Join to automatically receive all group messages.