在我的应用程序中,我正在尝试沿路径渲染文本;这对于大多数字符来说都很好,但是对于日语(或任何非 mac-Roman 字符集)则不行。我已经被建议使用 [NSString drawAtPoint] 在我的 CATiledLayer 中显示正确的字符;然而,它们在大约 5 秒后就消失了。在这段时间内,我可以缩放图层并且它们可以正确地缩放,但它们似乎没有像通常渲染的其余文本一样被提交到 CATiledLayer 中。
在渲染之前,我检查字符串并决定是否有任何无法渲染的内容。如果我会遇到问题,我会使用 drawAtpoint。
在渲染之前,我检查字符串并决定是否有任何无法渲染的内容。如果我会遇到问题,我会使用 drawAtpoint。
if (!isFullyDisplayable)
{
CGContextShowGlyphsAtPoint(context, pt.x, pt.y, realGlyph, 1);
}
else {
// fall back on less flexible font rendering for difficult characters
NSString *b = [gv text];
NSString *c = [b substringWithRange:NSMakeRange(j,1)];
[c drawAtPoint:pt withFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0]];
}
有人能提供一些关于为什么文本会消失的指向吗?
只要使用drawAtPoint,我的调试输出就会被淹没:
<Error>: CGContextGetShouldSmoothFonts: invalid context
<Error>: CGContextSetFont: invalid context
<Error>: CGContextSetTextMatrix: invalid context
<Error>: CGContextSetFontSize: invalid context
<Error>: CGContextSetTextPosition: invalid context
<Error>: CGContextShowGlyphsWithAdvances: invalid context
所以我猜测这与我的上下文管理有关,但我认为如果这个代码段在我使用CGContextShowGlyphsAtPoint的同一位置,它应该已经具有正确的上下文了?