CGContextShowGlyphsAtPositions
이 아닌 유니 코드를 그리려면 CoreText가 답이됩니다. 또한 사용자 정의 도면이 필요한 경우 [NSString drawAtPoint:withFont:]
보다 좋습니다. 다음은 완전한 예입니다.
CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attributedString);
CFArrayRef runArray = CTLineGetGlyphRuns(line);
//in more complicated cases make loop on runArray
//here I assumed this array has only 1 CTRunRef within
const CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, 0);
//do not use CTFontCreateWithName, otherwise you won't see e.g. chinese characters
const CTFontRef font = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName);
CFIndex glyphCount = CTRunGetGlyphCount(run);
CGGlyph glyphs[glyphCount];
CGPoint glyphPositions[glyphCount];
CTRunGetGlyphs(run, CFRangeMake(0, 0), glyphs);
//you can modify positions further
CTRunGetPositions(run, CFRangeMake(0, 0), glyphPositions);
CTFontDrawGlyphs(font, glyphs, glyphPositions, glyphCount, context);
CFRelease(line);
알고 계시 겠지만, 거의 확실합니다. 그 문자를 이미지에 대한 내 필요를 처리하지만 그것에 대한 간단한 글꼴 통계를 얻을 수 없습니다. 현재 컨텍스트 ('UIGraphicsGetCurrentContext')에 들어갔다 나오는 것을 뛰어 넘을 수 있고 그리기 전후에'CGContextGetTextPosition'을 사용하여 본질적으로 경계 상자의 너비를 얻을 수 있습니다. 그게 제가 파생에 관심이있는 부분입니다. 감사합니다! – hkatz
잠깐,'[@ @ "a"sizeWithFont : ]와 (과) 무슨 문제가 있니? 왜 개별 문자에 대한 메트릭이 필요합니까? –
각 문자에 대해 sizeWithFont를 수행하기 때문에 메트릭을 얻을 수 있습니다. Andrew : 문자를 질감에 캐시하거나 경로를 따라 그려야 할 수도 있습니다. –