そのため、CoreText プロジェクトが適切に機能していなかったので、数時間頭を壁にぶつけました。私は問題を見つけました、そしてそれは奇妙でした。同じサイズの同じフォントのフォント特性が CTFontRef と UIFont で異なる理由を誰かが理解するのを手伝ってくれることを願っています。
テストするために、次の 4 行を使用しました。
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));
そして、この出力を受け取りました:
UIFont: ascent:18.400391 descent:-4.599609 leading:24.000000
CTFontRef: ascent:15.400391 descent:4.599609 leading:0.000000
何???