Repository navigation
Releases
1.2.0
Adds an in-app text size for macOS, where there is no Dynamic Type. Apps that do not choose a text size get the same fonts as with 1.1.1.
In-App Text Size
font(forTextStyle:design:weight:dynamicTypeSize:)returns a font scaled for a Dynamic Type size that the app chooses. On macOS, a custom font scales by the factorUIFontMetricsapplies on iOS and a system font by the ratio of the iOS preferred font sizes, both rounded to whole points as on iOS..largereturns the same font as before, and a larger size never gets a smaller font, even with a fractional style dictionary size (#11).- On iOS, iPadOS, tvOS and visionOS, the same method takes an explicit size that replaces the size chosen in the system settings.
- On macOS 12 and later, the
scaledFont(_:)modifiers scale their fonts for thedynamicTypeSizeof the environment. TextSizePreferencestores the size in the user defaults of the app, keeps it within a range that includes every accessibility size by default, and posts a notification when it changes. SwiftUI observes it as anObservableObject, AppKit thro 10BC8 ughdidChangeNotification.
See #6 and the new article Offering an In-App Text Size in the documentation.
Examples
TextSizeDemo, a macOS app in theExamplesfolder that changes the text size from the View menu, the toolbar and Settings, for text in SwiftUI and in AppKit. Run it withswift run TextSizeDemoin that folder.Examples/SystemFonts.plist, a style dictionary that uses the system font with the serif and monospaced designs and a bold weight.
Documentation
- README sections on what this fork adds, on macOS support, on using ScaledFont with AppKit and on the in-app text size.
- The Swift Package Index builds the documentation on macOS, so it includes the AppKit API, and the README badges show this fork.
Upgrading
- On macOS 12 and later, a view hierarchy that already sets
dynamicTypeSize, for example in code shared with iOS, now gets scaled fonts from thescaledFont(_:)modifiers.
Full changelog: 1.1.1...1.2.0
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.