2

So I just spent several hours beating my head against the wall because my CoreText project wasn't working properly. I found the issue, and it was odd. I'm hoping someone here can help me understand why the font characteristics of the same font of the same size are different between CTFontRef and UIFont.

To test, I used these four lines:

UIFont* tFont=[UIFont fontWithName:@"Helvetica" size:20];
CTFontRef fontRef=CTFontCreateWithName((CFStringRef)@"Helvetica", 20.0f, NULL);
NSLog(@"UIFont: ascent:%f descent:%f leading:%f",_font.ascender,_font.descender,_font.leading);
NSLog(@"CTFontRef: ascent:%f descent:%f leading:%f",CTFontGetAscent(fontRef),CTFontGetDescent(fontRef),CTFontGetLeading(fontRef));

And received this output:

UIFont: ascent:18.400391 descent:-4.599609 leading:24.000000
CTFontRef: ascent:15.400391 descent:4.599609 leading:0.000000

What???

Chris
  • 1,013
  • 1
  • 15
  • 35
  • Other than font handling, UIKit and CT don't overlap at all. – CodaFi May 23 '12 at 03:53
  • Understood, but Helvetica 20 is Helvetica 20. Things like ascent, leading, descent, should be the same, shouldn't they? – Chris May 23 '12 at 04:13
  • Not necessarily check out the varying return value definitions for [CT](https://developer.apple.com/library/mac/documentation/Carbon/reference/CTFontRef/Reference/reference.html#//apple_ref/c/func/CTFontGetAscent), and [UI](http://developer.apple.com/library/ios/documentation/uikit/reference/UIFont_Class/Reference/Reference.html#//apple_ref/occ/instp/UIFont/ascender) – CodaFi May 23 '12 at 04:16

0 Answers0