I recently found out about core text. So I am playing around with this API.
I use core text to draw text in a CALayer subclass. This is similar to CATextLayer, but should (eventually) give more flexibility on how and where the text is drawn.
Text is displayed but the quality is not very good. A common problem according to google.
One requirement for decent looking text is not to have a transparent background. (This is already the case in my code).
Another suggestion somewhere was to set CGContextSetAllowsAntialiasing, CGContextSetAllowsFontSubpixelQuantization, etc.
I assumed these had to be set to YES, but this did not improve the text drawing.
I then found a message that CGContextSetShouldSmoothFonts should be set to NO. This did improve the quality.
There are (at least) 7 of these type of functions. With 2 possibilities (yes,no) that gives (at least) 2^7 possible combinations.
A bit too much to try out.
So, my question would be: In your experience, which functions give the best text render quality with core text and CALayer?
I use core text to draw text in a CALayer subclass. This is similar to CATextLayer, but should (eventually) give more flexibility on how and where the text is drawn.
Text is displayed but the quality is not very good. A common problem according to google.
One requirement for decent looking text is not to have a transparent background. (This is already the case in my code).
Another suggestion somewhere was to set CGContextSetAllowsAntialiasing, CGContextSetAllowsFontSubpixelQuantization, etc.
I assumed these had to be set to YES, but this did not improve the text drawing.
I then found a message that CGContextSetShouldSmoothFonts should be set to NO. This did improve the quality.
There are (at least) 7 of these type of functions. With 2 possibilities (yes,no) that gives (at least) 2^7 possible combinations.
A bit too much to try out.
So, my question would be: In your experience, which functions give the best text render quality with core text and CALayer?
Code:
-(void) drawInContext:(CGContextRef)context
{
//[super drawInContext:context]; //default implementation does nothing (see docs)
//get graphics context
NSGraphicsContext *graphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context
flipped:NO];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:graphicsContext];
[B] //How to improve text quality?
// CGContextSetTextMatrix(context, CGAffineTransformIdentity);
// CGContextSetAllowsAntialiasing(context, YES);
// CGContextSetAllowsFontSmoothing(context, YES);
CGContextSetShouldSmoothFonts(context, [COLOR="Blue"]NO[/COLOR]); //improves draw quality of text
// CGContextSetAllowsFontSubpixelPositioning(context, YES);
// CGContextSetShouldSubpixelPositionFonts(context, YES);
// CGContextSetAllowsFontSubpixelQuantization(context, YES);
// CGContextSetShouldSubpixelQuantizeFonts(context, YES);[/B]
//custom drawing
CTFrameDraw(_coreTextFrame, context);
//restore graphics context
[NSGraphicsContext restoreGraphicsState];
}