Using NSLayoutManager to calculate frames for each character

In this thread, Core Text calculates the letter frame in iOS , they were able to accurately calculate the frame of each glyph using Core Text. The final bulges embrace perfectly drawn glyphs.

Using NSLayoutManager boundingRectForGlyphRange:inTextContainer: doesn't seem to return the boundingRectForGlyphRange:inTextContainer: glyphs, which are exactly:

glyph frames using boundingRectForGlyphRange: inTextContainer

And the returned rectangles do not fully cover the more complex fonts (Zapfino example):

Zapfino f glyph using boundingRectForGlyphRange: inTextContainer

Does anyone know how to replicate the results of the above discussion without going into Core Text in iOS 7 apps?

Thank.

+14
iphone ios7 ipad glyph nslayoutmanager
Feb 13 '14 at 19:59
source share
2 answers

I found a solution to this problem, or at least a kind

Problem: boundingRectForGlyphRange results are disabled in the case of RTL text.

Thus, in the case of an RTL text, only:

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

Here is his diagram:

 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 the approximate width of a letter, calculated as a delta between two consecutive starting points.

+1
Aug 21 '14 at 16:36
source share
— -

The selected answer in the message you are linking to apparently solves this problem for Zapfino .

0
Aug 14 '14 at 16:03
source share



All Articles