Skip to content

Commit 9e907ac

Browse files
Mark Pospeselmpospese
authored andcommitted
Rename FontRepresentable to FontFamily
1 parent d8b7982 commit 9e907ac

File tree

10 files changed

+34
-27
lines changed

10 files changed

+34
-27
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ 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 `FontRepresentable` 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 `FontRepresentable` 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`, `SystemFontInfo`, 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

175175
```
176-
struct AppleSDGothicNeoInfo: FontRepresentable {
176+
struct AppleSDGothicNeoInfo: FontFamily {
177177
/// Font family root name
178178
let familyName: String = "AppleSDGothicNeo"
179179

Sources/YMatterType/Typography/FontRepresentable.swift renamed to Sources/YMatterType/Typography/FontFamily.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// FontRepresentable.swift
2+
// FontFamily.swift
33
// YMatterType
44
//
55
// Created by Mark Pospesel on 8/23/21.
@@ -10,20 +10,20 @@ import UIKit
1010
import os
1111

1212
/// Information about a font family. When an app specifies a custom font, they will
13-
/// implement an instance of FontRepresentable to fully describe that font.
14-
public protocol FontRepresentable {
13+
/// implement an instance of FontFamily to fully describe that font.
14+
public protocol FontFamily {
1515
/// Font family root name, e.g. "AvenirNext"
1616
var familyName: String { get }
1717

1818
/// Optional suffix to use for the font name.
1919
///
20-
/// Used by `FontRepresentable.fontName(for:compatibleWith:)`
20+
/// Used by `FontFamily.fontName(for:compatibleWith:)`
2121
/// e.g. "Italic" is a typical suffix for italic fonts.
2222
/// default = ""
2323
var fontNameSuffix: String { get }
2424

2525
// The following four methods have default implementations that
26-
// can be overridden in custom implementations of FontRepresentable
26+
// can be overridden in custom implementations of FontFamily
2727

2828
/// Returns a font for the specified `weight` and `pointSize` that is compatible with the `traitCollection`
2929
/// - Parameters:
@@ -63,7 +63,7 @@ extension Typography {
6363

6464
// MARK: - Default implementations
6565

66-
extension FontRepresentable {
66+
extension FontFamily {
6767
public var fontNameSuffix: String { "" }
6868

6969
public func font(
@@ -156,3 +156,10 @@ extension FontRepresentable {
156156
return traitCollection.legibilityWeight == .bold
157157
}
158158
}
159+
160+
/// Information about a font family. When an app specifies a custom font, they will
161+
/// implement an instance of FontFamily to fully describe that font.
162+
///
163+
/// Renamed to `FontFamily`
164+
@available(*, deprecated, renamed: "FontFamily")
165+
public typealias FontRepresentable = FontFamily

Sources/YMatterType/Typography/FontInfo.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import UIKit
1010

11-
/// Information about a font family. Default implementation of FontRepresentable.
12-
public struct FontInfo: FontRepresentable {
11+
/// Information about a font family. Default implementation of FontFamily.
12+
public struct FontInfo: FontFamily {
1313
/// Suffix to use for italic family font names "Italic"
1414
public static let italicSuffix = "Italic"
1515

@@ -30,7 +30,7 @@ public struct FontInfo: FontRepresentable {
3030

3131
/// Optional suffix to use for the font name.
3232
///
33-
/// Used by `FontRepresentable.fontName(for:compatibleWith:)`
33+
/// Used by `FontFamily.fontName(for:compatibleWith:)`
3434
/// e.g. "Italic" is a typical suffix for italic fonts.
3535
/// default = ""
3636
public var fontNameSuffix: String {

Sources/YMatterType/Typography/SystemFontInfo.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public extension Typography.FontWeight {
3636

3737
public extension FontInfo {
3838
/// Information about the system font family
39-
static let system: FontRepresentable = SystemFontInfo()
39+
static let system: FontFamily = SystemFontInfo()
4040
}
4141

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

Sources/YMatterType/Typography/Typography+SFPro.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
/// Typographical information about Apple's SF family of fonts
12-
public struct SFProFontFamily: FontRepresentable {
12+
public struct SFProFontFamily: FontFamily {
1313
fileprivate enum SFProFamily {
1414
case display
1515
case displayItalic
@@ -72,7 +72,7 @@ public struct SFProFontFamily: FontRepresentable {
7272

7373
/// Optional suffix to use for the font name.
7474
///
75-
/// Used by `FontRepresentable.fontName(for:compatibleWith:)`
75+
/// Used by `FontFamily.fontName(for:compatibleWith:)`
7676
/// e.g. "Italic" is a typical suffix for italic fonts.
7777
/// default = ""
7878
public var fontNameSuffix: String {

Sources/YMatterType/Typography/Typography.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import UIKit
1111
/// Represents a font as it would appear in a design document
1212
public struct Typography {
1313
/// Information about the font family
14-
public let fontFamily: FontRepresentable
14+
public let fontFamily: FontFamily
1515
/// Font weight
1616
public let fontWeight: FontWeight
1717
/// Font size (aka point size)
@@ -48,7 +48,7 @@ public struct Typography {
4848
/// - textStyle: text style to use for scaling (defaults to `.body`)
4949
/// - isFixed: `true` if this font should never scale, `false` if it should scale (defaults to `.false`)
5050
public init(
51-
fontFamily: FontRepresentable,
51+
fontFamily: FontFamily,
5252
fontWeight: FontWeight,
5353
fontSize: CGFloat,
5454
lineHeight: CGFloat,

Tests/YMatterTypeTests/Typography/FontRepresentableTests.swift renamed to Tests/YMatterTypeTests/Typography/FontFamilyTests.swift

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

12-
final class FontRepresentableTests: XCTestCase {
12+
final class FontFamilyTests: XCTestCase {
1313
func testFontName() {
1414
let (sut, weightNames, traitCollection) = makeSUT()
1515
for weight in Typography.FontWeight.allCases {
@@ -93,12 +93,12 @@ final class FontRepresentableTests: XCTestCase {
9393
// We use large tuples in makeSUT()
9494
// swiftlint:disable large_tuple
9595

96-
private extension FontRepresentableTests {
96+
private extension FontFamilyTests {
9797
func makeSUT(
9898
file: StaticString = #filePath,
9999
line: UInt = #line
100-
) -> (FontRepresentable, [Typography.FontWeight: String], UITraitCollection) {
101-
let sut = MockFontRepresentable()
100+
) -> (FontFamily, [Typography.FontWeight: String], UITraitCollection) {
101+
let sut = MockFontFamily()
102102
let weightNames: [Typography.FontWeight: String] = [
103103
.ultralight: "ExtraLight",
104104
.thin: "Thin",
@@ -117,6 +117,6 @@ private extension FontRepresentableTests {
117117
}
118118
}
119119

120-
final class MockFontRepresentable: FontRepresentable {
120+
final class MockFontFamily: FontFamily {
121121
let familyName: String = "MockSerifMono"
122122
}

Tests/YMatterTypeTests/Typography/SystemFontInfoTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class SystemFontInfoTests: XCTestCase {
3535
// swiftlint:disable large_tuple
3636

3737
private extension SystemFontInfoTests {
38-
func makeSUT() -> (FontRepresentable, [CGFloat], [UITraitCollection?]) {
38+
func makeSUT() -> (FontFamily, [CGFloat], [UITraitCollection?]) {
3939
super.setUp()
4040
let sut = FontInfo.system
4141
let pointSizes: [CGFloat] = [10, 12, 14, 16, 18, 24, 28, 32]

Tests/YMatterTypeTests/Typography/Typography+FontTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ final class TypographyFontTests: XCTestCase {
157157
}
158158
}
159159

160-
struct AppleSDGothicNeoInfo: FontRepresentable {
160+
struct AppleSDGothicNeoInfo: FontFamily {
161161
let familyName: String = "AppleSDGothicNeo"
162162

163163
func weightName(for weight: Typography.FontWeight) -> String {

Tests/YMatterTypeTests/Typography/Typography+SFProTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class TypographySFProTests: XCTestCase {
4444
}
4545

4646
private extension TypographySFProTests {
47-
func _testFontFamily(_ fontFamily: FontRepresentable, style: Typography.FontStyle) {
47+
func _testFontFamily(_ fontFamily: FontFamily, style: Typography.FontStyle) {
4848
Typography.FontWeight.allCases.forEach {
4949
let typography = Typography(
5050
fontFamily: fontFamily,

0 commit comments

Comments
 (0)