替代NSGlyph的-glyphIsEncoded:?

时间:2012-09-29 08:07:58

标签: objective-c macos cocoa

在移植一些 古代 代码时,我遇到了一个特殊的类,在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...

1 个答案:

答案 0 :(得分:2)

根据documentation

[font glyphIsEncoded:glyph]

可以替换为

glyph < [font numberOfGlyphs]