Get bounding box for CGGlyphs characters except letters or numbers

I am looking for a way to align a character as shown in the picture:

enter image description here

The method should work for any given character (or at least all common Unicode characters).

Here is my actual approach (in Swift, inspired by this and this question):

let char = "a" let ctFont = CTFontCreateWithNameAndOptions("HelveticaNeue", 12, nil, nil) var ctGlyph = CTFontGetGlyphWithName(ctFont, char) let boundingBox = withUnsafePointer(&ctGlyph) { pointer -> CGRect in return CTFontGetBoundingRectsForGlyphs(ctFont, CTFontOrientation.OrientationDefault, pointer, nil, 1) } 

The descent I need is just -boundingBox.origin.y . This approach works well for alphabetic, numeric, and numeric characters (see this answer for a graphical representation).

The problem is that for all other letters or numbers (for example: .,#')* ) I get the same bounding box: {x:0.612, y:0.012, w:4.908, h:8.532} . This is clearly wrong.

How can I associate a descent rectangle directly for all characters?

+5
string iso swift core-text
Nov 20 '14 at 20:20
source share

No one has answered this question yet.

See similar questions:

42
Core Text calculates letter frame in iOS
four
What is the relationship between the Glyph Ascender font and Descender in iOS?

or similar:

898
Count the number of occurrences of a character in a string
454
Count the number of occurrences of a character in a string in Javascript
388
Get the nth character of a string in the Swift programming language
360
How to get character position in Python?
317
How to get application version and build number using Swift?
303
Programmatically get your own iOS phone number
293
Extract ("get") a number from a string
248
Get the first n characters of a string
176
Get the last 4 characters of a string
2
Straight rectangle using body text



All Articles