Releases: gewill/ScaledFont
Release list
1.1.1
Documentation release. The library's API and behaviour are unchanged from 1.1.0.
Documentation
- The DocC landing page now covers UIKit, AppKit and SwiftUI on every supported platform, and its topics are grouped into Essentials, Font Variants and SwiftUI.
- New article Using a Scaled Font: creating a scaled font and using it with UIKit, AppKit and SwiftUI. It explains that macOS has no Dynamic Type, so a custom font keeps the size from the style dictionary there.
- New article Choosing Font Variants: the
designandweightkeys, call-site overrides and their precedence, howboldpicks a face for a custom font, availability, and why aswitchoverFontDesignorFontWeightneeds adefaultcase. ScaledFont,FontDesignandFontWeightare organized into topic groups, andrawValueandinit(rawValue:)are documented.- Creating A Style Dictionary shows how to list font names on macOS and links to the variants article.
- The link to the typography specifications in the Human Interface Guidelines works again, and the
adjustsFontForContentSizeCategorytypo is fixed in the docs and the README.
Tooling
swift package generate-documentationworks again with current toolchains. The pinned swift-docc-plugin moved from 1.0.0, which passed an option that current DocC no longer accepts, to 1.5.0.
1.1.0
First release of this fork. It builds on upstream 1.0.5, adds macOS support, and adds system font variants to style dictionaries. The changelog covers every release of the fork.
Font variants
A style dictionary entry can now describe a system font instead of a custom font. Omit fontName and fontSize and use the optional variant keys:
design:default,seriformonospacedweight:regularorbold
The weight key also works in a custom font entry.
The same variants can be set at the call site, where they take precedence over the style dictionary:
Text("Metadata")
.scaledFont(.subheadline, design: .serif, weight: .bold)
label.font = scaledFont.font(forTextStyle: .headline, weight: .bold)design: .default and weight: .regular clear a variant that the style dictionary sets. For a custom font, weight: .bold uses the bold face of the same family when the family has one that keeps the other style traits, such as italic or condensed; otherwise the configured fontName is kept.
Other changes
- macOS 11 support. On macOS,
font(forTextStyle:)takes anNSFont.TextStyleand returns anNSFont, and the SwiftUI modifiers work as they do on the other platforms. macOS has no Dynamic Type, so a custom font keeps the size from the style dictionary. - A style dictionary entry without
fontNameandfontSizedescribes a system font. Previously such an entry made the whole style dictionary invalid. An entry with only one of the two keys still does.
API notes
ScaledFont.FontDesign and ScaledFont.FontWeight are RawRepresentable structs with static constants rather than enums. Code that switches over them needs a default clause:
switch design {
case .serif: …
case .monospaced: …
default: …
}In exchange, new values such as a rounded design or a semibold weight can be added later without breaking any client. See #2 for the background.
Unknown values are ignored: a value the platform does not support falls back to the normal system font, and a style dictionary that uses one still loads.
Upgrading from the pre-release branch
Apps that used the codex/font-variant-overrides branch before this release should note these differences:
FontDesignandFontWeightchanged from enumerations to structures, so aswitchover them needs adefaultcase. See #2.- If your app resolved the branch before commit
98de724, this release also:- makes the whole style dictionary invalid again when an entry has only one of
fontNameandfontSize, instead of turning that text style into a system font; - scales system fonts once instead of twice at larger text sizes;
- keeps an italic, condensed or already bold custom font when the weight is bold, instead of replacing it with another face;
- applies the call-site variants in SwiftUI on iOS 13.
- makes the whole style dictionary invalid again when an entry has only one of
Not included
The changes in upstream 1.0.6 and 1.0.7 are not part of this release: compatibility with strict Swift concurrency checking, the removal of the LibraryContentProvider, and changes to the Swift tools version.
Requirements
iOS 11, macOS 11, tvOS 11, watchOS 4 or later. The serif and monospaced designs need iOS 13, tvOS 13, watchOS 7 or macOS 11.
Verification
Tests pass on macOS, on an iOS 27 simulator and on a tvOS 27 simulator, including a run with the simulator set to the largest accessibility text size. The sources type check for iOS 11 and 13, tvOS 11, watchOS 4, 6 and 7, macOS 11 and visionOS.