Created
July 7, 2014 09:47
-
-
Save vfig/41f25867fc7af6555110 to your computer and use it in GitHub Desktop.
Calculate the line height of a CGFontRef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGFloat CGFontGetLineHeight(CGFontRef font, CGFloat fontSize) | |
{ | |
if (!font) return 0.0f; | |
int lineHeightGlyphUnits = CGFontGetAscent(font) - CGFontGetDescent(font) + CGFontGetLeading(font); | |
CGFloat lineHeightEms = (CGFloat)lineHeightGlyphUnits / CGFontGetUnitsPerEm(font); | |
return lineHeightEms * fontSize; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment