在移植一些古老的代码时,我遇到了一个在 OS X 10.4 中大部分被弃用的特殊类,称为 NSGlyph。在谷歌上搜索了一段时间后,我几乎没有找到关于它究竟做了什么,以及为什么它对框架中的 if-else 分支很重要的问题。特别是,该方法NSFont -glyphIsEncoded:
似乎是某些分支的重要组成部分,如果只是将其删除并继续前进,以防万一发生故障,这对我来说将是一种耻辱。有人知道合适的替代品NSFont -glyphIsEncoded:
吗?
if (glyph == 0xffff || ![font glyphIsEncoded:glyph]) {
// Switch to getting it from the system font for "normal" keys
// get the glyph from the layout manager (this normally will be the ascii value)
glyph = [layoutManager glyphAtIndex: i];
font = [NSFont systemFontOfSize:[font pointSize]]; // use the system font
//NSLog(@"Asking layout manager for glyph for %@, got %d", glyphName, glyph);
}
if (glyph != 0xffff && [font glyphIsEncoded:glyph]) {
NSRect bounds = [font boundingRectForGlyph:glyph];
[path moveToPoint: NSMakePoint(left, 0.0 - [font descender])];
[path appendBezierPathWithGlyph: glyph inFont: font];
left += [font advancementForGlyph: glyph].width;
continue; // rendered a character
} //etc...