Using NSLayoutManager to calculate frames for each glyph

吃可爱长大的小学妹 提交于 2019-12-03 10:39:27
ugiflezet

I've found a solution for this issue or at least sort of

Problem: boundingRectForGlyphRange results is off in case of RTL text.

So in case of RTL text is detected only:

Using NSLayoutManager method locationForGlyphAtIndex, for each letter in the range. These are the starting points of each glyph in the range. Using these points I adjust the boundingRect correctly.

Here is an outline of it:

CGPoint endPoint = ((NSValue *)pointsOfGlyps.firstObject).CGPointValue;
CGPoint startPoint = ((NSValue *)pointsOfGlyps.lastObject).CGPointValue;
boundingRect.origin.x =  startPoint.x;
boundingRect.size.width = endPoint.x - startPoint.x + letterWidth;

letterWidth is an approximation of a letter width calculated as the delta between two consecutive starting points.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!