Skip to content

Commit 95f725c

Browse files
Mark Pospeselmpospese
authored andcommitted
Rename SystemFontInfo to SystemFontFamily
1 parent 9c4f7e7 commit 95f725c

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Just want to use the default system fonts? Y—MatterType has you covered.
142142
extension Typography {
143143
/// System font, Semibold 17/22 pts
144144
static let headline = Typography(
145-
fontFamily: FontInfo.system,
145+
fontFamily: Typography.systemFamily,
146146
fontWeight: .semibold,
147147
fontSize: 17,
148148
lineHeight: 22,
@@ -168,7 +168,7 @@ extension Typography {
168168

169169
## Custom Font Families
170170

171-
Y—MatterType does its best to automatically map font family name, font style (regular or italic), and font weight (ultralight to black) into the registered name of the font so that it may be loaded using `UIFont(name:, size:)`. (This registered font name may differ from the name of the font file and from the display name for the font family.) However, some font families may require custom behavior in order to properly load the font (e.g. the semibold font weight might be named "DemiBold" instead of the more common "SemiBold"). To support this you can declare a class or struct that conforms to the `FontFamily` protocol and use that to initialize your `Typography` instance. This protocol has four methods, each of which may be optionally overridden to customize how fonts of a given weight are loaded. The framework contains three different implementations of `FontFamily` for you to consider (`FontInfo`, `SystemFontInfo`, and `SFProFontFamily`).
171+
Y—MatterType does its best to automatically map font family name, font style (regular or italic), and font weight (ultralight to black) into the registered name of the font so that it may be loaded using `UIFont(name:, size:)`. (This registered font name may differ from the name of the font file and from the display name for the font family.) However, some font families may require custom behavior in order to properly load the font (e.g. the semibold font weight might be named "DemiBold" instead of the more common "SemiBold"). To support this you can declare a class or struct that conforms to the `FontFamily` protocol and use that to initialize your `Typography` instance. This protocol has four methods, each of which may be optionally overridden to customize how fonts of a given weight are loaded. The framework contains three different implementations of `FontFamily` for you to consider (`FontInfo`, `SystemFontFamily`, and `SFProFontFamily`).
172172

173173
In the event that the requested font cannot be loaded (either the name is incorrect or it was not registered), Y—MatterType will fall back to loading a system font of the specified point size and weight.
174174

Sources/YMatterType/Typography/FontFamily.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extension FontFamily {
7575
guard let font = UIFont(name: name, size: pointSize) else {
7676
// Fallback to system font and log a message.
7777
Typography.logger.warning("Custom font \(name) not properly installed.")
78-
return FontInfo.system.font(
78+
return Typography.systemFamily.font(
7979
for: weight,
8080
pointSize: pointSize,
8181
compatibleWith: traitCollection

Sources/YMatterType/Typography/SystemFontInfo.swift renamed to Sources/YMatterType/Typography/SystemFontFamily.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// SystemFontInfo.swift
2+
// SystemFontFamily.swift
33
// YMatterType
44
//
55
// Created by Mark Pospesel on 9/28/21.
@@ -34,13 +34,21 @@ public extension Typography.FontWeight {
3434
}
3535
}
3636

37-
public extension FontInfo {
37+
public extension Typography {
3838
/// Information about the system font family
39-
static let system: FontFamily = SystemFontInfo()
39+
static let systemFamily: FontFamily = SystemFontFamily()
40+
}
41+
42+
extension FontInfo {
43+
/// Information about the system font family
44+
///
45+
/// Renamed to `Typography.systemFamily`
46+
@available(*, deprecated, renamed: "Typography.systemFamily")
47+
static var system: FontFamily { Typography.systemFamily }
4048
}
4149

4250
/// Information about the system font. System font implementation of FontFamily.
43-
public struct SystemFontInfo: FontFamily {
51+
public struct SystemFontFamily: FontFamily {
4452
// The system font has a private font family name (literally ".SFUI"), so
4553
// just return empty string for familyName. The system font can't be retrieved by name anyway.
4654
public var familyName: String { "" }

Sources/YMatterType/Typography/Typography+System.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension Typography {
3939
) -> Typography {
4040
let lineHeight = ceil(fontSize * systemLineHeightMultiple)
4141
return Typography(
42-
fontFamily: FontInfo.system,
42+
fontFamily: Typography.systemFamily,
4343
fontWeight: weight,
4444
fontSize: fontSize,
4545
lineHeight: lineHeight,

Tests/YMatterTypeTests/Typography/FontFamilyTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class FontFamilyTests: XCTestCase {
6060
// This isn't a real font, so we expect it to fallback to the system font
6161
let (sut, _, _) = makeSUT()
6262
let font = sut.font(for: .regular, pointSize: 16, compatibleWith: .default)
63-
let systemFont = FontInfo.system.font(for: .regular, pointSize: 16, compatibleWith: .default)
63+
let systemFont = Typography.systemFamily.font(for: .regular, pointSize: 16, compatibleWith: .default)
6464
XCTAssertEqual(font.familyName, systemFont.familyName)
6565
XCTAssertEqual(font.fontName, systemFont.fontName)
6666
XCTAssertEqual(font.pointSize, systemFont.pointSize)

Tests/YMatterTypeTests/Typography/SystemFontInfoTests.swift renamed to Tests/YMatterTypeTests/Typography/SystemFontFamilyTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// SystemFontInfoTests.swift
2+
// SystemFontFamilyTests.swift
33
// YMatterTypeTests
44
//
55
// Created by Mark Pospesel on 9/28/21.
@@ -9,7 +9,7 @@
99
import XCTest
1010
@testable import YMatterType
1111

12-
final class SystemFontInfoTests: XCTestCase {
12+
final class SystemFontFamilyTests: XCTestCase {
1313
func testFont() throws {
1414
let (sut, pointSizes, traitCollections) = makeSUT()
1515
let systemFont = UIFont.systemFont(ofSize: 12)
@@ -34,10 +34,10 @@ final class SystemFontInfoTests: XCTestCase {
3434
// We use large tuples in makeSUT()
3535
// swiftlint:disable large_tuple
3636

37-
private extension SystemFontInfoTests {
37+
private extension SystemFontFamilyTests {
3838
func makeSUT() -> (FontFamily, [CGFloat], [UITraitCollection?]) {
3939
super.setUp()
40-
let sut = FontInfo.system
40+
let sut = Typography.systemFamily
4141
let pointSizes: [CGFloat] = [10, 12, 14, 16, 18, 24, 28, 32]
4242
let traitCollections: [UITraitCollection?] = [
4343
nil,

0 commit comments

Comments
 (0)