diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index a1c17e88..89f08ed4 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -27,6 +27,17 @@ EA3361C328902D960071C351 /* VDSToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361C228902D960071C351 /* VDSToggle.swift */; }; EA3361C5289030FC0071C351 /* Accessable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361C4289030FC0071C351 /* Accessable.swift */; }; EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361C8289054C50071C351 /* Surfaceable.swift */; }; + EA3361E12891D1110071C351 /* TypographyProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361E02891D1110071C351 /* TypographyProtocol.swift */; }; + EA3361E32891D1860071C351 /* FontWeight.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3361E22891D1860071C351 /* FontWeight.swift */; }; + EA3361F42891D5290071C351 /* VDSTypographyTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA3361F32891D5290071C351 /* VDSTypographyTokens.xcframework */; }; + EA3362042891E14D0071C351 /* VerizonNHGeTX-Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = EA3362002891E14C0071C351 /* VerizonNHGeTX-Bold.otf */; }; + EA3362052891E14D0071C351 /* VerizonNHGeDS-Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = EA3362012891E14D0071C351 /* VerizonNHGeDS-Bold.otf */; }; + EA3362062891E14D0071C351 /* VerizonNHGeTX-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = EA3362022891E14D0071C351 /* VerizonNHGeTX-Regular.otf */; }; + EA3362072891E14D0071C351 /* VerizonNHGeDS-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = EA3362032891E14D0071C351 /* VerizonNHGeDS-Regular.otf */; }; + EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33622B2891E73B0071C351 /* FontProtocol.swift */; }; + EA33622E2891EA3C0071C351 /* DispatchQueue+Once.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33622D2891EA3C0071C351 /* DispatchQueue+Once.swift */; }; + EA3362302891EB4A0071C351 /* VDSFonts.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33622F2891EB4A0071C351 /* VDSFonts.swift */; }; + EA3362322891F2ED0071C351 /* VDSFontStyles.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3362312891F2ED0071C351 /* VDSFontStyles.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -61,6 +72,17 @@ EA3361C228902D960071C351 /* VDSToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSToggle.swift; sourceTree = ""; }; EA3361C4289030FC0071C351 /* Accessable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Accessable.swift; sourceTree = ""; }; EA3361C8289054C50071C351 /* Surfaceable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Surfaceable.swift; sourceTree = ""; }; + EA3361E02891D1110071C351 /* TypographyProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypographyProtocol.swift; sourceTree = ""; }; + EA3361E22891D1860071C351 /* FontWeight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontWeight.swift; sourceTree = ""; }; + EA3361F32891D5290071C351 /* VDSTypographyTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSTypographyTokens.xcframework; path = ../SharedFrameworks/VDSTypographyTokens.xcframework; sourceTree = ""; }; + EA3362002891E14C0071C351 /* VerizonNHGeTX-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGeTX-Bold.otf"; sourceTree = ""; }; + EA3362012891E14D0071C351 /* VerizonNHGeDS-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGeDS-Bold.otf"; sourceTree = ""; }; + EA3362022891E14D0071C351 /* VerizonNHGeTX-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGeTX-Regular.otf"; sourceTree = ""; }; + EA3362032891E14D0071C351 /* VerizonNHGeDS-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGeDS-Regular.otf"; sourceTree = ""; }; + EA33622B2891E73B0071C351 /* FontProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontProtocol.swift; sourceTree = ""; }; + EA33622D2891EA3C0071C351 /* DispatchQueue+Once.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+Once.swift"; sourceTree = ""; }; + EA33622F2891EB4A0071C351 /* VDSFonts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSFonts.swift; sourceTree = ""; }; + EA3362312891F2ED0071C351 /* VDSFontStyles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSFontStyles.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -69,6 +91,7 @@ buildActionMask = 2147483647; files = ( EA336195288B1C420071C351 /* VDSColorTokens.xcframework in Frameworks */, + EA3361F42891D5290071C351 /* VDSTypographyTokens.xcframework in Frameworks */, EA336197288B1C420071C351 /* VDSFormControlsTokens.xcframework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -106,13 +129,15 @@ EA33616E288B19200071C351 /* VDS */ = { isa = PBXGroup; children = ( - EA336170288B19200071C351 /* VDS.docc */, - EA33616F288B19200071C351 /* VDS.h */, EA3361B4288B2A360071C351 /* BaseClasses */, EA33619D288B1E330071C351 /* Components */, EA3361A6288B23240071C351 /* Extensions */, EA3361AB288B25EC0071C351 /* Protocols */, + EA3361DF2891D0F10071C351 /* Typography */, EA3361B9288B2BE30071C351 /* Utilities */, + EA3361FE2891E14C0071C351 /* SupportingFiles */, + EA336170288B19200071C351 /* VDS.docc */, + EA33616F288B19200071C351 /* VDS.h */, ); path = VDS; sourceTree = ""; @@ -128,6 +153,7 @@ EA33618D288B1C0C0071C351 /* Frameworks */ = { isa = PBXGroup; children = ( + EA3361F32891D5290071C351 /* VDSTypographyTokens.xcframework */, EA33618E288B1C0C0071C351 /* VDSColorTokens.xcframework */, EA33618F288B1C0C0071C351 /* VDSFormControlsTokens.xcframework */, ); @@ -155,6 +181,7 @@ isa = PBXGroup; children = ( EA3361A7288B23300071C351 /* UIColor.swift */, + EA33622D2891EA3C0071C351 /* DispatchQueue+Once.swift */, ); path = Extensions; sourceTree = ""; @@ -191,6 +218,37 @@ path = Utilities; sourceTree = ""; }; + EA3361DF2891D0F10071C351 /* Typography */ = { + isa = PBXGroup; + children = ( + EA33622F2891EB4A0071C351 /* VDSFonts.swift */, + EA3362312891F2ED0071C351 /* VDSFontStyles.swift */, + EA3361E02891D1110071C351 /* TypographyProtocol.swift */, + EA3361E22891D1860071C351 /* FontWeight.swift */, + EA33622B2891E73B0071C351 /* FontProtocol.swift */, + ); + path = Typography; + sourceTree = ""; + }; + EA3361FE2891E14C0071C351 /* SupportingFiles */ = { + isa = PBXGroup; + children = ( + EA3361FF2891E14C0071C351 /* Fonts */, + ); + path = SupportingFiles; + sourceTree = ""; + }; + EA3361FF2891E14C0071C351 /* Fonts */ = { + isa = PBXGroup; + children = ( + EA3362002891E14C0071C351 /* VerizonNHGeTX-Bold.otf */, + EA3362012891E14D0071C351 /* VerizonNHGeDS-Bold.otf */, + EA3362022891E14D0071C351 /* VerizonNHGeTX-Regular.otf */, + EA3362032891E14D0071C351 /* VerizonNHGeDS-Regular.otf */, + ); + path = Fonts; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -283,6 +341,10 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + EA3362042891E14D0071C351 /* VerizonNHGeTX-Bold.otf in Resources */, + EA3362072891E14D0071C351 /* VerizonNHGeDS-Regular.otf in Resources */, + EA3362062891E14D0071C351 /* VerizonNHGeTX-Regular.otf in Resources */, + EA3362052891E14D0071C351 /* VerizonNHGeDS-Bold.otf in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -300,8 +362,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + EA3362322891F2ED0071C351 /* VDSFontStyles.swift in Sources */, EA3361C328902D960071C351 /* VDSToggle.swift in Sources */, + EA33622E2891EA3C0071C351 /* DispatchQueue+Once.swift in Sources */, EA3361C5289030FC0071C351 /* Accessable.swift in Sources */, + EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */, EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */, EA3361A2288B1E840071C351 /* VDSToggleModel.swift in Sources */, EA3361BD288B2C760071C351 /* TypeAlias.swift in Sources */, @@ -310,8 +375,11 @@ EA336171288B19200071C351 /* VDS.docc in Sources */, EA3361AA288B25E40071C351 /* Disabling.swift in Sources */, EA3361B6288B2A410071C351 /* Control.swift in Sources */, + EA3361E32891D1860071C351 /* FontWeight.swift in Sources */, EA3361B1288B26490071C351 /* Invertable.swift in Sources */, EA3361AD288B26190071C351 /* DataTrackable.swift in Sources */, + EA3361E12891D1110071C351 /* TypographyProtocol.swift in Sources */, + EA3362302891EB4A0071C351 /* VDSFonts.swift in Sources */, EA3361B8288B2AAA0071C351 /* ViewProtocol.swift in Sources */, EA3361BF288B2EA60071C351 /* Modelable.swift in Sources */, EA3361A8288B23300071C351 /* UIColor.swift in Sources */, diff --git a/VDS/Extensions/DispatchQueue+Once.swift b/VDS/Extensions/DispatchQueue+Once.swift new file mode 100644 index 00000000..092500cf --- /dev/null +++ b/VDS/Extensions/DispatchQueue+Once.swift @@ -0,0 +1,42 @@ +// +// DispatchQueue+Once.swift +// VDS +// +// Created by Matt Bruce on 7/27/22. +// + +import Foundation + +extension DispatchQueue { + private static var _onceTracker = [String]() + + public class func once( + file: String = #file, + function: String = #function, + line: Int = #line, + block: () -> Void + ) { + let token = "\(file):\(function):\(line)" + once(token: token, block: block) + } + + /** + Executes a block of code, associated with a unique token, only once. The code is thread safe and will + only execute the code once even in the presence of multithreaded calls. + + - parameter token: A unique reverse DNS style name such as com.vectorform. or a GUID + - parameter block: Block to execute once + */ + public class func once( + token: String, + block: () -> Void + ) { + objc_sync_enter(self) + defer { objc_sync_exit(self) } + + guard !_onceTracker.contains(token) else { return } + + _onceTracker.append(token) + block() + } +} diff --git a/VDS/SupportingFiles/Fonts/VerizonNHGeDS-Bold.otf b/VDS/SupportingFiles/Fonts/VerizonNHGeDS-Bold.otf new file mode 100755 index 00000000..dd3476af Binary files /dev/null and b/VDS/SupportingFiles/Fonts/VerizonNHGeDS-Bold.otf differ diff --git a/VDS/SupportingFiles/Fonts/VerizonNHGeDS-Regular.otf b/VDS/SupportingFiles/Fonts/VerizonNHGeDS-Regular.otf new file mode 100755 index 00000000..ce34c596 Binary files /dev/null and b/VDS/SupportingFiles/Fonts/VerizonNHGeDS-Regular.otf differ diff --git a/VDS/SupportingFiles/Fonts/VerizonNHGeTX-Bold.otf b/VDS/SupportingFiles/Fonts/VerizonNHGeTX-Bold.otf new file mode 100755 index 00000000..59b1f438 Binary files /dev/null and b/VDS/SupportingFiles/Fonts/VerizonNHGeTX-Bold.otf differ diff --git a/VDS/SupportingFiles/Fonts/VerizonNHGeTX-Regular.otf b/VDS/SupportingFiles/Fonts/VerizonNHGeTX-Regular.otf new file mode 100755 index 00000000..13d202d1 Binary files /dev/null and b/VDS/SupportingFiles/Fonts/VerizonNHGeTX-Regular.otf differ diff --git a/VDS/Typography/FontProtocol.swift b/VDS/Typography/FontProtocol.swift new file mode 100644 index 00000000..f915d31d --- /dev/null +++ b/VDS/Typography/FontProtocol.swift @@ -0,0 +1,52 @@ +// +// FontStyle.swift +// VDS +// +// Created by Matt Bruce on 7/27/22. +// + +import Foundation +import UIKit + +public protocol FontProtocol: CaseIterable, RawRepresentable, Hashable { + var fontFileExtension: String { get } + var fontName: String { get } +} + +extension FontProtocol { + + public func register() { + guard let bundle = Bundle(identifier: "com.verizon.vega.metrics") else { return } + Self.allCases.forEach{ font in + if let url = bundle.url(forResource: font.fontName, withExtension: font.fontFileExtension){ + do{ + try Self.register(from: url) + } catch{ + //DLog("Font called \(font.fontName).\(font.fontFileExtension) couldn't be registered") + } + } else { + //DLog("Font for FontStyle: \(font) couldn't be found") + } + } + } + + public static func register(from url: URL) throws { + guard let fontDataProvider = CGDataProvider(url: url as CFURL) else { + throw NSError(domain: "www.verizon.com", code: 123, userInfo: ["description":"Could not create font data provider for \(url)."]) + } + let font = CGFont(fontDataProvider) + var error: Unmanaged? + guard CTFontManagerRegisterGraphicsFont(font!, &error) else { + throw error!.takeUnretainedValue() + } + } + + public func font(ofSize size: CGFloat) -> UIFont{ + DispatchQueue.once(block: { self.register() }) + if let font = UIFont(name: self.fontName, size: size){ + return UIFontMetrics.default.scaledFont(for: font) + } else { + return UIFontMetrics.default.scaledFont(for: UIFont.systemFont(ofSize: size)) + } + } +} diff --git a/VDS/Typography/FontWeight.swift b/VDS/Typography/FontWeight.swift new file mode 100644 index 00000000..bd890924 --- /dev/null +++ b/VDS/Typography/FontWeight.swift @@ -0,0 +1,23 @@ +// +// FontWeight.swift +// VDS +// +// Created by Matt Bruce on 7/27/22. +// + +import Foundation +import UIKit +import VDSTypographyTokens + +public struct Typography { + + public enum FontWeight: String, Codable { + case regular, bold + } + + public enum Letterspacing: String, Codable { + case tight, wide + } + +} + diff --git a/VDS/Typography/TypographyProtocol.swift b/VDS/Typography/TypographyProtocol.swift new file mode 100644 index 00000000..5606fd56 --- /dev/null +++ b/VDS/Typography/TypographyProtocol.swift @@ -0,0 +1,192 @@ +// +// TypographyProtocol.swift +// VDS +// +// Created by Matt Bruce on 7/27/22. +// + +import Foundation +import VDSTypographyTokens + +public protocol XXLFontable { + static var xxlBold: UIFont { get } + static var xxlRegular: UIFont { get } +} + +public protocol XLFontable { + static var xlBold: UIFont { get } + static var xlRegular: UIFont { get } +} + +public protocol LargeFontable { + static var largeBold: UIFont { get } + static var largeRegular: UIFont { get } +} + +public protocol MediumFontable { + static var mediumBold: UIFont { get } + static var mediumRegular: UIFont { get } +} + +public protocol SmallFontable { + static var smallBold: UIFont { get } + static var smallRegular: UIFont { get } +} + +public protocol XSmallFontable { + static var xsmallBold: UIFont { get } + static var xsmallRegular: UIFont { get } +} + +public protocol FeatureTypograhyProtocol: XLFontable, LargeFontable, MediumFontable, SmallFontable, XSmallFontable {} + +public protocol TitleTypograhyProtocol: XXLFontable, XLFontable, LargeFontable, MediumFontable, SmallFontable {} + +public protocol BodyTypograhyProtocol: LargeFontable, MediumFontable, SmallFontable {} + +public protocol MicroTypographyProtocol { + static var bold: UIFont { get } + static var regular: UIFont { get } +} + +//public struct VDSFontStyles { +// public enum Feature: FeatureTypograhyProtocol { +// +// private static func getFont(vdsFont: VDSFonts, size: AvailableSize) -> UIFont { +// switch size { +// case .xlarge: +// return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature144 : VDSTypography.fontSizeFeature96) +// case .large: +// return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature128 : VDSTypography.fontSizeFeature80) +// case .medium: +// return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature96 : VDSTypography.fontSizeFeature64) +// case .small: +// return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature80 : VDSTypography.fontSizeFeature48) +// case .xsmall: +// return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature64 : VDSTypography.fontSizeFeature40) +// } +// } +// +// public static var xlBold: UIFont { +// return VDSFonts.dsBold.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature144 : VDSTypography.fontSizeFeature96) +// } +// +// public static var xlRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature144 : VDSTypography.fontSizeFeature96) +// } +// +// public static var largeBold: UIFont{ +// return VDSFonts.dsBold.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature128 : VDSTypography.fontSizeFeature80) +// } +// +// public static var largeRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature128 : VDSTypography.fontSizeFeature80) +// } +// +// public static var mediumBold: UIFont{ +// return VDSFonts.dsBold.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature96 : VDSTypography.fontSizeFeature64) +// } +// +// public static var mediumRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature96 : VDSTypography.fontSizeFeature64) +// } +// +// public static var smallBold: UIFont{ +// return VDSFonts.dsBold.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature80 : VDSTypography.fontSizeFeature48) +// } +// +// public static var smallRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature80 : VDSTypography.fontSizeFeature48) +// } +// +// public static var xsmallBold: UIFont{ +// return VDSFonts.dsBold.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature64 : VDSTypography.fontSizeFeature40) +// } +// +// public static var xsmallRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature64 : VDSTypography.fontSizeFeature40) +// } +// } +// +// public enum Title: TitleTypograhyProtocol { +// +// public static var xxlBold: UIFont { +// return VDSFonts.dsBold.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle64 : VDSTypography.fontSizeTitle40) +// } +// +// public static var xxlRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle64 : VDSTypography.fontSizeTitle40) +// } +// +// public static var xlBold: UIFont { +// return VDSFonts.dsBold.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle48 : VDSTypography.fontSizeTitle32) +// } +// +// public static var xlRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle48 : VDSTypography.fontSizeTitle32) +// } +// +// public static var largeBold: UIFont{ +// return VDSFonts.dsBold.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle32 : VDSTypography.fontSizeTitle24) +// } +// +// public static var largeRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle32 : VDSTypography.fontSizeTitle24) +// } +// +// public static var mediumBold: UIFont{ +// return VDSFonts.dsBold.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle24 : VDSTypography.fontSizeTitle20) +// } +// +// public static var mediumRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle24 : VDSTypography.fontSizeTitle20) +// } +// +// public static var smallBold: UIFont{ +// return VDSFonts.dsBold.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle20 : VDSTypography.fontSizeTitle16) +// } +// +// public static var smallRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle20 : VDSTypography.fontSizeTitle16) +// } +// +// } +// +// public enum Body: BodyTypograhyProtocol { +// public static var largeBold: UIFont { +// return VDSFonts.dsBold.font(ofSize: VDSTypography.fontSizeBody16) +// } +// +// public static var largeRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: VDSTypography.fontSizeBody16) +// } +// +// public static var mediumBold: UIFont{ +// return VDSFonts.dsBold.font(ofSize: VDSTypography.fontSizeBody14) +// } +// +// public static var mediumRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: VDSTypography.fontSizeBody14) +// } +// +// public static var smallBold: UIFont{ +// return VDSFonts.dsBold.font(ofSize: VDSTypography.fontSizeBody12) +// } +// +// public static var smallRegular: UIFont{ +// return VDSFonts.dsRegular.font(ofSize: VDSTypography.fontSizeBody12) +// } +// +// +// } +// +// public enum Micro: MicroTypographyProtocol { +// public static var bold: UIFont { +// return VDSFonts.txBold.font(ofSize: VDSTypography.fontSizeMicro11) +// } +// +// public static var regular: UIFont { +// return VDSFonts.txRegular.font(ofSize: VDSTypography.fontSizeMicro11) +// } +// } +//} diff --git a/VDS/Typography/VDSFontStyles.swift b/VDS/Typography/VDSFontStyles.swift new file mode 100644 index 00000000..1de2cf73 --- /dev/null +++ b/VDS/Typography/VDSFontStyles.swift @@ -0,0 +1,140 @@ +// +// VDSFontStyles.swift +// VDS +// +// Created by Matt Bruce on 7/27/22. +// + +import Foundation +import UIKit +import VDSTypographyTokens + +public struct VDSFontStyles { + + public enum Feature { + + private enum AvailableSize{ + case xlarge, large, medium, small, xsmall + } + + private static func getFont(vdsFont: VDSFonts, size: AvailableSize) -> UIFont { + switch size { + case .xlarge: + return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature144 : VDSTypography.fontSizeFeature96) + case .large: + return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature128 : VDSTypography.fontSizeFeature80) + case .medium: + return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature96 : VDSTypography.fontSizeFeature64) + case .small: + return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature80 : VDSTypography.fontSizeFeature48) + case .xsmall: + return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeFeature64 : VDSTypography.fontSizeFeature40) + } + } + + public enum Bold { + public static let xlarge = getFont(vdsFont: VDSFonts.dsBold, size: .xlarge) + public static let large = getFont(vdsFont: VDSFonts.dsBold, size: .large) + public static let medium = getFont(vdsFont: VDSFonts.dsBold, size: .medium) + public static let small = getFont(vdsFont: VDSFonts.dsBold, size: .small) + public static let xsmall = getFont(vdsFont: VDSFonts.dsBold, size: .xsmall) + } + + public enum Regular { + public static let xlarge = getFont(vdsFont: VDSFonts.dsRegular, size: .xlarge) + public static let large = getFont(vdsFont: VDSFonts.dsRegular, size: .large) + public static let medium = getFont(vdsFont: VDSFonts.dsRegular, size: .medium) + public static let small = getFont(vdsFont: VDSFonts.dsRegular, size: .small) + public static let xsmall = getFont(vdsFont: VDSFonts.dsRegular, size: .xsmall) + } + } + + public enum Title { + + private enum AvailableSize{ + case xxlarge, xlarge, large, medium, small + } + + private static func getFont(vdsFont: VDSFonts, size: AvailableSize) -> UIFont { + switch size { + case .xxlarge: + return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle64 : VDSTypography.fontSizeTitle40) + case .xlarge: + return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle48 : VDSTypography.fontSizeTitle32) + case .large: + return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle32 : VDSTypography.fontSizeTitle24) + case .medium: + return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle24 : VDSTypography.fontSizeTitle20) + case .small: + return vdsFont.font(ofSize: UIDevice.isIPad ? VDSTypography.fontSizeTitle20 : VDSTypography.fontSizeTitle16) + } + } + + public enum Bold { + public static let xxlarge = getFont(vdsFont: VDSFonts.dsBold, size: .xxlarge) + public static let xlarge = getFont(vdsFont: VDSFonts.dsBold, size: .xlarge) + public static let large = getFont(vdsFont: VDSFonts.dsBold, size: .large) + public static let medium = getFont(vdsFont: VDSFonts.dsBold, size: .medium) + public static let small = getFont(vdsFont: VDSFonts.dsBold, size: .small) + } + + public enum Regular { + public static let xxlarge = getFont(vdsFont: VDSFonts.dsBold, size: .xxlarge) + public static let xlarge = getFont(vdsFont: VDSFonts.dsRegular, size: .xlarge) + public static let large = getFont(vdsFont: VDSFonts.dsRegular, size: .large) + public static let medium = getFont(vdsFont: VDSFonts.dsRegular, size: .medium) + public static let small = getFont(vdsFont: VDSFonts.dsRegular, size: .small) + } + + } + + public enum Body { + + private enum AvailableSize{ + case large, medium, small + } + + private static func getFont(vdsFont: VDSFonts, size: AvailableSize) -> UIFont { + switch size { + case .large: + return vdsFont.font(ofSize: VDSTypography.fontSizeBody16) + case .medium: + return vdsFont.font(ofSize: VDSTypography.fontSizeBody14) + case .small: + return vdsFont.font(ofSize: VDSTypography.fontSizeBody12) + } + } + + public enum Bold { + public static let large = getFont(vdsFont: VDSFonts.dsBold, size: .large) + public static let medium = getFont(vdsFont: VDSFonts.dsBold, size: .medium) + public static let small = getFont(vdsFont: VDSFonts.dsBold, size: .small) + } + + public enum Regular { + public static let large = getFont(vdsFont: VDSFonts.dsRegular, size: .large) + public static let medium = getFont(vdsFont: VDSFonts.dsRegular, size: .medium) + public static let small = getFont(vdsFont: VDSFonts.dsRegular, size: .small) + } + } + + public enum Micro: MicroTypographyProtocol { + private static func getFont(vdsFont: VDSFonts) -> UIFont { + return vdsFont.font(ofSize: VDSTypography.fontSizeMicro11) + } + + public static var bold: UIFont { + return getFont(vdsFont: .txBold) + } + + public static var regular: UIFont { + return getFont(vdsFont: .txRegular) + } + } +} + +extension UIDevice { + static var isIPad: Bool { + UIDevice.current.userInterfaceIdiom == .pad + } +} diff --git a/VDS/Typography/VDSFonts.swift b/VDS/Typography/VDSFonts.swift new file mode 100644 index 00000000..669a0264 --- /dev/null +++ b/VDS/Typography/VDSFonts.swift @@ -0,0 +1,32 @@ +// +// Fonts.swift +// VDS +// +// Created by Matt Bruce on 7/27/22. +// + +import Foundation + +public enum VDSFonts: String, FontProtocol { + case dsBold + case dsRegular + case txBold + case txRegular + + public var fontName: String { + switch self { + case .dsBold: + return "VerizonNHGeDS-Bold" + case .dsRegular: + return "VerizonNHGeDS-Regular" + case .txBold: + return "VerizonNHGeTX-Bold" + case .txRegular: + return "VerizonNHGeTX-Regular" + } + } + + public var fontFileExtension: String { + return "otf" + } +}