我想用自定義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:謝天謝地,昨天我發現問題消失了一個稍微不同的字體,我不確定會適用於您的案件。請閱讀下面的評論。 –