2012-11-25 37 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