Source Text CoreText

I am working on a new application. I process various documents from NSAttributedString using Core Text. I am having problems with weird glitches in text rendering. This does not happen with every document. It seems that there is no rhyme or reason when it appears or not.

A screenshot is shown here to demonstrate the problem.

Glitch in rendering

Here is a line from the same screenshot that displays correctly.

Correct rendering

Screenshots from one screenshot and the same document.

When a problem occurs, usually only 2-3 lines of lines are displayed that are not displayed correctly. The rest of the document is in order.

Here is the code I'm using to render text in drawRect:

CGContextRef context = UIGraphicsGetCurrentContext(); float viewHeight = self.bounds.size.height; CGContextTranslateCTM(context, 0, viewHeight); CGContextScaleCTM(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 help is appreciated!

EDIT: This problem does not exist on iPhone 4, only on 3GS, which I have for testing.

The failure is always in the middle of the document.

+4
source share
1 answer

Try different settings to affect subpixel text rendering. You can see the various options on line 259 at https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML/blob/master/Classes/DTCoreTextLayoutFrame.m

0
source

All Articles