mastodon-app-ufficiale-ipho.../MastodonSDK/Sources/MastodonAsset/Generated/Fonts.swift

128 lines
3.8 KiB
Swift
Raw Normal View History

// swiftlint:disable all
// Generated using SwiftGen https://github.com/SwiftGen/SwiftGen
2022-11-14 18:44:28 +01:00
#if os(macOS)
2022-02-08 05:36:06 +01:00
import AppKit.NSFont
#elseif os(iOS) || os(tvOS) || os(watchOS)
import UIKit.UIFont
#endif
2022-11-14 18:44:28 +01:00
#if canImport(SwiftUI)
import SwiftUI
#endif
2022-02-08 05:36:06 +01:00
// Deprecated typealiases
@available(*, deprecated, renamed: "FontConvertible.Font", message: "This typealias will be removed in SwiftGen 7.0")
public typealias Font = FontConvertible.Font
2022-11-14 18:44:28 +01:00
// swiftlint:disable superfluous_disable_command file_length implicit_return
2022-02-08 05:36:06 +01:00
// MARK: - Fonts
// swiftlint:disable identifier_name line_length type_body_length
public enum FontFamily {
public enum Staatliches {
public static let regular = FontConvertible(name: "Staatliches-Regular", family: "Staatliches", path: "Staatliches-Regular.ttf")
public static let all: [FontConvertible] = [regular]
}
public static let allCustomFonts: [FontConvertible] = [Staatliches.all].flatMap { $0 }
public static func registerAllCustomFonts() {
allCustomFonts.forEach { $0.register() }
}
}
// swiftlint:enable identifier_name line_length type_body_length
// MARK: - Implementation Details
public struct FontConvertible {
public let name: String
public let family: String
public let path: String
2022-11-14 18:44:28 +01:00
#if os(macOS)
2022-02-08 05:36:06 +01:00
public typealias Font = NSFont
#elseif os(iOS) || os(tvOS) || os(watchOS)
public typealias Font = UIFont
#endif
public func font(size: CGFloat) -> Font {
guard let font = Font(font: self, size: size) else {
fatalError("Unable to initialize font '\(name)' (\(family))")
}
return font
}
2022-11-14 18:44:28 +01:00
#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
public func swiftUIFont(size: CGFloat) -> SwiftUI.Font {
return SwiftUI.Font.custom(self, size: size)
}
@available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, *)
public func swiftUIFont(fixedSize: CGFloat) -> SwiftUI.Font {
return SwiftUI.Font.custom(self, fixedSize: fixedSize)
}
@available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, *)
public func swiftUIFont(size: CGFloat, relativeTo textStyle: SwiftUI.Font.TextStyle) -> SwiftUI.Font {
return SwiftUI.Font.custom(self, size: size, relativeTo: textStyle)
}
#endif
2022-02-08 05:36:06 +01:00
public func register() {
// swiftlint:disable:next conditional_returns_on_newline
guard let url = url else { return }
CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil)
}
2022-11-14 18:44:28 +01:00
fileprivate func registerIfNeeded() {
#if os(iOS) || os(tvOS) || os(watchOS)
if !UIFont.fontNames(forFamilyName: family).contains(name) {
register()
}
#elseif os(macOS)
if let url = url, CTFontManagerGetScopeForURL(url as CFURL) == .none {
register()
}
#endif
}
2022-02-08 05:36:06 +01:00
fileprivate var url: URL? {
// swiftlint:disable:next implicit_return
return Bundle.module.url(forResource: path, withExtension: nil)
}
}
public extension FontConvertible.Font {
convenience init?(font: FontConvertible, size: CGFloat) {
2022-11-14 18:44:28 +01:00
font.registerIfNeeded()
2022-02-08 05:36:06 +01:00
self.init(name: font.name, size: size)
}
}
2022-11-14 18:44:28 +01:00
#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
public extension SwiftUI.Font {
static func custom(_ font: FontConvertible, size: CGFloat) -> SwiftUI.Font {
font.registerIfNeeded()
return custom(font.name, size: size)
}
}
@available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, *)
public extension SwiftUI.Font {
static func custom(_ font: FontConvertible, fixedSize: CGFloat) -> SwiftUI.Font {
font.registerIfNeeded()
return custom(font.name, fixedSize: fixedSize)
}
static func custom(
_ font: FontConvertible,
size: CGFloat,
relativeTo textStyle: SwiftUI.Font.TextStyle
) -> SwiftUI.Font {
font.registerIfNeeded()
return custom(font.name, size: size, relativeTo: textStyle)
}
}
#endif