mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-06-14 01:35:05 +08:00
61 lines
1.4 KiB
Swift
61 lines
1.4 KiB
Swift
//
|
|
// Font.swift
|
|
// StyledTextKit
|
|
//
|
|
// Created by Ryan Nystrom on 2/19/18.
|
|
// Copyright © 2018 Ryan Nystrom. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
public enum Font: Hashable, Equatable {
|
|
|
|
public enum SystemFont: Hashable, Equatable {
|
|
case `default`
|
|
case bold
|
|
case italic
|
|
case weighted(UIFont.Weight)
|
|
case monospaced(UIFont.Weight)
|
|
|
|
// MARK: Hashable
|
|
|
|
public var hashValue: Int {
|
|
switch self {
|
|
case .default: return 0
|
|
case .bold: return 1
|
|
case .italic: return 2
|
|
case .weighted(let weight): return weight.hashValue
|
|
case .monospaced(let weight): return weight.hashValue
|
|
}
|
|
}
|
|
|
|
// MARK: Equatable
|
|
|
|
public static func ==(lhs: SystemFont, rhs: SystemFont) -> Bool {
|
|
return lhs.hashValue == rhs.hashValue
|
|
}
|
|
|
|
}
|
|
|
|
case name(String)
|
|
case descriptor(UIFontDescriptor)
|
|
case system(SystemFont)
|
|
|
|
// MARK: Hashable
|
|
|
|
public var hashValue: Int {
|
|
switch self {
|
|
case .name(let name): return name.hashValue
|
|
case .descriptor(let descriptor): return descriptor.hashValue
|
|
case .system(let system): return system.hashValue
|
|
}
|
|
}
|
|
|
|
// MARK: Equatable
|
|
|
|
public static func ==(lhs: Font, rhs: Font) -> Bool {
|
|
return lhs.hashValue == rhs.hashValue
|
|
}
|
|
|
|
}
|