Carbon/Cocoa 字体看起来不同
我正在尝试使用 Carbon 应用程序中的 ATSU api 绘制当前选择的系统字体。 而且字体比所有其他本机应用程序都更粗。 这是我正在谈论的内容的屏幕截图示例:
(来源:memecode.com)
行是 XCode,中间是我的应用程序使用非粗体字体,底部是我的应用程序使用粗体字体。 我使用了相同的文本,以便更容易看出它们之间的重量差异。 我用来创建绘制样式的代码是:
if (Face() AND !(e = ATSUCreateStyle(&d->hFont)))
{
// Lookup ID
ATSUFontID atsuFont = 0;
e = ATSUFindFontFromName(Face(),
strlen(Face()),
kFontFamilyName,
(FontPlatformCode)kFontNoPlatform,
(FontScriptCode)kFontNoScript,
(FontLanguageCode)kFontNoLanguage,
&atsuFont);
if (!e)
{
Fixed Size;
Size = PointSize() << 16;
Boolean IsBold = Bold();
Boolean IsItalic = Italic();
Boolean IsUnder = Underline();
// Set style attr
ATSUAttributeTag Tags[] = {kATSUFontTag, kATSUSizeTag, kATSUQDItalicTag, kATSUQDUnderlineTag, kATSUQDBoldfaceTag};
ATSUAttributeValuePtr Values[] = {&atsuFont, &Size, &IsItalic, &IsUnder, &IsBold};
ByteCount Lengths[] = {sizeof(atsuFont), sizeof(Size), sizeof(IsItalic), sizeof(IsUnder), sizeof(IsBold)};
if (!(e = ATSUSetAttributes(d->hFont,
CountOf(Tags),
Tags,
Lengths,
Values)))
{
GDisplayString ds(this, "A");
d->Height = ds.Y();
return true;
}
}
}
其中“Face()”返回包含字体名称的 C 字符串,“PointSize()”返回包含我想要的点大小等的整数。我是使用此代码检索此值:
Str255 Name;
SInt16 Size;
Style St;
OSStatus e = GetThemeFont( kThemeSmallSystemFont,
smSystemScript,
Name,
&Size,
&St);
if (e) printf("%s:%i - GetThemeFont failed with %i\n", __FILE__, __LINE__, e);
else
{
Info.Face(p2c(Name));
Info.PointSize(Size);
Status = true;
}
它返回有效的外观/点大小信息,实际上字体看起来是正确的,除了它看起来比其他应用程序更大胆。 它可能看起来没什么大的区别,但当你的整个应用程序充满文本时,它就会变得很明显。 我的旗舰产品是电子邮件客户端......因此有很多文字。
创建布局并最终调用 ATSUDrawText 的绘图代码相当长,我不确定它是否导致了问题..我认为它与样式更相关...但如果需要,我稍后会发布指向该源的链接。
谁能帮助我的字体看起来不那么粗体?
I'm trying to draw in the currently selected system font using the ATSU api in a Carbon app. And the fonts are coming out bolder than all the other native apps. Here is a screenshot example of what I'm talking about:
(source: memecode.com)
The top line is XCode, and the middle is my app using a non-bold font and the bottom is my app using a bold font. I used the same text to make it easy to see the difference in weight between them. The code I'm using to create the styles I draw with is:
if (Face() AND !(e = ATSUCreateStyle(&d->hFont)))
{
// Lookup ID
ATSUFontID atsuFont = 0;
e = ATSUFindFontFromName(Face(),
strlen(Face()),
kFontFamilyName,
(FontPlatformCode)kFontNoPlatform,
(FontScriptCode)kFontNoScript,
(FontLanguageCode)kFontNoLanguage,
&atsuFont);
if (!e)
{
Fixed Size;
Size = PointSize() << 16;
Boolean IsBold = Bold();
Boolean IsItalic = Italic();
Boolean IsUnder = Underline();
// Set style attr
ATSUAttributeTag Tags[] = {kATSUFontTag, kATSUSizeTag, kATSUQDItalicTag, kATSUQDUnderlineTag, kATSUQDBoldfaceTag};
ATSUAttributeValuePtr Values[] = {&atsuFont, &Size, &IsItalic, &IsUnder, &IsBold};
ByteCount Lengths[] = {sizeof(atsuFont), sizeof(Size), sizeof(IsItalic), sizeof(IsUnder), sizeof(IsBold)};
if (!(e = ATSUSetAttributes(d->hFont,
CountOf(Tags),
Tags,
Lengths,
Values)))
{
GDisplayString ds(this, "A");
d->Height = ds.Y();
return true;
}
}
}
Where "Face()" returns a C string containing the font name, "PointSize()" returns an integer containing the point size I want etc etc. I'm retreiving this values with this code:
Str255 Name;
SInt16 Size;
Style St;
OSStatus e = GetThemeFont( kThemeSmallSystemFont,
smSystemScript,
Name,
&Size,
&St);
if (e) printf("%s:%i - GetThemeFont failed with %i\n", __FILE__, __LINE__, e);
else
{
Info.Face(p2c(Name));
Info.PointSize(Size);
Status = true;
}
And it returns valid looking face/pointsize info, and in fact the font looks correct apart from it looking bolder than other apps. It might not look like a big difference but when your entire app is full of text it gets to be obvious. And my flagship product is an email client... hence lots of text.
The drawing code that creates the layouts and eventually calls ATSUDrawText is quite long, and I'm not sure it's causing the issue.. I think it's more style related... but if need by I'll post a link to that source later.
Can anyone help getting my fonts looking less bold?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已将 cocoa ATSU 示例代码转换为 Carbon 并与我自己的代码一起运行。 它看起来是正确的,所以我改进了代码并找出了我在做的不同的事情。 事实证明,这是将字体名称转换为 ATSUFontID 的初始阶段。 显然,我使用的是 ATSUFindFontFromName ,这似乎完全合理,但它看起来与操作系统的其余部分不同。 替换代码的正确下降是:
所以现在我的应用程序看起来很棒:)
I've converted the cocoa ATSU example code to carbon and ran that alongside my own code. It looked correct so I refined that code and worked out what I was doing differently. Turns out that it's that initial stage of turning a font face name into an ATSUFontID. Obviously I'm using ATSUFindFontFromName which appears to be totally reasonable, however it looks different to the rest of the operating system. The correct drop in replacement code is:
So now my apps are looking great :)
实际上,这就是您在应用程序的上面一行看到的粗体字体。 这是照片证据,右侧是 TextEdit 中的 Lucida Grande Bold 11。 应用程序中的下面一行是添加了人造粗体的行。
你知道 Carbon 已经被弃用了,对吧?
Actually, that is the bold font you're seeing in the upper line in your app. Here's photographic evidence, with Lucida Grande Bold 11 in TextEdit on the right. The lower line in your app is that with faux bold added.
And you know Carbon is deprecated, right?