Skip to content

Follow the Bold Text and Increase Contrast settings - #36

Merged
servercimen merged 12 commits into
feature/math-image-reusefrom
feature/bold-text-contrast
Nov 24, 2026
Merged

servercimen merged 12 commits into
feature/math-image-reusefrom
feature/bold-text-contrast

Conversation

@servercimen

Copy link
Copy Markdown
Owner

Part 6 of a stack of 13 pull requests. The base is #35 (feature/math-image-reuse). #31 (part 1) tells how to merge the stack.

On this stacked branch, swift test passes (260 tests), and the iOS build and build-for-testing pass.

Summary

Bold Text and Increase Contrast are accessibility settings. Before this change, the text view did not follow them. With Bold Text on, the fonts stayed the same while the system text became heavier. TranscriptColor(UIColor) kept only the light and dark values, so system colors lost their high-contrast values.

  • Add TranscriptStyle.followsBoldText (default true). With Bold Text on, system fonts become heavier: weights below semibold go two steps up, and heavier weights go one step, to at most black. Regular text becomes semibold, and bold text becomes heavy. A named font keeps its weight.
  • The default code font takes its bold face under Bold Text. A system codeFont, such as TranscriptFont(size: 15, monospaced: true), keeps bold code heavier. The README tells this.
  • Add TranscriptStyle.withBoldText(_:) for an app that lays out a DocumentLayout itself. The setting is part of the font cache key and of ==.
  • TranscriptTextView observes UITraitLegibilityWeight and lays out again when it changes. The public style does not change. A lazy-stack row that is measured but not placed yet, and a view that gets its width back, also get the new style.
  • TranscriptColor keeps four values: light, dark, and a high-contrast value for each. TranscriptColor(UIColor) resolves all four. init(light:dark:highContrastLight:highContrastDark:) has two new optional arguments.
  • DocumentLayout.draw(in:dirtyRect:text:codeBackground:accent:dark:highContrast:) has a new highContrast argument (default false). TranscriptTextView observes UITraitAccessibilityContrast and draws again, also the streaming tail.
  • Update the README.

Tests

  • swift test on macOS: 192 tests pass. 13 new tests cover the weight steps, the default and named fonts, bold code, the opt-out, the cache key, a style that reaches a row before it is placed, the four color values and a highlight drawn in its high-contrast colors.
  • iOS: a local test app builds with this branch for an iPhone (Release). The package sources give no warnings.

Checked on an iPhone 12 mini

iOS 27.0, in a check screen in a local test app. Trait overrides on the window scene stand in for the two settings. The first runs were on main. Main showed the problem in the first three items. The numbers come from the last runs of each build.

  • Bold Text: main keeps the same fonts, height and pixels, while UILabels next to it become heavier. The branch draws again in 44 to 51 ms: body .SFUI-Semibold, bold and heading .SFUI-Heavy, code Menlo-Bold. The body text is 113.87 pt wide, the same as a UILabel. The fonts go back to the main fonts when the trait goes off. With followsBoldText = false, the fonts do not change.
  • Increase Contrast, light and dark: main draws a tag in the normal systemBlue and systemGray5. The branch draws the high-contrast values that UIColor gives.
  • The streaming tail: main keeps the old quote bar color for at least 377 ms. The branch draws the new color within 105 ms.
  • Relayout checks without a main counterpart, because main ignores the setting: a stream with a change in the middle matches a new view (0 different pixels). A view with no width gets the height of a new view in bold (126 to 222 pt). A LazyVStack row that is empty or off screen at the change gets a height equal to its layout.

Other stand-ins: overrideUserInterfaceStyle for dark mode, and setContentOffset for scrolling.

Not checked

  • The real Bold Text and Increase Contrast settings.
  • A system font that the real setting already makes heavier. Under the trait override, UIFont.systemFont and CTFontCreateUIFontForLanguage did not change. So the check did not show that the weight goes up only one time, or that the cache keeps the fonts of the two settings apart.
  • An app font of weight semibold or bold in the text view. On the phone, UILabel makes these weights two steps heavier. The code of this branch makes them one step heavier.

🤖 Generated with Claude Code

servercimen and others added 11 commits November 23, 2026 17:09
The style has an internal Bold Text state that the font cache key
includes. When it is on, system fonts take a heavier weight: regular
becomes semibold, and bold becomes heavy. The default code font takes
its bold face. Named fonts keep their own weight. The new
followsBoldText property turns this off. It is on by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TranscriptTextView gives layout its style with the Bold Text state of
its trait collection. It observes the legibility weight trait, and it
lays out again when the change gives other fonts. The public style
does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TranscriptColor keeps a light and a dark value for Increase Contrast
too. The UIColor initializer resolves them, so system colors keep their
high-contrast values. init(light:dark:) takes optional high-contrast
colors. Drawing takes a highContrast flag next to the dark flag, and
the view resolves the style colors for the contrast of its traits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TranscriptTextView observes the accessibility contrast trait with the
appearance and display scale traits. A change redraws the text in the
colors for the new contrast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The README says how the text follows the Bold Text setting and how to
turn that off. It also says that colors keep Increase Contrast values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The heavier weight now comes from the declared weight of the font, not
from the weight of the font that the system gives. If the system
already gives a heavy enough font for Bold Text, the font stays as it
is, and the weight does not go up two times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A lazy stack can measure a row and not place it. The row has no width,
so a style change did not reach the layout engine. The engine then laid
out new text in the old style, the view dropped each result, and the row
kept its old height.

The engine now takes a new style at the width that it already lays out
at. The view gives the engine the new style, and asks SwiftUI to measure
the row again after a Bold Text change. sizeThatFits uses the installed
layout only when its style is the current one. The empty layout follows
the style too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The style now keeps the Bold Text setting itself, and followsBoldText
decides whether layout uses it. Both go in the font cache key. If the
system fonts change with the setting, fonts made with the setting on are
not used with it off, also when followsBoldText is false.

withBoldText(_:) is public, so an app that lays out a DocumentLayout
itself can follow Bold Text too. The LaTeX fallback font of a formula
now comes from the cache.

The documentation now says that bold code looks the same as other code
with the default code font, and how a system code font keeps it heavier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The internal draw has no default for highContrast now, as it has none
for dark. The fade cache check is on two lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A view can lose its width, see a style or Bold Text change, and then get
the same width back. It now lays out again when the installed layout has
another style.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DocumentLayout.draw: the doc comment keeps the style colors and the Increase Contrast values.
TranscriptStyle.font(for:traits:weight:): the font cache key keeps the weight and the Bold Text fields.
TranscriptStyle.mathFallbackFont(size:): the font cache key gives no weight.
DocumentLayout: the style colors for quote bars, table headers, quote text and task boxes get the Increase Contrast state.
TranscriptStyle.makeFont: Bold Text starts from the weight of a list number or a table header, with a new test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@servercimen
servercimen added this pull request to stack #44 November 24, 2026 20:57
@servercimen
servercimen removed this pull request from stack #44 November 24, 2026 21:01
@servercimen
servercimen added this pull request to stack #45 November 24, 2026 21:01
@servercimen
servercimen merged commit 4683d63 into main Nov 24, 2026
1 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant