Search code examples
objective-ccocoatextdrawingbase-sdk

Problem with font thickness after changing BaseSDK from 10.5 to 10.6


After changing the BaseSDK of my project to 10.6 I noticed that my custom drawn text looks different (look at the images: the same code for drawing)

Under 10.5 BaseSDK: image1

Under 10.6 BaseSDK: image2

I'm drawing with [(NSString *)myString drawInRect:myRect withAttributes:myAttributes].

myAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
    [NSColor myColor], NSForegroundColorAttributeName,
    [NSFont systemFontOfSize:18], NSFontAttributeName,
    paragraphStyle, NSParagraphStyleAttributeName,
    shadow, NSShadowAttributeName, nil];

What is the reason of such difference, or just how to reduce the thickness of the font? I've tried to reduce thickness by

[NSFontManager convertWeight:NO ofFont:font]

but it looks not much better...

Thanks in advance.


Solution

  • Now I know the reason why it happens and the fix of this problem: Seems that with 10.6 was added font LCD smoothing option, that is enabled in Preferences -> Appearance -> "Use LCD font smoothing when available" as checkbox which is checked by default.

    That's why after changing the BaseSDK of the project to 10.6, texts in the application became LCD-style smoothed and looking bad at all.

    So the fix of the problem in code is to change the smoothing options in graphics context before our drawings:

    CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
    CGContextSetShouldSmoothFonts(context, NO);
    

    The documentation of this method tells us that this parameter is part of the graphics state so if you don't want to change this option in other font drawings, you should restore the graphics state.

    Thanks to @NSGod for finding the reason of this problem.