Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: bbf3da027554a8765a28877dc9776d70be90ec6f
https://github.com/WebKit/WebKit/commit/bbf3da027554a8765a28877dc9776d70be90ec6f
Author: Alan Baradlay <[email protected]>
Date: 2026-06-03 (Wed, 03 Jun 2026)
Changed paths:
A
LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/text/2d.text.draw.align.center.complex-shaping-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/text/2d.text.draw.align.center.complex-shaping.html
M Source/WebCore/platform/graphics/FontCascade.cpp
Log Message:
-----------
Canvas fillText with textAlign=center misplaces complex-shaped text
https://bugs.webkit.org/show_bug.cgi?id=316235
Reviewed by Antti Koivisto.
<canvas id=c width=300 height=200></canvas>
<script>
let ctx = c.getContext("2d");
ctx.font = "152px serif";
ctx.textAlign = "center";
ctx.fillText("\u0BB5", 150, 100);
</script>
The Tamil glyph (U+0BB5) should be centered horizontally on x=150.
Instead it was left-aligned at x=150 - canvas treated the text as zero
width.
The canvas shaped-text cache reads result.width from
FontCascade::layoutComplexText. That function computed the segment width
as controller.totalAdvance().width() before and after advancing the
ComplexTextController, but totalAdvance() is the full run total - it is
populated up front in the controller's constructor and does not change
across advance() calls. So the difference was always zero for any run
that took the complex shaping path. Pre-cache callers only consumed the
glyph buffer and ignored result.width, so the defect was latent.
The fix mirrors layoutSimpleText: use controller.runWidthSoFar() (the
running tally that grows with each advance() call) instead of
totalAdvance().width(). The simple path already did this correctly via
WidthIterator::runWidthSoFar(), which is why Latin text centered
correctly while Tamil/Devanagari/Arabic/emoji did not.
*
LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/text/2d.text.draw.align.center.complex-shaping-expected.txt:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/text/2d.text.draw.align.center.complex-shaping.html:
Added.
* Source/WebCore/platform/graphics/FontCascade.cpp:
(WebCore::FontCascade::layoutComplexText const):
Canonical link: https://commits.webkit.org/314522@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications