2012-05-21 2 views
0

가 나는 기능을 가진 한자를 보여주고 있습니다Quartz 2D로 중국어 글꼴 글리프 그리기?

CG_EXTERN void CGContextShowGlyphsAtPoint(CGContextRef context, CGFloat x, 
CGFloat y, const CGGlyph glyphs[], size_t count) 

을하지만 정확하게 표시되지 않습니다. 다음과 같이 내가 사용하는 코드는 다음과 같습니다

CGFontRef cgfont = CGFontCreateWithFontName((CFStringRef)label.font.fontName); 
CGContextSetFont(theContext, cgfont); 
CGContextSetFontSize(theContext, label.font.pointSize); 
CGContextSetTextDrawingMode (theContext, kCGTextClip); 

CGGlyph *glyphs = malloc(sizeof(CGGlyph) * [label.text length]); 
char *Chars = malloc(sizeof(char) * ([label.text length] + 1)); 
[label.text getCString:Chars maxLength:([label.text length] + 1) encoding:NSISOLatin2StringEncoding]; 

for(int currentChar = 0; currentChar < [label.text length]; ++currentChar) 
{ 
    glyphs[currentChar] = Chars[currentChar]; 
} 
CGContextShowGlyphsAtPoint(theContext, 0, (size_t)label.font.ascender, glyphs, [label.text length]); 

편집

장치가 아이폰이다. 예를 들어 "中文"같은 중국어 문자를 표시하고 싶지만 CGContextShowGlyphsAtPoint를 사용하여 "@ # Radcx67"처럼 문자열을 그립니다.

이 문제를 해결하는 방법은 무엇입니까? 감사!

+0

더 구체적으로 말씀해 주시겠습니까? 예 : "정확히 보여주지 않는다"는 말의 의미는 무엇입니까? 제발, 당신이 무엇을 기대하고 무엇을 얻었는지에 대한 예를 들어주세요. 게다가 어떤 장치를 개발할 것인지 지정할 수 있습니까? Mac, iPad, iPhone? 그들 중 아무도 없습니다?!? –

+0

답장을 보내 주셔서 감사합니다. 기기는 iPhone입니다. 예를 들어 "中文"같은 중국어 문자를 표시하고 싶지만 CGContextShowGlyphsAtPoint를 사용하여 "@ # Radcx67"과 같이 문자열을 그립니다. – Bunsman

+0

제공된 정보로 질문을 편집 했으므로 이제 더 많은 관심을 끌기를 바랍니다. –

답변

1

먼저,이

#import "CoreText/CTFont.h" 

그런 다음 아래와 같은 기능을 사용하시기 바랍니다 포함한다.

void drawStringWithglyphs(CTFontRef iFont, CFStringRef iString, CGContextRef ctx, int x, int y) 

{ 
UniChar *characters; 
CGGlyph *glyphs; 
// CGPoint *points; 
CFIndex count; 

assert(iFont != NULL && iString != NULL); 

// Get our string length. 
count = CFStringGetLength(iString); 

// Allocate our buffers for characters and glyphs. 
characters = (UniChar *)malloc(sizeof(UniChar) * count); 
assert(characters != NULL); 

glyphs = (CGGlyph *)malloc(sizeof(CGGlyph) * count); 
assert(glyphs != NULL); 

// Get the characters from the string. 
CFStringGetCharacters(iString, CFRangeMake(0, count), characters); 

CTFontGetGlyphsForCharacters(iFont, characters, glyphs, count); 


// Do something with the glyphs here, if a character is unmapped 
    CGContextShowGlyphsAtPoint(ctx, x, y, glyphs, count); 

// Free our buffers 
free(characters); 
free(glyphs); 
} 
+0

은 reply.I이 시도 주셔서 감사합니다,하지만 여전히 방법 대신 일하러하지 않습니다 CTFontRef ctfont = CTFontCreateWithName ((CFStringRef) label.font.fontName, label.font.pointSize이 함께 CGContextShowGlyphsAtPoint 을 , & xform); drawStringWithglyphs (ctfont, (CFStringRef) label.text, theContext, 0, (size_t) label.font.ascender); 올바른 방법입니까? – Bunsman

+0

마침내 성공 사용 NSString 그리기 방법 : CGContextSaveGState (ctx); CGAffineTransform save = CGContextGetTextMatrix (ctx); CGContextTranslateCTM (ctx, 0.0f, self.bounds.size.height); CGContextScaleCTM (ctx, 1.0f, -1.0f); [str drawAtPoint : point withFont : font]; CGContextSetTextMatrix (ctx, save); CGContextRestoreGState (ctx); –

+0

이 링크를 참조하십시오 : http : //stackoverflow.com/questions/1252343/flipped-nsstring-drawing-in-cgcontext/11281065#11281065 –

관련 문제