【问题标题】:Use medieval (lowercase, non-lining) numbers使用中世纪(小写,非衬里)数字
【发布时间】:2014-02-27 13:17:00
【问题描述】:

我有一位客户要求在 iOS 7 项目中使用某种字体,因为它有 medieval numbers

有没有办法为 NSAttributedString 激活这些数字?由于使用了默认的行号,它们也包含在字体中。


这是一个例子。两行具有相同的字体,没有变体(Regular),一次激活中世纪数字,第二行使用默认行号。

【问题讨论】:

  • 激活是什么意思?改字体不行吗?
  • 字体有2种数字样式。衬里样式是默认样式。 @Sulthan
  • @Sulthan,也许我添加的图像会让事情更清晰。
  • 关于“测距”“中世纪”数字的杰出信息,谢谢! en.wikipedia.org/wiki/Text_figures

标签: objective-c cocoa-touch ios7 nsattributedstring typography


【解决方案1】:

这些被称为小写数字,可以使用UIFontDescriptor打开。

首先,你需要为一些常量导入CoreText:

#import <CoreText/SFNTLayoutTypes.h>
or
@import CoreText.SFNTLayoutTypes;

然后使用字体描述符创建字体。这里我使用Georgia家族:

NSDictionary *lowercaseNumbers = @{
                                   UIFontFeatureTypeIdentifierKey: @(kNumberCaseType),
                                   UIFontFeatureSelectorIdentifierKey: @(kLowerCaseNumbersSelector),
                                   };
UIFontDescriptor *descriptor = [[UIFontDescriptor alloc] initWithFontAttributes:
                                @{
                                  UIFontDescriptorFamilyAttribute: @"Georgia",
                                  UIFontDescriptorFeatureSettingsAttribute:@[ lowercaseNumbers ],
                                  }];
UIFont *font = [UIFont fontWithDescriptor:descriptor size:15];

结果:

编辑:正如 @Random832 指出的那样,Georgia 只有小写数字,因此结果无关紧要。但是,@vikingosegundo 确认此代码适用于支持的字体。谢谢。

顶行是用

生成的
UIFont *font = [UIFont fontWithName:@"DIN Next LT Pro" size:12];
if (font)
    label.font = font;

第二行

NSDictionary *lowercaseNumbers = @{  UIFontFeatureTypeIdentifierKey:@(kNumberCaseType), UIFontFeatureSelectorIdentifierKey: @(kLowerCaseNumbersSelector)};
UIFontDescriptor *descriptor = [[UIFontDescriptor alloc] initWithFontAttributes:
                                @{UIFontDescriptorFamilyAttribute: @"DIN Next LT Pro",UIFontDescriptorFeatureSettingsAttribute:@[ lowercaseNumbers ]}];
UIFont *font = [UIFont fontWithDescriptor:descriptor size:12];
if (font)
    label.font = font;

【讨论】:

  • 没问题。 SFNTLayoutTypes.h 值得研究,您可能会发现一些更有趣的功能,例如比例数字或替代标点符号。
  • 我猜最大的问题是措辞。排版有很多我不知道的词汇。甚至用我自己的母语。
  • @vikingosegundo 在这种情况下,您必须尝试所有这些以查看它们的作用;)
  • Georgia 默认情况下有小写数字,我不确定它是否有大写数字,也许是一个不同字体的例子?
  • @Random832:我使用 DIN Next LT Regular。它不是免费提供的。但它同时具有 - 非衬里和衬里数字。 iMartins 代码正在使用它。
【解决方案2】:

Another question 有一个指向正确方向的指针,尽管问题提到了表格数字 [vs 比例] 而不是文本 vs 衬里。

看起来您可以使用 CTFontDescriptorCreateCopyWithFeature 并将 kNumberCaseType 设置为 kLowerCaseNumbersSelector 以这种方式显示数字。

Here's another related questionhere's the blog post provided in the answer

【讨论】:

    猜你喜欢
    • 2020-02-18
    • 1970-01-01
    • 2014-04-27
    • 2023-03-22
    • 1970-01-01
    • 2021-04-14
    • 1970-01-01
    • 2018-01-25
    • 2018-03-03
    相关资源
    最近更新 更多