CoreText rendering text glitch
I am working on a new app. I render different documents from an NSAttributedString using Core Text. I am having trouble with strange glitches in the rendering of the text. It doesn't happen with every document. There doesn't seem to be a rhyme or reason to when it appears or not.
Here is a cropped screen shot here to demonstrate the problem.
Here is a line from the same screenshot that is rendered correctly.
The screenshots are from the same screenshot and the same document.
When the problem occurs, there are usually only 2-3 consecutive lines of text that are rendered incorrectly. The rest of the document is fine.
Here is the code that I use to render the text in drawRect:
CGContextRef context = UIGraphicsGetCurrentContext();
float viewHeight = self.bounds.size.height;
CGContextTranslateCTM(context, 0, viewHeight);
CGContextScaleCTM(开发者_C百科context, 1.0, -1.0);
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, 1.0));
CGMutablePathRef path = CGPathCreateMutable();
CGRect bounds = CGRectMake(PADDING_LEFT, -PADDING_TOP, self.bounds.size.width-20.0, self.bounds.size.height);
CGPathAddRect(path, NULL, bounds);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFMutableAttributedStringRef)attrString);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
CFRelease(framesetter);
CFRelease(path);
CTFrameDraw(frame, context);
Any assistance is appreciated!
EDIT: This problem does not appear to exist on the iPhone 4, only on the 3GS that I have for testing.
The glitch is always in the middle of a document.
Please try the various settings to affect the subpixel rendering of text. You can see various options on line 259 in https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML/blob/master/Classes/DTCoreTextLayoutFrame.m
精彩评论