Skip to content

Commit 0cc3326

Browse files
Mark Pospeselmpospese
authored andcommitted
Rename FontInfo to DefaultFontFamily
1 parent 95f725c commit 0cc3326

13 files changed

+51
-45
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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`, `SystemFontFamily`, 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 (`DefaultFontFamily`, `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/FontInfo.swift renamed to Sources/YMatterType/Typography/DefaultFontFamily.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// FontInfo.swift
2+
// DefaultFontFamily.swift
33
// YMatterType
44
//
55
// Created by Mark Pospesel on 8/23/21.
@@ -9,7 +9,7 @@
99
import UIKit
1010

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

@@ -19,7 +19,7 @@ public struct FontInfo: FontFamily {
1919
/// Font style, e.g. regular or italic
2020
public let style: Typography.FontStyle
2121

22-
/// Initialize a `FontInfo` object
22+
/// Initialize a `DefaultFontFamily` object
2323
/// - Parameters:
2424
/// - familyName: font family name
2525
/// - style: font style (default = `.regular`)
@@ -34,6 +34,12 @@ public struct FontInfo: FontFamily {
3434
/// e.g. "Italic" is a typical suffix for italic fonts.
3535
/// default = ""
3636
public var fontNameSuffix: String {
37-
(style == .italic) ? FontInfo.italicSuffix : ""
37+
(style == .italic) ? DefaultFontFamily.italicSuffix : ""
3838
}
3939
}
40+
41+
/// Information about a font family. Default implementation of FontFamily.
42+
///
43+
/// Renamed to `DefaultFontFamily`
44+
@available(*, deprecated, renamed: "DefaultFontFamily")
45+
public typealias FontInfo = DefaultFontFamily

Sources/YMatterType/Typography/SystemFontFamily.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public extension Typography {
3939
static let systemFamily: FontFamily = SystemFontFamily()
4040
}
4141

42-
extension FontInfo {
42+
extension DefaultFontFamily {
4343
/// Information about the system font family
4444
///
4545
/// Renamed to `Typography.systemFamily`

Sources/YMatterType/Typography/Typography+SFPro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public struct SFProFontFamily: FontFamily {
7676
/// e.g. "Italic" is a typical suffix for italic fonts.
7777
/// default = ""
7878
public var fontNameSuffix: String {
79-
(style == .italic) ? FontInfo.italicSuffix : ""
79+
(style == .italic) ? DefaultFontFamily.italicSuffix : ""
8080
}
8181
}
8282

Sources/YMatterType/Typography/Typography.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public struct Typography {
102102
isFixed: Bool = false
103103
) {
104104
self.init(
105-
fontFamily: FontInfo(familyName: familyName, style: fontStyle),
105+
fontFamily: DefaultFontFamily(familyName: familyName, style: fontStyle),
106106
fontWeight: fontWeight,
107107
fontSize: fontSize,
108108
lineHeight: lineHeight,

Tests/YMatterTypeTests/Elements/TypographyButtonTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ final class TypographyButtonTests: TypographyElementTests {
151151
sut.typography.lineHeight * 2 + sut.contentEdgeInsets.vertical
152152
)
153153

154-
let fontInfo = FontInfo(familyName: "Verdana")
154+
let fontFamily = DefaultFontFamily(familyName: "Verdana")
155155
let typography = Typography(
156-
fontFamily: fontInfo,
156+
fontFamily: fontFamily,
157157
fontWeight: .bold,
158158
fontSize: 18,
159159
lineHeight: 28,
@@ -184,9 +184,9 @@ final class TypographyButtonTests: TypographyElementTests {
184184

185185
func testMaximumPointSize() {
186186
let sut = makeSUT()
187-
let fontInfo = FontInfo(familyName: "Menlo")
187+
let fontFamily = DefaultFontFamily(familyName: "Menlo")
188188
let scaledType = Typography(
189-
fontFamily: fontInfo,
189+
fontFamily: fontFamily,
190190
fontWeight: .regular,
191191
fontSize: 16,
192192
lineHeight: 24,
@@ -229,9 +229,9 @@ final class TypographyButtonTests: TypographyElementTests {
229229

230230
func testMaximumScaleFactor() {
231231
let sut = makeSUT()
232-
let fontInfo = FontInfo(familyName: "Menlo")
232+
let fontFamily = DefaultFontFamily(familyName: "Menlo")
233233
let scaledType = Typography(
234-
fontFamily: fontInfo,
234+
fontFamily: fontFamily,
235235
fontWeight: .regular,
236236
fontSize: 16,
237237
lineHeight: 24,

Tests/YMatterTypeTests/Elements/TypographyLabelTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ final class TypographyLabelTests: TypographyElementTests {
135135
// we expect label height to be a multiple of the old lineHeight
136136
XCTAssertEqual(sut.intrinsicContentSize.height, sut.typography.lineHeight * 2)
137137

138-
let fontInfo = FontInfo(familyName: "Verdana")
138+
let fontFamily = DefaultFontFamily(familyName: "Verdana")
139139
let typography = Typography(
140-
fontFamily: fontInfo,
140+
fontFamily: fontFamily,
141141
fontWeight: .bold,
142142
fontSize: 18,
143143
lineHeight: 28,
@@ -163,9 +163,9 @@ final class TypographyLabelTests: TypographyElementTests {
163163

164164
func testMaximumPointSize() {
165165
let sut = makeSUT()
166-
let fontInfo = FontInfo(familyName: "Menlo")
166+
let fontFamily = DefaultFontFamily(familyName: "Menlo")
167167
let scaledType = Typography(
168-
fontFamily: fontInfo,
168+
fontFamily: fontFamily,
169169
fontWeight: .regular,
170170
fontSize: 16,
171171
lineHeight: 18,
@@ -204,9 +204,9 @@ final class TypographyLabelTests: TypographyElementTests {
204204

205205
func testMaximumScaleFactor() {
206206
let sut = makeSUT()
207-
let fontInfo = FontInfo(familyName: "Menlo")
207+
let fontFamily = DefaultFontFamily(familyName: "Menlo")
208208
let scaledType = Typography(
209-
fontFamily: fontInfo,
209+
fontFamily: fontFamily,
210210
fontWeight: .regular,
211211
fontSize: 16,
212212
lineHeight: 18,

Tests/YMatterTypeTests/Elements/TypographyTextFieldTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ final class TypographyTextFieldTests: TypographyElementTests {
7474
// we expect text field height to equal the old lineHeight
7575
XCTAssertEqual(sut.intrinsicContentSize.height, sut.typography.lineHeight)
7676

77-
let fontInfo = FontInfo(familyName: "Verdana")
77+
let fontFamily = DefaultFontFamily(familyName: "Verdana")
7878
let typography = Typography(
79-
fontFamily: fontInfo,
79+
fontFamily: fontFamily,
8080
fontWeight: .bold,
8181
fontSize: 18,
8282
lineHeight: 28,
@@ -200,9 +200,9 @@ final class TypographyTextFieldTests: TypographyElementTests {
200200
XCTAssertEqual(sut.intrinsicContentSize.height, sut.typography.lineHeight)
201201

202202
// changing the typograhy will restyle the attributed text
203-
let fontInfo = FontInfo(familyName: "Verdana")
203+
let fontFamily = DefaultFontFamily(familyName: "Verdana")
204204
sut.typography = Typography(
205-
fontFamily: fontInfo,
205+
fontFamily: fontFamily,
206206
fontWeight: .bold,
207207
fontSize: 18,
208208
lineHeight: 28,

Tests/YMatterTypeTests/Elements/TypographyTextViewTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ final class TypographyTextViewTests: TypographyElementTests {
100100
// we expect label height to be a multiple of the old lineHeight
101101
XCTAssertEqual(sut.intrinsicContentSize.height, sut.typography.lineHeight * 2)
102102

103-
let fontInfo = FontInfo(familyName: "Verdana")
103+
let fontFamily = DefaultFontFamily(familyName: "Verdana")
104104
let typography = Typography(
105-
fontFamily: fontInfo,
105+
fontFamily: fontFamily,
106106
fontWeight: .bold,
107107
fontSize: 18,
108108
lineHeight: 28,
@@ -128,9 +128,9 @@ final class TypographyTextViewTests: TypographyElementTests {
128128

129129
func testMaximumPointSize() {
130130
let sut = makeSUT()
131-
let fontInfo = FontInfo(familyName: "Menlo")
131+
let fontFamily = DefaultFontFamily(familyName: "Menlo")
132132
let scaledType = Typography(
133-
fontFamily: fontInfo,
133+
fontFamily: fontFamily,
134134
fontWeight: .regular,
135135
fontSize: 16,
136136
lineHeight: 18,
@@ -168,9 +168,9 @@ final class TypographyTextViewTests: TypographyElementTests {
168168

169169
func testMaximumScaleFactor() {
170170
let sut = makeSUT()
171-
let fontInfo = FontInfo(familyName: "Menlo")
171+
let fontFamily = DefaultFontFamily(familyName: "Menlo")
172172
let scaledType = Typography(
173-
fontFamily: fontInfo,
173+
fontFamily: fontFamily,
174174
fontWeight: .regular,
175175
fontSize: 16,
176176
lineHeight: 18,

Tests/YMatterTypeTests/Typography/TypogaphyTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import XCTest
1212
final class TypogaphyTests: XCTestCase {
1313
func testInit() {
1414
// test the default initializer
15-
let avenir = FontInfo(familyName: "AvenirNext")
15+
let avenir = DefaultFontFamily(familyName: "AvenirNext")
1616
let typeInfo = Typography(fontFamily: avenir, fontWeight: .bold, fontSize: 16, lineHeight: 24)
1717

1818
XCTAssertNotNil(typeInfo.generateLayout(compatibleWith: .default))

0 commit comments

Comments
 (0)