Skip to content
This repository was archived by the owner on Sep 17, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cartfile.private
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Quick/Nimble" ~> 4.1
github "Quick/Nimble"
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Quick/Nimble" "v4.1.0"
github "Quick/Nimble" "220152be528dcc0537764c179c95b8174028c80c"
17 changes: 12 additions & 5 deletions Typesetter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@
};
536F381B1C5D11E800948324 = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = 4MJAYLR55B;
LastSwiftMigration = 0800;
};
};
Expand Down Expand Up @@ -358,6 +357,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALID_ARCHS = "arm64 armv7 armv7s";
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -402,6 +402,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -412,6 +413,7 @@
536F38271C5D11E800948324 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = NO;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEFINES_MODULE = YES;
Expand All @@ -425,18 +427,20 @@
);
INFOPLIST_FILE = Typesetter/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = studio.Typesetter;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
536F38281C5D11E800948324 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = NO;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEFINES_MODULE = YES;
Expand All @@ -450,18 +454,20 @@
);
INFOPLIST_FILE = Typesetter/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = studio.Typesetter;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
536F382A1C5D11E800948324 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
Expand All @@ -471,14 +477,15 @@
PRODUCT_BUNDLE_IDENTIFIER = studio.TypesetterTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
536F382B1C5D11E800948324 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
Expand All @@ -487,7 +494,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = studio.TypesetterTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
16 changes: 8 additions & 8 deletions Typesetter/CSV.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import Foundation
class CSV {
let headers: [String]
let columns: [String: [String]]
private static let delimiter = NSCharacterSet(charactersInString: ",")
fileprivate static let delimiter = CharacterSet(charactersIn: ",")

private static func getColumns(headers: [String], lines: [String]) -> [String: [String]] {
fileprivate static func getColumns(_ headers: [String], lines: [String]) -> [String: [String]] {
return Array(lines)[1..<lines.count].reduce([String: [String]]()) { columns, line in
var newColumns = columns
let row = line.componentsSeparatedByCharactersInSet(NSCharacterSet(charactersInString: ","))
for (index, header) in headers.enumerate() {
let row = line.components(separatedBy: CharacterSet(charactersIn: ","))
for (index, header) in headers.enumerated() {
if columns[header] == nil {
newColumns[header] = [row[index]]
} else {
Expand All @@ -39,9 +39,9 @@ class CSV {
return nil
}

let newline = NSCharacterSet.newlineCharacterSet()
let newline = CharacterSet.newlines
var lines: [String] = []
contents.stringByTrimmingCharactersInSet(newline).enumerateLines { line, stop in lines.append(line)
contents.trimmingCharacters(in: newline).enumerateLines { line, stop in lines.append(line)
}

guard lines.count > 1 else {
Expand All @@ -50,8 +50,8 @@ class CSV {
return nil
}

let headers = lines[0].componentsSeparatedByCharactersInSet(CSV.delimiter)
let headers = lines[0].components(separatedBy: CSV.delimiter)
self.headers = headers
self.columns = CSV.getColumns(headers, lines: lines)
}
}
}
2 changes: 1 addition & 1 deletion Typesetter/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
37 changes: 22 additions & 15 deletions Typesetter/Typesetter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ import UIKit

Where the columns headers are `TypesetterTextStyle`s and the row headers are `TypesetterFontSize`s.
*/
public class Typesetter {
open class Typesetter {
internal typealias TextStyleFontSizeMatrix = [TypesetterTextStyle: [TypesetterFontSize: CGFloat]]

private let configuration: TypesetterConfiguration
private let matrix: TextStyleFontSizeMatrix
private let application = UIApplication.sharedApplication()
fileprivate let configuration: TypesetterConfiguration
fileprivate let matrix: TextStyleFontSizeMatrix
fileprivate let application = UIApplication.shared

/**
Check if this instance of typesetter has sizes loaded. Returns `true` if this instance has successfully loaded font sizes from a file, `false` if not.
*/
public var hasSizes: Bool {
open var hasSizes: Bool {
return matrix.count > 0
}

private static var resourcePaths: [NSBundle: String] = [:]
private static func defaultResourcePathForBundle(bundle: NSBundle) -> String? {
fileprivate static var resourcePaths: [Bundle: String] = [:]
fileprivate static func defaultResourcePathForBundle(_ bundle: Bundle) -> String? {
if let path = resourcePaths[bundle] {
return path
} else if let path = bundle.pathForResource("FontSizes", ofType: "csv") {
} else if let path = bundle.path(forResource: "FontSizes", ofType: "csv") {
resourcePaths[bundle] = path
return path
}
Expand All @@ -51,7 +51,7 @@ public class Typesetter {

- Parameter bundle: The bundle in which to look for the file named `FontSizes.csv`
*/
public convenience init(bundle: NSBundle) {
public convenience init(bundle: Bundle) {
guard let path = Typesetter.defaultResourcePathForBundle(bundle) else {
self.init(configuration: TypesetterConfiguration(sizeDefinitionsPath: "NoPath"))
return
Expand Down Expand Up @@ -79,8 +79,15 @@ public class Typesetter {
- textStyle: The `TypesetterTextStyle` text style to return the `UIFont` instance for
- font: The `TypesetterFont` to return the `UIFont` with.
*/
public func sizedFontFor(textStyle: TypesetterTextStyle, font: TypesetterFont) -> UIFont {
let size = TypesetterFontSize(contentSize: application.preferredContentSizeCategory)
open func sizedFontFor(_ textStyle: TypesetterTextStyle, font: TypesetterFont) -> UIFont {

var preferrredContentSize = UIContentSizeCategory.medium

if UIApplication.shared.responds(to: #selector(getter: UIApplication.preferredContentSizeCategory)) {
preferrredContentSize = UIApplication.shared.preferredContentSizeCategory
}

let size = TypesetterFontSize(contentSize: preferrredContentSize)
let pointSize = sizeFor(size: size, textStyle: textStyle)

return UIFont(descriptor: descriptorFor(textStyle, size: size, font: font), size: pointSize)
Expand All @@ -93,18 +100,18 @@ public class Typesetter {
- textStyle: The text style as a string to return the `UIFont` instance for
- font: The `TypesetterFont` to return the `UIFont` with.
*/
public func sizedFontFor(textStyle: String, font: TypesetterFont) -> UIFont {
open func sizedFontFor(_ textStyle: String, font: TypesetterFont) -> UIFont {
let style = TypesetterTextStyle(rawValue: textStyle) ?? .Body

return sizedFontFor(style, font: font)
}

private func descriptorFor(textStyle: TypesetterTextStyle, size: TypesetterFontSize, font: TypesetterFont) -> UIFontDescriptor {
fileprivate func descriptorFor(_ textStyle: TypesetterTextStyle, size: TypesetterFontSize, font: TypesetterFont) -> UIFontDescriptor {
return UIFontDescriptor(name: font.name, size: sizeFor(size: size, textStyle: textStyle))
}

private func sizeFor(size size: TypesetterFontSize, textStyle: TypesetterTextStyle) -> CGFloat {
fileprivate func sizeFor(size: TypesetterFontSize, textStyle: TypesetterTextStyle) -> CGFloat {
return matrix[textStyle]?[size] ?? configuration.defaultFontSize
}

}
}
4 changes: 2 additions & 2 deletions Typesetter/TypesetterConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct TypesetterConfiguration {
*/
public let defaultFontSize: CGFloat

private let defaultDefaultFontSize: CGFloat = 12.0
fileprivate let defaultDefaultFontSize: CGFloat = 12.0

/**
Initialize a new `TypesetterConfiguration` with a custom path to a definition file.
Expand All @@ -37,4 +37,4 @@ public struct TypesetterConfiguration {
self.sizeDefinitionsPath = sizeDefinitionsPath
self.defaultFontSize = defaultFontSize
}
}
}
75 changes: 18 additions & 57 deletions Typesetter/TypesetterFontSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,85 +29,46 @@ public enum TypesetterFontSize: String {
/** The largest font size reflecting the current accessibility settings. */
case AccessibilityExtraExtraExtraLarge

static let allSizes = [ ExtraSmall, Small, Medium, Large, ExtraLarge, ExtraExtraLarge, ExtraExtraExtraLarge, AccessibilityMedium, AccessibilityLarge, AccessibilityExtraLarge, AccessibilityExtraExtraLarge, AccessibilityExtraExtraExtraLarge]

/**
The number of typesetter font sizes available. Always returns 12.
*/
static var count: Int {
var count = 0

switch self.Small {
case .Small:
count += 1
fallthrough
case .Medium:
count += 1
fallthrough
case .Large:
count += 1
fallthrough
case .ExtraSmall:
count += 1
fallthrough
case .ExtraLarge:
count += 1
fallthrough
case .ExtraExtraLarge:
count += 1
fallthrough
case .ExtraExtraExtraLarge:
count += 1
fallthrough
case .AccessibilityMedium:
count += 1
fallthrough
case .AccessibilityLarge:
count += 1
fallthrough
case .AccessibilityExtraLarge:
count += 1
fallthrough
case .AccessibilityExtraExtraLarge:
count += 1
fallthrough
case .AccessibilityExtraExtraExtraLarge:
count += 1
}

return count
}

static let count = allSizes.count

/**
Initialize the corresponding TypesetterFontSize for a UIContentSize.
Parameter contentSize: The UIContentSize to wrap.
*/
init(contentSize: String) {
init(contentSize: UIContentSizeCategory) {
switch contentSize {
case UIContentSizeCategorySmall:
case UIContentSizeCategory.small:
self = .Small
case UIContentSizeCategoryMedium:
case UIContentSizeCategory.medium:
self = .Medium
case UIContentSizeCategoryLarge:
case UIContentSizeCategory.large:
self = .Large
case UIContentSizeCategoryExtraSmall:
case UIContentSizeCategory.extraSmall:
self = .ExtraSmall
case UIContentSizeCategoryExtraLarge:
case UIContentSizeCategory.extraLarge:
self = .ExtraLarge
case UIContentSizeCategoryExtraExtraLarge:
case UIContentSizeCategory.extraExtraLarge:
self = .ExtraExtraLarge
case UIContentSizeCategoryExtraExtraExtraLarge:
case UIContentSizeCategory.extraExtraExtraLarge:
self = .ExtraExtraExtraLarge
case UIContentSizeCategoryAccessibilityMedium:
case UIContentSizeCategory.accessibilityMedium:
self = .AccessibilityMedium
case UIContentSizeCategoryAccessibilityLarge:
case UIContentSizeCategory.accessibilityLarge:
self = .AccessibilityLarge
case UIContentSizeCategoryAccessibilityExtraLarge:
case UIContentSizeCategory.accessibilityExtraLarge:
self = .AccessibilityExtraLarge
case UIContentSizeCategoryAccessibilityExtraExtraLarge:
case UIContentSizeCategory.accessibilityExtraExtraLarge:
self = .AccessibilityExtraExtraLarge
case UIContentSizeCategoryAccessibilityExtraExtraExtraLarge:
case UIContentSizeCategory.accessibilityExtraExtraExtraLarge:
self = .AccessibilityExtraExtraExtraLarge
default:
self = .Medium
}
}
}
}
Loading