Skip to content
Merged
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
6 changes: 3 additions & 3 deletions Example-iOS/DemoStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ enum DemoStrings {
let xml = "<li>This list is defined with XML and displayed in a single <code>UILabel</code>.</li><li>Each row is represented with an <code>&lt;li&gt;</code> tag.</li><li>Attributed strings define the string to use for bullets.</li><li>The text style is also specified for the <code>&lt;li&gt;</code> and <code>&lt;code&gt;</code> tags.</li>"

// Use this method of parsing XML if the content is not under your
// control, since you are less likley to catch edge cases while
// control, since you are less likely to catch edge cases while
// developing. This way, you can handle parsing errors gracefully.
guard let string = try? NSAttributedString.composed(ofXML: xml, rules: rules) else {
fatalError("Unable to load XML \(xml)")
Expand Down Expand Up @@ -285,10 +285,10 @@ enum DemoStrings {
/// Demonstrate specifying Dynamic Type sizing behavior and custom styles
/// via IBDesignable in Interface Builder. To see this example in action,
/// play with the iOS Text Size slider and see how the UI elements react.
static let dynamcTypeUIKitExample = DemoStrings.customStoryboard(identifier: "CatalogViewController")
static let dynamicTypeUIKitExample = DemoStrings.customStoryboard(identifier: "CatalogViewController")
.attributedString(from: "Dynamic UIKit elements with custom fonts")

/// Demonstrate how BonMot interacts with sytem preferred text styles.
/// Demonstrate how BonMot interacts with system preferred text styles.
static let preferredFontsExample = DemoStrings.customStoryboard(identifier: "PreferredFonts")
.attributedString(from: "Preferred Fonts")

Expand Down
2 changes: 1 addition & 1 deletion Example-iOS/StyleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class StyleViewController: UITableViewController {
("Baseline Offset", [DemoStrings.heartsExample]),
("Indentation", DemoStrings.indentationExamples),
("Advanced XML and Kerning", [DemoStrings.advancedXMLAndKerningExample]),
("Dynamic Type", [DemoStrings.dynamcTypeUIKitExample, DemoStrings.preferredFontsExample]),
("Dynamic Type", [DemoStrings.dynamicTypeUIKitExample, DemoStrings.preferredFontsExample]),
("OpenType Features", [
DemoStrings.figureStylesExample,
DemoStrings.ordinalsExample,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Composable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public protocol Composable {
/// - Parameters:
/// - attributedString: The attributed string to which to append the
/// receiver.
/// - baseStyle: Additional attribues to apply to the receiver before
/// - baseStyle: Additional attributes to apply to the receiver before
/// appending it to the passed attributed string.
func append(to attributedString: NSMutableAttributedString, baseStyle: StringStyle)

Expand All @@ -38,7 +38,7 @@ public protocol Composable {
/// - Parameters:
/// - attributedString: The attributed string to which to append the
/// receiver.
/// - baseStyle: Additional attribues to apply to the receiver before
/// - baseStyle: Additional attributes to apply to the receiver before
/// appending it to the passed attributed string.
/// - isLastElement: Whether the receiver is the final element that is
/// being appended to an attributed string. Used in cases
Expand Down
8 changes: 4 additions & 4 deletions Sources/FontFeatures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
/// will line up when arranged in columns.
case monospaced

/// Proportionally spaced numbers, also known as "proprotional figures",
/// Proportionally spaced numbers, also known as "proportional figures",
/// are of variable width. This makes them look better in most cases,
/// but they should be avoided when numbers need to line up in columns.
case proportional
Expand All @@ -115,12 +115,12 @@

/// Diagonal Fractions, when written on paper, are written on one line
/// with the numerator diagonally above and to the left of the
/// demoninator, with the slash ("/") between them.
/// denominator, with the slash ("/") between them.
case diagonal

/// Vertical Fractions, when written on paper, are written on one line
/// with the numerator directly above the
/// demoninator, with a line lying horizontally between them.
/// denominator, with a line lying horizontally between them.
case vertical

public func featureSettings() -> [(type: Int, selector: Int)] {
Expand All @@ -143,7 +143,7 @@
/// No vertical position adjustment is applied.
case normal

/// Superscript (superior) glpyh variants are used, as in footnotes¹.
/// Superscript (superior) glyph variants are used, as in footnotes¹.
case superscript

/// Subscript (inferior) glyph variants are used: vₑ.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extension Tab {
let string = attributedString.string as NSString

// Lookup the range this paragraph is operating on.
// This is the range from `range` to the preceeding newline or the start of the string.
// This is the range from `range` to the preceding newline or the start of the string.
let precedingRange = NSRange(location: 0, length: NSMaxRange(range))
var leadingNewline = string.rangeOfCharacter(from: CharacterSet.newlines, options: [.backwards], range: precedingRange).location
leadingNewline = (leadingNewline == NSNotFound) ? 0 : leadingNewline + 1
Expand Down
4 changes: 2 additions & 2 deletions Sources/UIKit/AdaptableTextContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ extension UIToolbar {
// MARK: - AdaptableTextContainer for UIViewController
extension UIViewController {

/// Adapt the attributed text of teh bar items in the navigation item or in
/// Adapt the attributed text of the bar items in the navigation item or in
/// the toolbar to the specified trait collection.
///
/// - parameter traitCollection: The new trait collection.
Expand Down Expand Up @@ -246,7 +246,7 @@ extension UIBarItem {
/// Adapt `titleTextAttributes` to the specified trait collection.
///
/// - note: This extension does not conform to `AdaptableTextContainer`
/// because `UIBarIterm` is not a view or view controller.
/// because `UIBarItem` is not a view or view controller.
/// - parameter traitCollection: the new trait collection.
@objc(bon_updateTextForTraitCollection:)
public func adaptText(forTraitCollection traitCollection: UITraitCollection) {
Expand Down
50 changes: 44 additions & 6 deletions Sources/UIKit/AdaptiveStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ extension AdaptiveStyle {
/// - Parameters:
/// - size: The size the font was designed for at `UIContentSizeCategory.large`.
/// - contentSizeCategory: The content size category to scale to.
/// - minimiumSize: The smallest size the font can be. Defaults to 11, or
/// - minimumSize: The smallest size the font can be. Defaults to 11, or
/// `designatedSize` if `designatedSize` is less than 11.
/// - Returns: The new point size, scaled to the specified content size
public static func adapt(designatedSize size: CGFloat, for contentSizeCategory: BonMotContentSizeCategory, minimiumSize: CGFloat = 11) -> CGFloat {
public static func adapt(designatedSize size: CGFloat, for contentSizeCategory: BonMotContentSizeCategory, minimumSize: CGFloat = 11) -> CGFloat {
let shift = min(shiftTable[contentSizeCategory] ?? 0, CGFloat(6))
let minSize = min(minimiumSize, size)
let minSize = min(minimumSize, size)
return max(size + shift, minSize)
}

Expand All @@ -146,16 +146,54 @@ extension AdaptiveStyle {
/// - Parameters:
/// - size: The size the font was designed for at `UIContentSizeCategory.large`.
/// - contentSizeCategory: The content size category to scale to.
/// - minimiumSize: The smallest size the font can be. Defaults to 11.
/// - minimumSize: The smallest size the font can be. Defaults to 11.
/// - Returns: The new point size, scaled to the specified contentSize.
public static func adaptBody(designatedSize size: CGFloat, for contentSizeCategory: BonMotContentSizeCategory, minimiumSize: CGFloat = 11) -> CGFloat {
public static func adaptBody(designatedSize size: CGFloat, for contentSizeCategory: BonMotContentSizeCategory, minimumSize: CGFloat = 11) -> CGFloat {
let shift = shiftTable[contentSizeCategory] ?? 0
let minSize = min(minimiumSize, size)
let minSize = min(minimumSize, size)
return max(size + shift, minSize)
}

}

extension AdaptiveStyle { // Deprecated - search the code and remove other deprecations when you remove this

/// The default scaling function. Grows by 2 points for each
/// step above Large, and shrinks by 1 point for each step below Large.
/// This function does not create larger values for content size category
/// values in the Accessibility range of content size categories.
///
/// - Parameters:
/// - size: The size the font was designed for at `UIContentSizeCategory.large`.
/// - contentSizeCategory: The content size category to scale to.
/// - minimiumSize: The smallest size the font can be. Defaults to `designatedSize` if `designatedSize` is less
/// than the supplied size.
/// - Returns: The new point size, scaled to the specified content size
@available(*, deprecated, renamed: "adapt(designatedSize:for:minimumSize:)")
public static func adapt(designatedSize size: CGFloat, for contentSizeCategory: BonMotContentSizeCategory, minimiumSize minimumSize: CGFloat) -> CGFloat {
// removed default value of minimiumSize so that call sites that don't pass anything will use the new implementation
let shift = min(shiftTable[contentSizeCategory] ?? 0, CGFloat(6))
let minSize = min(minimumSize, size)
return max(size + shift, minSize)
}

/// A scaling function for "body" elements. Continues to grow for content
/// size category values in the Accessibility range.
///
/// - Parameters:
/// - size: The size the font was designed for at `UIContentSizeCategory.large`.
/// - contentSizeCategory: The content size category to scale to.
/// - minimiumSize: The smallest size the font can be.
/// - Returns: The new point size, scaled to the specified contentSize.
@available(*, deprecated, renamed: "adaptBody(designatedSize:for:minimumSize:)")
public static func adaptBody(designatedSize size: CGFloat, for contentSizeCategory: BonMotContentSizeCategory, minimiumSize minimumSize: CGFloat) -> CGFloat {
// removed default value of minimiumSize so that call sites that don't pass anything will use the new implementation
let shift = shiftTable[contentSizeCategory] ?? 0
let minSize = min(minimumSize, size)
return max(size + shift, minSize)
}
}

extension AdaptiveStyle: EmbeddedTransformation {

struct Key {
Expand Down
2 changes: 1 addition & 1 deletion Sources/UIKit/AttributedStringTransformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// Defines a transformation to be performed on an `NSMutableAttributedString`.
/// It is used for adative transformations that need to know about the content
/// It is used for adaptive transformations that need to know about the content
/// of the string in order to be performed. These are applied after the
/// `AdaptiveStyleTransformation`s are applied.
internal protocol AttributedStringTransformation {
Expand Down
6 changes: 4 additions & 2 deletions Sources/UIKit/NSAttributedString+Adaptive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension NSAttributedString {
/// - Parameters:
/// - theAttributes: The attributes to transform.
/// - traitCollection: The trait collection to which to adapt the attributes.
/// - Returns: Attributes with fonts updated to the specified contect size category.
/// - Returns: Attributes with fonts updated to the specified content size category.
public static func adapt(attributes theAttributes: StyleAttributes, to traitCollection: UITraitCollection) -> StyleAttributes {
let adaptations: [AdaptiveStyleTransformation] = EmbeddedTransformationHelpers.transformations(from: theAttributes)
var styleAttributes = theAttributes
Expand Down Expand Up @@ -73,7 +73,9 @@ extension StringStyle {
// MARK: - Deprecations
extension NSAttributedString {

@available(*, deprecated, renamed: "adapted(to:)") public final func adapt(to traitCollection: UITraitCollection) -> NSAttributedString {
// Deprecated - search the code and remove other deprecations when you remove this
@available(*, deprecated, renamed: "adapted(to:)")
public final func adapt(to traitCollection: UITraitCollection) -> NSAttributedString {
return adapted(to: traitCollection)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/UIKit/StyleableUIElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ extension UITextView {

/// A string style. Stored via associated objects.
/// - note: The style is applied to both the `attributedText` and
/// `typingAtributes`. If you plan on styling them differently, use
/// `typingAttributes`. If you plan on styling them differently, use
/// attributed strings directly.
public final var bonMotStyle: StringStyle? {
get { return StyleableUIElementHelpers.getAssociatedStyle(from: self) }
Expand Down
2 changes: 1 addition & 1 deletion Sources/XMLBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension NSAttributedString {
/// specify styling options.
/// - styler: An optional custom styler to perform extra style operations.
/// - options: XML parsing options.
/// - Returns: A styled attriubted string.
/// - Returns: A styled attriubuted string.
/// - Throws: Any errors encountered by the XML parser.
public static func composed(ofXML fragment: String, baseStyle: StringStyle? = nil, styler: XMLStyler? = nil, options: XMLParsingOptions = []) throws -> NSAttributedString {
let builder = XMLBuilder(
Expand Down
Loading