NSFont - 如何获得正确的字体?
我想制作一个 NSFont 来描述 Arial,正常,高度 30pt。到目前为止我已经:
NSNumber *weight = [NSNumber numberWithFloat:1.0];
NSNumber *slant = [NSNumber numberWithFloat:1.0];
NSDictionary *fontTraits = [NSDictionary dictionaryWithObjectsAndKeys: weight, NSFontWeightTrait, slant, NSFontSlantTrait, nil];
NSDictionary *fontAttributes = [NSDictionary dictionaryWithObjectsAndKeys: @"Arial", NSFontFaceAttribute,
fontTraits, NSFontTraitsAttribute, nil];
NSFontDescriptor *fontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes: fontAttributes];
NSFont *largeFont = [NSFont fontWithDescriptor: fontDescriptor size: 30];
但是生成的 NSFont 大小不正确。我可以把任何我想要的尺寸放在那里,它们看起来都一样。
I would like to make a NSFont to describe Arial, normal, 30pt in height. So far I have:
NSNumber *weight = [NSNumber numberWithFloat:1.0];
NSNumber *slant = [NSNumber numberWithFloat:1.0];
NSDictionary *fontTraits = [NSDictionary dictionaryWithObjectsAndKeys: weight, NSFontWeightTrait, slant, NSFontSlantTrait, nil];
NSDictionary *fontAttributes = [NSDictionary dictionaryWithObjectsAndKeys: @"Arial", NSFontFaceAttribute,
fontTraits, NSFontTraitsAttribute, nil];
NSFontDescriptor *fontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes: fontAttributes];
NSFont *largeFont = [NSFont fontWithDescriptor: fontDescriptor size: 30];
but the resulting NSFont is not the right size. I can put any size I want in there and they all look the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在为 iOS 或 Mac OS X 编写内容?
这在我的 Mac 应用程序中运行良好:
使用粗体和/或斜体更新:这对您来说足够了吗?
UPDATE 2 可能会看看 NSFontManager
,但是使用这两个都无法创建粗细为 5 且倾斜度为 4 的字体。
我最近与一位设计师谈论了字体,他告诉我我认为通常像 Arial 这样的字体实际上有 4 种字体(即 Arial、Arial Italic、Arial Bold 和 Arial Bold Italic)。这 3 种其他字体样式(具有特征)不是由算法动态生成的。
are you writing for iOS or Mac OS X?
this works fine in my Mac App:
UPDATE with bold and/or italic: is that enough for you ?
UPDATE 2 may be take a look at NSFontManager
But with neither of those you are able to create a font with a weight of 5 and a slant of 4.
i recently talked to a designer about fonts and he told me that usually a font like Arial is actually 4 Fonts (i.e. Arial, Arial Italic, Arial Bold and Arial Bold Italic). those 3 other font styles (with the traits) are not generated on the fly by an algorithm.