2012-11-25 38 views
3

我想用自定义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), &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

+0

我有与其他字体相同的问题。看看这里,如果你已经找到了答案:http://stackoverflow.com/questions/13755757/ctframedraw-cut-some-fonts – Coolant

+0

@Coolant:谢天谢地,昨天我发现问题消失了一个稍微不同的字体,我不确定会适用于您的案件。请阅读下面的评论。 –

回答

2

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

如果您的问题仍然存在,那么您应该提供具体细节的雷达。你也应该打开Apple DTS的电话,这可能会为你提供一种解决方法。通常情况下 - 如果您的问题确实是一个错误 - 那么您会将您的DTS电话归还。

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

+0

非常感谢您的回复。在过去的几周里,我尝试了很多东西,我几乎失去了原有的轨迹 - 但我肯定尝试了手动布局,问题仍然存在。 然而,幸运的是,昨天我想到了一个稍微不同的字体问题消失,这使得读完你的帖子后,完美的感觉...... :) –

+0

是的,我在iOS6中测试,问题仍然存在。 – Coolant

+0

向我确认iOS 6修复程序的Apple工程师提到,对于某些字体,嵌入的度量标准缺失或错误。所以使用不同的字体也可以是一种解决方法。但绝对要提供一个雷达,以便他们在将来解决这个问题。 – Cocoanetics