绘画中文:
Quartz中CGContextshowtextAtPoint不支持中文,用以下方式绘画
NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
[NSGraphicsContext setCurrentContext:gc];
[gc flushGraphics];
[strtext drawAtPoint:origin withAttributes:nil];
[NSGraphicsContext restoreGraphicsstate];
以下是将字符串内容转换为矢量路径图形
- (NSBezIErPath *) makePathFromString: (Nsstring *) string forFont: (NSFont *) Font { NSTextVIEw *textvIEw; textvIEw = [[NSTextVIEw alloc] init]; [textvIEw setString: string]; [textvIEw setFont: Font]; NSLayoutManager *layoutManager; layoutManager = [textvIEw layoutManager]; NSRange range; range = [layoutManager glyphRangeForCharacterRange: NSMakeRange (0,[string length]) actualCharacterRange: NulL]; NSGlyph *glyphs; glyphs = (NSGlyph *) malloc (sizeof(NSGlyph) * (range.length * 2)); [layoutManager getGlyphs: glyphs range: range]; NSBezIErPath *path; path = [NSBezIErPath bezIErPath]; [path movetoPoint: NSMakePoint (20.0, 20.0)]; [path appendBezIErPathWithGlyphs: glyphs count: range.length inFont: Font]; free (glyphs); [textvIEw release]; return (path); } 总结
以上是内存溢出为你收集整理的cocoa绘画中文全部内容,希望文章能够帮你解决cocoa绘画中文所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)