メソッド glyphWithName: は、文字ではなく、glyphName を想定しています。単純なラテン文字の場合、glyphName は文字 (@"A") と同じです。私の知る限り、ひらがなやカタカナには名前がありますが、漢字には名前がありません。漢字は単純に数が多すぎて、グリフの多くは同じ漢字の変形です。
したがって、漢字では別の方法を使用する必要があります。ここに私のために働く例があります。
// Convert a single character to a bezier path
- (UIBezierPath *)bezierPathFromChar:(NSString *)aChar inFont:(CTFontRef)aFont {
// Buffers
unichar chars[1];
CGGlyph glyphs[1];
// Copy the character into a buffer
chars[0] = [aChar characterAtIndex:0];
// Encode the glyph for the single character into another buffer
CTFontGetGlyphsForCharacters(aFont, chars, glyphs, 1);
// Get the single glyph
CGGlyph aGlyph = glyphs[0];
// Find a reference to the Core Graphics path for the glyph
CGPathRef glyphPath = CTFontCreatePathForGlyph(aFont, aGlyph, NULL);
// Create a bezier path from the CG path
UIBezierPath *glyphBezierPath = [UIBezierPath bezierPath];
[glyphBezierPath moveToPoint:CGPointZero];
[glyphBezierPath appendPath:[UIBezierPath bezierPathWithCGPath:glyphPath]];
CGPathRelease(glyphPath);
return glyphBezierPath;
}
次のように使用します。
NSString *theChar = @"男";
CTFontRef font = CTFontCreateWithName(CFSTR("HiraKakuProN-W6"), 114.0, NULL);
UIBezierPath *glyphBezierPath = [self bezierPathFromChar:theChar inFont:font];
編集 - ローカライズ可能なフォントを定義する別の方法:
CTFontRef font = CTFontCreateWithName((CFStringRef)@"Helvetica-Bold", 114.0, NULL);