我想用自定义TTF字体(scheherazade)在我的iOS应用中使用核心文本呈现阿拉伯文字,这在很大程度上起作用 - 但是CTFrame边缘的某些字形被删除。CTFrame在边缘掉落的字形
当我调整框架大小使框架内部出现掉落的字形时,它们显示得相当正确,这导致我相信CTFrameDraw内部出现问题。以下是我用于呈现阿拉伯文字的代码:
CGContextRef context = UIGraphicsGetCurrentContext();
// Flip the coordinate system
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, v.textFrame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGMutablePathRef path = CGPathCreateMutable(); //1
CGPathAddRect(path, NULL, v.textFrame);
CGFloat minLineHeight = 60.0;
CGFloat maxLineHeight = 60.0;
CTTextAlignment paragraphAlignment = kCTRightTextAlignment;
CTLineBreakMode lineBrkMode = kCTLineBreakByWordWrapping;
CTParagraphStyleSetting setting[4] = {
{kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), ¶graphAlignment},
{kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(CGFloat), &minLineHeight},
{kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(CGFloat), &maxLineHeight},
{kCTParagraphStyleSpecifierLineBreakMode, sizeof(CTLineBreakMode), &lineBrkMode}
};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(setting, 4);
NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys:
(id)v.arabicFont, (id)kCTFontAttributeName,
paragraphStyle, (id)kCTParagraphStyleAttributeName,
nil];
CFRelease(paragraphStyle);
NSAttributedString* attString = [[[NSAttributedString alloc]
initWithString:v.verseText attributes:attr] autorelease]; //2
CTFramesetterRef framesetter =
CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attString); //3
CTFrameRef frame =
CTFramesetterCreateFrame(framesetter,
CFRangeMake(0, [attString length]), path, NULL);
CTFrameDraw(frame, context); //4
CFRelease(frame); //5
CFRelease(path);
CFRelease(framesetter);
还附上了显示我面对的问题的屏幕截图。任何帮助将非常感激。谢谢。
无效:http://stellarbeacon.com.au/invalid.png 有效:http://stellarbeacon.com.au/valid.png
我有与其他字体相同的问题。看看这里,如果你已经找到了答案:http://stackoverflow.com/questions/13755757/ctframedraw-cut-some-fonts – Coolant
@Coolant:谢天谢地,昨天我发现问题消失了一个稍微不同的字体,我不确定会适用于您的案件。请阅读下面的评论。 –