Add opt-in synthetic font weight for fonts without bold faces#854
Draft
atani wants to merge 1 commit into
Draft
Conversation
Member
|
Currently we're focusing on migrating the toolkit to Swift 6 with strict concurrency support in the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #853.
Problem
EPUBPreferences.fontWeightmaps to a CSSfont-weightoverride injected into the page. WebKit can only apply a heavier weight when the font actually ships a bold face. For single-face fonts — most notably custom fonts declared throughfontFamilyDeclarations— WebKit does not synthesize bolding, sofontWeighthas no visible effect. Rendering the same passage atfontWeight1.0 and 1.5 with a single-face font produces pixel-identical output.This is an engine limitation, so
font-weightalone cannot fix it. We need a separate channel to thicken glyphs.Approach
Add an opt-in
fontWeightSynthesis: BoolEPUB preference, defaulting to off (nil/false). When it is enabled andfontWeightis greater than 1.0,ReadiumCSSemits a-webkit-text-stroke-widthoverride alongside the existingfont-weightentry:Notes on the design:
em-based. The stroke width scales with the font size instead of being a fixed pixel value.-webkit-text-stroke-coloris intentionally left unset; it defaults tocurrentColor, which tracks the text color across the light, dark and sepia themes.<html>and updated live throughreadium.setCSSProperties.-webkit-text-strokeinherits, so applying it on<html>covers all text, and an empty value clears it on live settings changes (mirroring thefont-weightentry). Both call sites handle the new key without changes.The preference is wired through
EPUBPreferences,EPUBSettings,EPUBDefaultsandEPUBPreferencesEditor, following the exact pattern oftextNormalization.Tests
Added
ReadiumCSSTestscases covering theupdate(with:)mapping: synthesis off emits no stroke; on with weight not above 1.0 or unset emits none; on with weight 1.75 gives0.0175em; on with weight 2.5 gives0.0350em; and an out-of-range weight is clamped to the 2.5 result.Verification
xcodebuild test -scheme Readium-Package -destination 'platform=iOS Simulator,name=iPhone 17' -only-testing:ReadiumNavigatorTests— 110 tests pass, including the 5 new cases.swift run --package-path BuildTools swiftformat --lint .— clean.