Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
Slight modernizations to the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtSabintsev committed Jan 6, 2021
1 parent f2a2fda commit faff959
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 47 deletions.
10 changes: 5 additions & 5 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 1220;
LastUpgradeCheck = 1230;
ORGANIZATIONNAME = "Arthur Ariel Sabintsev";
TargetAttributes = {
8E7CBE8A1AF9BD7200009618 = {
Expand Down Expand Up @@ -350,7 +350,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -401,7 +401,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 4.2;
Expand All @@ -416,7 +416,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/Example/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Sabintsev.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -431,7 +431,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/Example/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Sabintsev.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
33 changes: 14 additions & 19 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FontBlaster.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
# Version
s.version = "5.1.2"
s.version = "5.1.3"
s.swift_version = "5.3"

# Meta
Expand Down
30 changes: 10 additions & 20 deletions Sources/FontBlaster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import UIKit
// MARK: - FontBlaster

final public class FontBlaster {

fileprivate enum SupportedFontExtensions: String {
case TrueTypeFont = ".ttf"
case OpenTypeFont = ".otf"
Expand Down Expand Up @@ -55,12 +54,12 @@ private extension FontBlaster {
/// Loads all fonts found in a bundle.
///
/// - Parameter path: The absolute path to the bundle.
class func loadFontsForBundle(withPath path: String) {
final class func loadFontsForBundle(withPath path: String) {
do {
let contents = try FileManager.default.contentsOfDirectory(atPath: path) as [String]
let loadedFonts = fonts(fromPath: path, withContents: contents)
if !loadedFonts.isEmpty {
for font in loadedFonts {
loadedFonts.forEach { font in
loadFont(font: font)
}
} else {
Expand All @@ -74,10 +73,10 @@ private extension FontBlaster {
/// Loads all fonts found in a bundle that is loaded within another bundle.
///
/// - Parameter path: The absolute path to the bundle.
class func loadFontsFromBundlesFoundInBundle(path: String) {
final class func loadFontsFromBundlesFoundInBundle(path: String) {
do {
let contents = try FileManager.default.contentsOfDirectory(atPath: path)
for item in contents {
contents.forEach { item in
if let url = URL(string: path),
item.contains(".bundle") {
let urlPathString = url.appendingPathComponent(item).absoluteString
Expand All @@ -92,7 +91,7 @@ private extension FontBlaster {
/// Loads a specific font.
///
/// - Parameter font: The font to load.
class func loadFont(font: Font) {
final class func loadFont(font: Font) {
let fontPath: FontPath = font.path
let fontName: FontName = font.name
let fontExtension: FontExtension = font.ext
Expand All @@ -102,21 +101,12 @@ private extension FontBlaster {
if let fontData = try? Data(contentsOf: fontFileURL) as CFData,
let dataProvider = CGDataProvider(data: fontData) {

/// Fixes deadlocking issue caused by `let fontRef = CGFont(dataProvider)`.
/// Temporary fix until rdar://18778790 is addressed.
/// Open Radar at http://www.openradar.me/18778790
/// Discussion at https://github.com/ArtSabintsev/FontBlaster/issues/19
_ = UIFont()

let fontRef = CGFont(dataProvider)

if CTFontManagerRegisterGraphicsFont(fontRef!, &fontError) {

if let postScriptName = fontRef?.postScriptName {
if CTFontManagerRegisterGraphicsFont(fontRef!, &fontError),
let postScriptName = fontRef?.postScriptName {
printDebugMessage(message: "Successfully loaded font: '\(postScriptName)'.")
loadedFonts.append(String(postScriptName))
}

} else if let fontError = fontError?.takeRetainedValue() {
let errorDescription = CFErrorCopyDescription(fontError)
printDebugMessage(message: "Failed to load font '\(fontName)': \(String(describing: errorDescription))")
Expand All @@ -143,7 +133,7 @@ private extension FontBlaster {
/// - contents: The contents of an Bundle as an array of String objects.
///
/// - Returns: A an array of Font objects.
class func fonts(fromPath path: String, withContents contents: [String]) -> [Font] {
final class func fonts(fromPath path: String, withContents contents: [String]) -> [Font] {
var fonts = [Font]()
for fontName in contents {
var parsedFont: (FontName, FontExtension)?
Expand All @@ -166,15 +156,15 @@ private extension FontBlaster {
/// - Parameter name: The name of the font.
///
/// - Returns: A tuple with the font's name and extension.
class func font(fromName name: String) -> (FontName, FontExtension) {
final class func font(fromName name: String) -> (FontName, FontExtension) {
let components = name.split{$0 == "."}.map { String($0) }
return (components[0], components[1])
}

/// Prints debug messages to the console if debugEnabled is set to true.
///
/// - Parameter message: The status to print to the console.
class func printDebugMessage(message: String) {
final class func printDebugMessage(message: String) {
if debugEnabled == true {
print("[FontBlaster]: \(message)")
}
Expand Down

0 comments on commit faff959

Please sign in to comment.