Skip to content

Commit 389d7c9

Browse files
Mark Pospeselmpospese
authored andcommitted
Add Font Family Factory
1 parent 0cc3326 commit 389d7c9

File tree

9 files changed

+96
-0
lines changed

9 files changed

+96
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// DefaultFontFamilyFactory.swift
3+
// YMatterType
4+
//
5+
// Created by Mark Pospesel on 9/21/22.
6+
// Copyright © 2022 Y Media Labs. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/// Returns a `DefaultFontFamily` given a font family name and style.
12+
public struct DefaultFontFamilyFactory {
13+
/// Initializes a default font family factory
14+
public init() { }
15+
}
16+
17+
extension DefaultFontFamilyFactory: FontFamilyFactory {
18+
/// Given a family name and style instantiates and returns a `DefaultFontFamily`
19+
/// - Parameters:
20+
/// - familyName: font family name
21+
/// - style: font style
22+
/// - Returns: a font family matching the family name and style
23+
public func getFontFamily(familyName: String, style: Typography.FontStyle) -> FontFamily {
24+
DefaultFontFamily(familyName: familyName, style: style)
25+
}
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// FontFamilyFactory.swift
3+
// YMatterType
4+
//
5+
// Created by Mark Pospesel on 9/21/22.
6+
// Copyright © 2022 Y Media Labs. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/// Returns a font family given a font family name and style.
12+
public protocol FontFamilyFactory {
13+
/// Given a family name and style returns a font family
14+
/// - Parameters:
15+
/// - familyName: font family name
16+
/// - style: font style
17+
/// - Returns: a font family matching the family name and style
18+
func getFontFamily(familyName: String, style: Typography.FontStyle) -> FontFamily
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// DefaultFontFamilyFactoryTests.swift
3+
// YMatterTypeTests
4+
//
5+
// Created by Mark Pospesel on 9/21/22.
6+
// Copyright © 2022 Y Media Labs. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import YMatterType
11+
12+
final class DefaultFontFamilyFactoryTests: XCTestCase {
13+
func testGetFontFamily() {
14+
// Given
15+
let sut = DefaultFontFamilyFactory()
16+
17+
// When
18+
let regular = sut.getFontFamily(familyName: "Foo", style: .regular)
19+
let italic = sut.getFontFamily(familyName: "Bar", style: .italic)
20+
21+
// Then
22+
XCTAssertTrue(regular is DefaultFontFamily)
23+
XCTAssertEqual(regular.familyName, "Foo")
24+
XCTAssertEqual(regular.fontNameSuffix, "")
25+
XCTAssertTrue(italic is DefaultFontFamily)
26+
XCTAssertEqual(italic.familyName, "Bar")
27+
XCTAssertEqual(italic.fontNameSuffix, "Italic")
28+
}
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// DefaultFontFamilyTests.swift
3+
// YMatterTypeTests
4+
//
5+
// Created by Mark Pospesel on 9/21/22.
6+
// Copyright © 2022 Y Media Labs. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import YMatterType
11+
12+
final class DefaultFontFamilyTests: XCTestCase {
13+
func testFontNameSuffix() {
14+
// Given
15+
let sut = DefaultFontFamily(familyName: "Mock", style: .regular)
16+
let sutItalic = DefaultFontFamily(familyName: "Mock", style: .italic)
17+
18+
// Then
19+
XCTAssertEqual(sut.fontNameSuffix, "")
20+
XCTAssertEqual(sutItalic.fontNameSuffix, "Italic")
21+
}
22+
}

0 commit comments

Comments
 (0)