Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: b0089a4add643baa29ec693a70008a30729adaf8
https://github.com/WebKit/WebKit/commit/b0089a4add643baa29ec693a70008a30729adaf8
Author: Ahmad Saleem <[email protected]>
Date: 2026-08-06 (Thu, 06 Aug 2026)
Changed paths:
A LayoutTests/fast/canvas/canvas-font-relative-size-restyle-expected.txt
A LayoutTests/fast/canvas/canvas-font-relative-size-restyle.html
M Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h
Log Message:
-----------
ctx.font does not re-resolve relative font sizes when set to the same string
after the canvas element's style changed
https://bugs.webkit.org/show_bug.cgi?id=321156
rdar://184194378
Reviewed by Gerald Squelart.
Relative values in the canvas font shorthand ('%', 'em', 'ex', 'larger', ...)
are
resolved against the computed style of the canvas element at the time the font
is
set. CanvasRenderingContext2D::setFontWithoutUpdatingStyle() memoized that work
on
the unparsed font string alone, so assigning the same string again was treated
as a
no-op even when the element's font-size had changed in between, leaving the
context
with a font resolved against a stale style. Nothing else invalidates it either:
the
only invalidation path is FontProxy::fontsNeedUpdate(), which fires for web font
loads rather than for style changes on the canvas.
This is easy to hit in practice, because a page that varies the size through
CSS has
no reason to vary the font string:
canvas.style.fontSize = "40px";
ctx.font = "100% Georgia"; // Ignored if "100% Georgia" was already set.
Compute the base font description before the early return and record it in the
canvas state, so the memoized font is only reused when both the string and the
description it was resolved against still match.
Test: fast/canvas/canvas-font-relative-size-restyle.html
* LayoutTests/fast/canvas/canvas-font-relative-size-restyle-expected.txt: Added.
* LayoutTests/fast/canvas/canvas-font-relative-size-restyle.html: Added.
* Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::setFontWithoutUpdatingStyle):
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h:
Canonical link: https://commits.webkit.org/318753@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications