Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The method glyphWithName: expects a glyphName, not the character. For simple latin characters the glyphName is the same as the character – @"A". As far as I know, Kanji do not have names, although hiragana and katakana do. Kanji are simply too numerous, and many of the glyphs are variants on the same Kanji.</p> <p>So you have to use a different method with Kanji. Here is an example that works for me.</p> <pre><code>// 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; } </code></pre> <p>Use like this:</p> <pre><code>NSString *theChar = @"男"; CTFontRef font = CTFontCreateWithName(CFSTR("HiraKakuProN-W6"), 114.0, NULL); UIBezierPath *glyphBezierPath = [self bezierPathFromChar:theChar inFont:font]; </code></pre> <p>Edit - another way of defining the font that can be localized:</p> <pre><code>CTFontRef font = CTFontCreateWithName((CFStringRef)@"Helvetica-Bold", 114.0, NULL); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload