在移植一些古老的代码时,我遇到了一个奇怪的类,该类在OS X 10.4中被NSGlyph弃用了。搜寻了一段时间后,我想出了very few hits的确切含义,以及为什么它对框架中的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...
最佳答案
[font glyphIsEncoded:glyph]
可以替换为
glyph < [font numberOfGlyphs]