Skip to content

fix(platform): add loadFontFace to platform abstraction#805

Merged
jfboeve merged 1 commit into
mainfrom
fix/legacy-platform-font-loading-v2
Jun 8, 2026
Merged

fix(platform): add loadFontFace to platform abstraction#805
jfboeve merged 1 commit into
mainfrom
fix/legacy-platform-font-loading-v2

Conversation

@wouterlucas

Copy link
Copy Markdown
Contributor

WebPlatformLegacy did not override font loading, so it inherited the FontFace JS constructor path from WebPlatform. On embedded/legacy browsers (QtWebKit, older WPEWebKit, some STB browsers) the FontFace API is absent or silently drops loaded fonts before they reach the canvas 2D rasteriser.

Introduce Platform.loadFontFace(family, url) as the single extension point for canvas font loading:

  • WebPlatform: uses new FontFace().load() + document.fonts.add() (existing modern-browser behaviour, unchanged)
  • WebPlatformLegacy: injects a <style> @font-face rule with format hints (.ttf/.woff2/.woff/.otf) and eagerly triggers loading via document.fonts.load() where available; resolves immediately on browsers that lack the CSS Font Loading API so the browser can load the font lazily on first paint.

CanvasFontHandler.loadFont() now delegates to
stage.platform.loadFontFace() instead of constructing FontFace directly, keeping all browser-specific font loading logic inside the platform layer.

Fixes font loading regression introduced in PR #746.

…owser support

WebPlatformLegacy did not override font loading, so it inherited the
FontFace JS constructor path from WebPlatform. On embedded/legacy
browsers (QtWebKit, older WPEWebKit, some STB browsers) the FontFace
API is absent or silently drops loaded fonts before they reach the
canvas 2D rasteriser.

Introduce Platform.loadFontFace(family, url) as the single extension
point for canvas font loading:

- WebPlatform: uses new FontFace().load() + document.fonts.add()
  (existing modern-browser behaviour, unchanged)
- WebPlatformLegacy: injects a <style> @font-face rule with format
  hints (.ttf/.woff2/.woff/.otf) and eagerly triggers loading via
  document.fonts.load() where available; resolves immediately on
  browsers that lack the CSS Font Loading API so the browser can
  load the font lazily on first paint.

CanvasFontHandler.loadFont() now delegates to
stage.platform.loadFontFace() instead of constructing FontFace
directly, keeping all browser-specific font loading logic inside
the platform layer.

Fixes font loading regression introduced in PR #746.
@jfboeve jfboeve merged commit aa7163f into main Jun 8, 2026
2 checks passed
@jfboeve jfboeve deleted the fix/legacy-platform-font-loading-v2 branch June 8, 2026 08:22
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.

3 participants