Skip to content

Releases: gewill/ScaledFont

Release list

1.1.1

Choose a tag to compare

@gewill gewill released this 17 Sep 14:22
6c3eea9

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 design and weight keys, call-site overrides and their precedence, how bold picks a face for a custom font, availability, and why a switch over FontDesign or FontWeight needs a default case.
  • ScaledFont, FontDesign and FontWeight are organized into topic groups, and rawValue and init(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 adjustsFontForContentSizeCategory typo is fixed in the docs and the README.

Tooling

  • swift package generate-documentation works 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

Choose a tag to compare

@gewill gewill released this 16 Sep 06:53
88585c7

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, serif or monospaced
  • weight: regular or bold

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 an NSFont.TextStyle and returns an NSFont, 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 fontName and fontSize describes 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:

  • FontDesign and FontWeight changed from enumerations to structures, so a switch over them needs a default case. 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 fontName and fontSize, 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.

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.