开发者

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:

Problem with font thickness after changing BaseSDK from 10.5 to 10.6

Under 10.6 BaseSDK:

Problem with font thickness after changing BaseSDK from 10.5 to 10.6

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

myAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
    [NSColor myColor], NSForegroundColorAttributeName,
    [NSFont systemFontOfSize:18], NSFontAttributeName,
    paragraphStyle, NSParagraphStyleAttributeName,
    shadow, NSShadowAttri开发者_开发问答buteName, 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.


If we zoom in and look closely at both images, we'll notice an immediate difference (at least I do):

Problem with font thickness after changing BaseSDK from 10.5 to 10.6

The text in the upper image is using CRT-style font smoothing, while the text in the lower image is using Medium LCD-style font smoothing. (All 3 styles of the LCD font smoothing will introduce color casts in the anti-aliased pixels).

We'd need more info about your testing setup to be able to say why this is happening. Under what version(s) of OS X are you testing this with? For example, was your app built against the 10.6 SDK with a deployment target of 10.5, the upper image was taken while testing under OS X 10.5.x (on the same machine), and the lower image was taken while testing under 10.6.x? Or, was all testing done in Mac OS X 10.6.x, and building against the 10.5 SDK resulted in the upper image, and building against the 10.6 SDK resulted in the lower image? What model Mac are you using? What type of external LCD or CRT displays do you have hooked up, if any?

Just a couple of ideas, without having the info asked for above. The default font smoothing style is CRT in 10.5, I believe, and 10.6 defaults to "automatic". So, if you have a system with an LCD display and were testing under 10.5, but have never changed the font-smoothing style from the default CRT-style, then you'd get an image like the upper one. If you then switched to 10.6 on the same system, it's possible that the 10.6 automatic font-smoothing automatically detected your LCD display, and used Medium LCD-style font smoothing, which would result in the "heavier-looking" text in the lower image.

Another thing to keep in mind is that the font smoothing value is stored on a by-host basis. For example, on my machine, the AppleFontSmoothing value is stored in ~/Library/Preferences/ByHost/.GlobalPreferences.##########.plist, where the ########## is your hardware UUID. I suppose it's possible that there could be 2 different values stored for different host setups.


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.


You are getting what you ask for

[NSFont systemFontOfSize:18]

They are most likely subtly different fonts between 10.5 and 10.6. A graphic designer has gone crazy for whatever reason.

What do you get if you log the output of [NSFont systemFontOfSize:18]. Is it different between 10.5 and 10.6?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜