2

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.

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
ruliak
  • 114
  • 7
  • It might not be thickness but shadow. – quaertym May 12 '11 at 12:51
  • Unfortunately, the problem is not with shadow. Checked many times) – ruliak May 12 '11 at 13:05
  • Are you drawing to a transparent bitmap? Or is there ever a risk that you might draw the text twice, without redrawing the background? – al45tair May 12 '11 at 14:22
  • @alastair Need to check if drawing twice, nice idea) – ruliak May 12 '11 at 16:13
  • @alastair Unfortunately, text is drawing once after redrawing background.I think the problem is in some changes in rendering options but didn't find anything in 10.6 BaseSDK release notes. – ruliak May 12 '11 at 16:21

3 Answers3

2

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

enter image description here

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.

NSGod
  • 22,699
  • 3
  • 58
  • 66
  • Hi! The project is building on 10.6 SDK with deployment target 10.4. I didn't find AppleFontSmoothing value in that plist, but you are right: the problem is in font smoothing options. If uncheck "Use LCD font smoothing when available" in "Appearance" section of "Preferences" - font becomes normal (as under 10.5 BaseSDK). – ruliak May 13 '11 at 15:41
  • But how can I change this smoothing option in the code or in the project building options or elsewhere to make it smoothing using CRT-style, without unchecking checkboxes in Preferences?) Thanks in advance. – ruliak May 13 '11 at 15:45
  • Oh, I found the answer at all. Will post in few minutes. – ruliak May 13 '11 at 16:01
  • Generally speaking, you should not try to override the user's font smoothing settings without good reason. If the user's default is to use subpixel rendering, probably the only good reason to disable it is if you are going to take a screenshot that might be printed on paper or viewed on a different monitor (which could have a different subpixel arrangement). – user57368 May 13 '11 at 21:20
  • @user57368 I agree with you that I shouldn't change the user's defaults. But in this case LCD smoothing makes the font looks awful... So I think I should change drawing options to make the font layout better. – ruliak May 16 '11 at 10:50
  • Perhaps on your machine the subpixel antialiasing looks awful. On my machine, it makes the text look much more legible. Perhaps your machine has gotten confused about the subpixel order for your monitor, and is using RGB instead of BGR, or vice versa. Regardless, I think you're trying to exert a level of precise control over appearance that will always be difficult to achieve across a variety of machines. – user57368 May 17 '11 at 02:43
  • There are all of apple displays types in our office so I confidently can say that LCD font smoothing makes the text in my app looks awful) – ruliak May 26 '11 at 08:47
2

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.

ruliak
  • 114
  • 7
0

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?

Warren Burton
  • 17,451
  • 3
  • 53
  • 73
  • I was logging out all of Font properties, but they are the same in both 10.5 and 10.6... – ruliak May 12 '11 at 16:06
  • looking closer you are getting different fonts or same font name with different glyphs . Compare the numbers especially. What happens if you explicitly ask for a font by name. "Helvetica" or "Arial" perhaps. – Warren Burton May 12 '11 at 17:31
  • I compared a lot of properties - they are the same in both cases, but real problem is in font smoothing options, as @NSGod told. – ruliak May 13 '11 at 15:48