Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos CGFontGetGlyphWithGlyphName()出现问题_Macos_Cocoa_Core Graphics - Fatal编程技术网

Macos CGFontGetGlyphWithGlyphName()出现问题

Macos CGFontGetGlyphWithGlyphName()出现问题,macos,cocoa,core-graphics,Macos,Cocoa,Core Graphics,我一直在尝试使用CGFontGetGlyphWithGlyphName方法创建CGGlyph。它适用于所有字母,但不适用于数字 -(void)drawInContext:(CGContextRef)ctx{ CGContextSetAllowsAntialiasing(ctx, true); CGContextSetFont(ctx, font); CGContextSetFontSize(ctx, size); CGGlyph glyph = CGFontGet

我一直在尝试使用CGFontGetGlyphWithGlyphName方法创建CGGlyph。它适用于所有字母,但不适用于数字

-(void)drawInContext:(CGContextRef)ctx{
    CGContextSetAllowsAntialiasing(ctx, true);
    CGContextSetFont(ctx, font);
    CGContextSetFontSize(ctx, size);
    CGGlyph glyph = CGFontGetGlyphWithGlyphName(font, CFSTR("L"));
    CGContextShowGlyphsAtPositions(ctx, &glyph, &(textbounds.origin), 1);
}
当我试图画数字时,它不起作用:

-(void)drawInContext:(CGContextRef)ctx{
    CGContextSetAllowsAntialiasing(ctx, true);
    CGContextSetFont(ctx, font);
    CGContextSetFontSize(ctx, size);
    CGGlyph glyph = CGFontGetGlyphWithGlyphName(font, CFSTR("3"));
    CGContextShowGlyphsAtPositions(ctx, &glyph, &(textbounds.origin), 1);
}

“3”的字形可能被命名为“三”。这是我的测试:

import Foundation
import CoreGraphics

let font = CGFont("Helvetica" as CFString)!
for g in CGGlyph.min ... CGGlyph.max {
    if let name = font.name(for: g) {
        print("\(g) \(name)")
    }
}
输出:

... many lines omitted ....
17 period
18 slash
19 zero
20 one
21 two
22 three
23 four
24 five
25 six
26 seven
... many more lines omitted ...
您最好使用核心文本CTFontGetGlyphsForCharacters函数。请注意,它使用CTFontRef,而不是CGFontRef。您可以使用CTFontCreateWithGraphicsFont将CGFontRef转换为CTFontRef