3

我正在尝试使用 core-text 在我的 iOS 应用程序中使用自定义 TTF 字体(scheherazade)呈现阿拉伯语文本,这在大多数情况下都有效 - 但是 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), &paragraphAlignment},
{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

4

1 回答 1

2

CoreText 中有一些与确定正确帧大小相关的错误。其中一些在 iOS 6 中已修复,例如http://www.cocoanetics.com/2012/02/radar-coretext-line-spacing-bug/

如果您的问题仍然存在,那么您应该向雷达提交详细信息。此外,您应该使用 Apple DTS 拨打电话,这可能会为您提供解决方法。通常——如果你的问题确实是一个错误——那么你的 DTS 呼叫就会被退回。

PS:尝试使用我的 DTCoreText 视图显示您的文本,这些视图进行手动布局和显示,看看是否可以在那里重现问题。如果没有,那么你有你的解决方法。

于 2012-12-09T09:42:47.947 回答