BaseSDK从10.5改为10.6后出现字体粗细问题
将项目的 BaseSDK 更改为 10.6 后,我注意到我的自定义绘制文本看起来有所不同(查看图像:相同的绘制代码)
在 10.5 BaseSDK 下:
在 10.6 BaseSDK 下:
我正在使用 [(NSString *)myString drawInRect:myRect withAttributes:myAttributes] 进行绘图。
myAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[NSColor myColor], NSForegroundColorAttributeName,
[NSFont systemFontOfSize:18], NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName,
shadow, NSShadowAttributeName, nil];
造成这种差异的原因是什么,或者如何减小字体的粗细? 我尝试通过
[NSFontManager ConvertWeight:NO ofFont:font]
来减少厚度,但看起来并没有好多少......
提前致谢。
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:
Under 10.6 BaseSDK:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我们放大并仔细观察这两个图像,我们会立即注意到差异(至少我是这样):
上图中的文本使用 CRT 风格的字体平滑,而下图像中的文本使用 Medium LCD 风格的字体平滑。 (所有 3 种 LCD 字体平滑样式都会在抗锯齿像素中引入色偏)。
我们需要有关您的测试设置的更多信息,以便能够说明为什么会发生这种情况。您在哪个版本的 OS X 下进行测试?例如,您的应用程序是针对 10.6 SDK 构建的,部署目标为 10.5,上图是在 OS X 10.5.x(在同一台计算机上)下测试时拍摄的,下图是在 10.6.x 下测试时拍摄的?或者,所有测试都是在 Mac OS X 10.6.x 中完成的,针对 10.5 SDK 构建会生成上图,而针对 10.6 SDK 构建会生成下图?您使用什么型号的 Mac?您连接了什么类型的外部 LCD 或 CRT 显示器(如果有)?
只是一些想法,没有上面要求的信息。我相信,10.5 中默认的字体平滑样式是 CRT,10.6 默认为“自动”。因此,如果您有一个带有 LCD 显示屏的系统,并且在 10.5 下进行测试,但从未更改过默认 CRT 样式的字体平滑样式,那么您将得到类似于上图的图像。如果您随后在同一系统上切换到 10.6,则 10.6 自动字体平滑可能会自动检测到您的 LCD 显示器,并使用中 LCD 风格的字体平滑,这会导致下图中的“看起来更重”的文本。
另一件需要记住的事情是字体平滑值是按主机存储的。例如,在我的计算机上,
AppleFontSmoothing
值存储在 ~/Library/Preferences/ByHost/.GlobalPreferences.##########.plist 中,其中 #### ###### 是您的硬件 UUID。我想可能会为不同的主机设置存储 2 个不同的值。If we zoom in and look closely at both images, we'll notice an immediate difference (at least I do):
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.现在我知道发生这种情况的原因以及解决此问题的方法:
似乎 10.6 中添加了字体 LCD 平滑选项,该选项在“首选项”->“启用”中启用。外观-> “在可用时使用 LCD 字体平滑”作为默认选中的复选框。
这就是为什么在将项目的BaseSDK更改为10.6后,应用程序中的文本变得LCD风格的平滑并且看起来很糟糕。
因此,代码中问题的解决方法是在绘图之前更改图形上下文中的平滑选项:
此方法的文档告诉我们此参数是图形状态的一部分,因此如果您不想在其他中更改此选项字体绘图后,应恢复图形状态。
感谢@NSGod 找到了这个问题的原因。
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:
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.
您正在得到您所要求的
[NSFont systemFontOfSize:18]
它们很可能是 10.5 和 10.6 之间略有不同的字体。一位平面设计师因为某种原因而发疯了。
如果记录
[NSFont systemFontOfSize:18]
的输出,您会得到什么。 10.5和10.6有区别吗?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?