canvas: Move font selection and text shaping to script (#38979)

Instead of doing font selection and text shaping in `canvas`, move this
to `script`. This allows canvas to use the shared `Document`
`FontContext`, which has access to web fonts. In addition, ensure that
there is a font style accessible for `OffscreenCanvas` in workers.

Testing: This causes a number of WPT tests to start to pass as web fonts
are
supported on canvas again. In addition, some start to fail as they
expose other
issues:
 - The lack of support for the `Context2D.fontStretch` property
 - Issues with zerosize gradient interpolation.
- Differences between quoted and unquoted font family names. This seems
like
a timing issue with the way we are handling web fonts. The test seems to
be
expecting Local fonts to be available immediately (without waiting for
them
to load). This isn't how Servo works ATM. Seems like an issue with the
test.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-08-28 03:30:34 -07:00 committed by GitHub
parent 91b27d98a2
commit cb64def7e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 604 additions and 809 deletions

View file

@ -0,0 +1,42 @@
[generic-family-keywords-003.html]
[@font-face matching for quoted and unquoted math (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted ui-serif (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted ui-sans-serif (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted ui-monospace (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted ui-rounded (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted sans-serif (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted cursive (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted fantasy (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted monospace (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted system-ui (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted generic(fangsong) (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted generic(kai) (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted generic(khmer-mul) (drawing text in a canvas)]
expected: FAIL
[@font-face matching for quoted and unquoted generic(nastaliq) (drawing text in a canvas)]
expected: FAIL

View file

@ -0,0 +1,2 @@
[canvas.2d.fontStretch.condensed.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[canvas.2d.fontStretch.expanded.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[canvas.2d.fontStretch.extra-condensed.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[canvas.2d.fontStretch.extra-expanded.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[canvas.2d.fontStretch.semi-condensed.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[canvas.2d.fontStretch.semi-expanded.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[canvas.2d.fontStretch.ultra-condensed.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[canvas.2d.fontStretch.ultra-expanded.html]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.align.center.html]
[textAlign center is the center of the em squares (not the bounding box)]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.align.end.ltr.html]
[textAlign end with ltr is the right edge]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.align.left.html]
[textAlign left is the left of the first em square (not the bounding box)]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.align.right.html]
[textAlign right is the right of the last em square (not the bounding box)]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.align.start.ltr.html]
[textAlign start with ltr is the left edge]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.baseline.alphabetic.html]
[Canvas test: 2d.text.draw.baseline.alphabetic]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.baseline.bottom.html]
[textBaseline bottom is the bottom of the em square (not the bounding box)]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.baseline.middle.html]
[textBaseline middle is the middle of the em square (not the bounding box)]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.baseline.top.html]
[textBaseline top is the top of the em square (not the bounding box)]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.fill.maxWidth.bound.html]
[fillText handles maxWidth based on line size, not bounding box size]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.fontface.html]
[Canvas test: 2d.text.draw.fontface]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.fontface.notinpage.html]
[@font-face fonts should work even if they are not used in the page]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.fontface.repeat.html]
[Draw with the font immediately, then wait a bit until and draw again. (This crashes some version of WebKit.)]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.space.collapse.other.html]
[Space characters are converted to U+0020, and are NOT collapsed]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.draw.space.collapse.space.html]
[Space characters are converted to U+0020, and are NOT collapsed]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.measure.emHeights.html]
[Testing emHeights]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.measure.fontBoundingBox.ahem.html]
[Testing fontBoundingBox for font ahem]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.measure.width.basic.html]
[The width of character is same as font used]
expected: FAIL

View file

@ -0,0 +1,3 @@
[2d.gradient.interpolate.zerosize.fillText.html]
[OffscreenCanvas test: 2d.gradient.interpolate.zerosize.fillText]
expected: FAIL

View file

@ -0,0 +1,3 @@
[2d.gradient.interpolate.zerosize.fillText.worker.html]
[2d]
expected: FAIL

View file

@ -2,9 +2,6 @@
[Test that drawing sans-serif produces the same result between canvas and OffscreenCanvas]
expected: FAIL
[Test that drawing serif produces the same result between canvas and OffscreenCanvas]
expected: FAIL
[Test that drawing cursive produces the same result between canvas and OffscreenCanvas]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.drawing.style.measure.rtl.text.html]
[Measurement should follow canvas direction instead text direction]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.drawing.style.measure.rtl.text.worker.html]
[Measurement should follow canvas direction instead text direction]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.drawing.style.measure.textAlign.html]
[Measurement should be related to textAlignment]
expected: FAIL

View file

@ -1,3 +0,0 @@
[2d.text.drawing.style.measure.textAlign.worker.html]
[Measurement should be related to textAlignment]
expected: FAIL

View file

@ -0,0 +1,3 @@
[2d.text.measure.width.nullCharacter.html]
[Null character does not take up space]
expected: FAIL