Skip to content

Commit

Permalink
Add support for kFractionsType Issue Rightpoint#243
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanSchatzline committed Feb 19, 2017
1 parent 617c35a commit bf75178
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Example-iOS/DemoStrings.swift
Expand Up @@ -306,6 +306,26 @@ enum DemoStrings {
)
}()

// Demonstrate fractions.
static let fractionsExample: NSAttributedString = {

let systemFontStyle = StringStyle(
.font(.systemFont(ofSize: 24)),
.adapt(.body)
)

let string = "\n1336 <fraction>6/10</fraction> + <fraction>4/10</fraction> = 1337"
return NSAttributedString.composed(of: [
"Fractions".styled(with: systemFontStyle, .smallCaps(.fromLowercase), .color(.raizlabsRed)),
string.styled(with: systemFontStyle.byAdding(
.xmlRules([
.style("fraction", systemFontStyle.byAdding(.numberCase(.fraction))),
])
)
),
])
}()

// Demonstrate scientific inferiors.
static let scientificInferiorsExample: NSAttributedString = {

Expand Down
1 change: 1 addition & 0 deletions Example-iOS/StyleViewController.swift
Expand Up @@ -32,6 +32,7 @@ class StyleViewController: UITableViewController {
DemoStrings.ordinalsExample,
DemoStrings.scientificInferiorsExample,
DemoStrings.stylisticAlternatesExample,
DemoStrings.fractionsExample,
]),
("Accessibility Speech", DemoStrings.accessibilitySpeechExamples),
]
Expand Down
7 changes: 7 additions & 0 deletions Sources/FontFeatures.swift
Expand Up @@ -61,12 +61,19 @@
/// which drop below the typographic baseline.
case lower

/// 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.
case fraction

public func featureSettings() -> [(type: Int, selector: Int)] {
switch self {
case .upper:
return [(type: kNumberCaseType, selector: kUpperCaseNumbersSelector)]
case .lower:
return [(type: kNumberCaseType, selector: kLowerCaseNumbersSelector)]
case .fraction:
return [(type: kFractionsType, selector: kDiagonalFractionsSelector)]
}
}

Expand Down

0 comments on commit bf75178

Please sign in to comment.