FFFF Releases · gewill/ScaledFont · GitHub
[go: up one dir, main page]

Skip to content

Releases

1.2.0

Choose a tag to compare

@gewill gewill released this 19 Sep 05:00
0823df9

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 factor UIFontMetrics applies on iOS and a system font by the ratio of the iOS preferred font sizes, both rounded to whole points as on iOS. .large returns 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 the dynamicTypeSize of the environment.
  • TextSizePreference stores 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 an ObservableObject, AppKit thro 10BC8 ugh didChangeNotification.

See #6 and the new article Offering an In-App Text Size in the documentation.

Examples

  • TextSizeDemo, a macOS app in the Examples folder that changes the text size from the View menu, the toolbar and Settings, for text in SwiftUI and in AppKit. Run it with swift run TextSizeDemo in 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 the scaledFont(_:) modifiers.

Full changelog: 1.1.1...1.2.0

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.

0