-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathFontBuilder.swift
46 lines (41 loc) · 1.48 KB
/
FontBuilder.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// FontBuilder.swift
// Eject
//
// Created by Brian King on 10/19/16.
// Copyright © 2016 Brian King. All rights reserved.
//
import Foundation
struct FontBuilder: Builder {
func lookupSize(name: String) -> String {
switch name {
case "button":
return "15"
default:
return "\(name) -- log a bug with this value!"
}
}
func buildElement(attributes: inout [String: String], document: XIBDocument, parent: Reference?) throws -> Reference? {
guard let parent = parent else { throw XIBParser.Error.needParent }
let key = try attributes.removeRequiredValue(forKey: "key")
let pointSize = try attributes.removeValue(forKey: "pointSize") ?? lookupSize(name: try attributes.removeRequiredValue(forKey: "size"))
let value: String
attributes.removeValue(forKey: "family")
// Not sure why, but the IB specifies a private key. Fix it up.
if let type = attributes.removeValue(forKey: "type") {
value = ".\(type)Font(ofSize: \(pointSize))"
}
else if let name = attributes.removeValue(forKey: "name") {
value = "UIFont(name: \"\(name)\", size: \(pointSize))"
}
else {
throw XIBParser.Error.unknown(attributes: attributes)
}
try document.addVariableConfiguration(
for: parent.identifier,
attribute: key,
value: BasicValue(value: value)
)
return parent
}
}