Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use medieval (lowercase, non-lining) numbers

I have a request from a customer to use a certain font in a iOS 7 project because it has medieval numbers.

Is there any way to activate those numbers for a NSAttributedString? As default lining numbers are used, that are included in the font as-well.


Here is an example. Both lines have the same font with no variant (Regular), once with medieval numbers activated, the second wit the default lining numbers.

enter image description here

like image 354
vikingosegundo Avatar asked Feb 27 '14 13:02

vikingosegundo


People also ask

What are non lining numbers?

Text figures (also known as non-lining, lowercase, old style, ranging, hanging, medieval, billing, or antique figures or numerals) are numerals designed with varying heights in a fashion that resembles a typical line of running text, hence the name.

What is the difference between lining numbers and old style numbers?

Lining figures are all the same height, and align on the baseline and (most commonly) the cap height, thus the name aligning. Old style figures approximate lowercase characters in that they have an x-height as well as fixed-arrangement ascenders and descenders.

What are lining numbers?

Lining Figures (LF)A modern style of numerals also known as short ranging figures or regular numerals, lining figures are all the same height and all figures sit on the baseline. They are generally the same height as the uppercase letters in the typeface.

What is a lining font?

Lining figures (also called aligning, cap, or modern figures) approximate capital letters in that they are uniform in height, and generally align with the baseline and the cap height. In some traditional typefaces, certain numerals extend slightly above and/or below the baseline and/or the cap height.


1 Answers

These are called lowercase numbers and can be turned on using UIFontDescriptor.

First, you need to import CoreText for some constants:

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

Then create font using font descriptor. Here I use Georgia family:

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

Result:
enter image description here

Edit: As @Random832 pointed out, Georgia has only lowercase numbers, so the result is irrelevant. However, @vikingosegundo confirmed this code works on supported fonts. Thanks.

enter image description here

The top line was generated with

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

the second line with

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;
like image 112
Tricertops Avatar answered Oct 23 '22 01:10

Tricertops