Truly independent web browser
LibWeb: Add tests of the attributes and operations of 2D contexts
Andreas Kling7bfe6de72520
diff --git a/Tests/LibWeb/Text/expected/canvas/2d-attribute-setters.txt b/Tests/LibWeb/Text/expected/canvas/2d-attribute-setters.txtnew file mode 100644index 00000000000..f4ba5bfd7f9--- /dev/null+++ b/Tests/LibWeb/Text/expected/canvas/2d-attribute-setters.txt@@ -0,0 +1,176 @@+A canvas, the initial state:+ globalAlpha: 1+ globalCompositeOperation: source-over+ imageSmoothingEnabled: true+ imageSmoothingQuality: low+ strokeStyle: #000000+ fillStyle: #000000+ shadowOffsetX: 0+ shadowOffsetY: 0+ shadowBlur: 0+ shadowColor: rgba(0, 0, 0, 0)+ filter: none+ lineWidth: 1+ lineCap: butt+ lineJoin: miter+ miterLimit: 10+ lineDashOffset: 0+ font: 10px sans-serif+ textAlign: start+ textBaseline: alphabetic+ direction: inherit+ letterSpacing: 0px+ getLineDash(): []+ getTransform(): 1,0,0,1,0,0+imageSmoothingQuality: "high" -> high, "bogus" -> high, "LOW" -> high, "" -> high, "medium" -> medium+lineCap: "round" -> round, "bogus" -> round, "SQUARE" -> round, null -> round, "square" -> square+lineJoin: "bevel" -> bevel, "miter " -> bevel, undefined -> bevel, "round" -> round+textAlign: "center" -> center, "middle" -> center, "End" -> center, "end" -> end+textBaseline: "top" -> top, "baseline" -> top, "HANGING" -> top, "hanging" -> hanging+direction: "rtl" -> rtl, "auto" -> rtl, "LTR" -> rtl, "ltr" -> ltr+globalAlpha: 0.5 -> 0.5, -0.1 -> 0.5, 1.5 -> 0.5, NaN -> 0.5, Infinity -> 0.5, 0.3 -> 0.30000001192092896+shadowOffsetX: 1.25 -> 1.25, NaN -> 1.25, -Infinity -> 1.25, -3.1 -> -3.0999999046325684+shadowOffsetY: 2.5 -> 2.5, Infinity -> 2.5, 0.1 -> 0.10000000149011612+shadowBlur: 4 -> 4, -1 -> 4, NaN -> 4, Infinity -> 4, 0.7 -> 0.699999988079071+lineWidth: 3 -> 3, 0 -> 3, -2 -> 3, NaN -> 3, Infinity -> 3, 0.1 -> 0.10000000149011612+miterLimit: 5 -> 5, 0 -> 5, -1 -> 5, NaN -> 5, 1.1 -> 1.100000023841858+lineDashOffset: 7 -> 7, NaN -> 7, Infinity -> 7, -0.2 -> -0.20000000298023224+globalCompositeOperation: "multiply" -> multiply, "bogus" -> multiply, "XOR" -> multiply, "plus-lighter" -> plus-lighter, "destination-atop" -> destination-atop+shadowColor: "red" -> #ff0000, "bogus" -> #ff0000, "rgba(1, 2, 3, 0.5)" -> rgba(1, 2, 3, 0.5), "#abc" -> #aabbcc+strokeStyle: "blue" -> #0000ff, "not a color" -> #0000ff, "hsl(120, 100%, 50%)" -> #00ff00+fillStyle: "#123456" -> #123456, "rgb(1 2 3 / 50%)" -> rgba(1, 2, 3, 0.5), "nope" -> rgba(1, 2, 3, 0.5), "transparent" -> rgba(0, 0, 0, 0)+filter: "blur(2px)" -> blur(2px), "bogus" -> blur(2px), "none" -> none, "brightness(50%) blur(1em)" -> brightness(50%) blur(1em), "inherit" -> brightness(50%) blur(1em)+font: "20px serif" -> 20px serif, "bogus" -> 20px serif, "italic bold 12px/30px monospace" -> italic 700 12px monospace, "inherit" -> italic 700 12px monospace, "small-caps 1em sans-serif" -> small-caps 10px sans-serif+letterSpacing: "2px" -> 2px, "bogus" -> 2px, "1em" -> 1em, "0" -> 0px, "3.5pt" -> 3.5pt+imageSmoothingEnabled: false+setLineDash([1,2]) -> [1,2]+setLineDash([3]) -> [3,3]+setLineDash([1,-1]) -> [3,3]+setLineDash([1,NaN]) -> [3,3]+setLineDash([]) -> []+setLineDash([0.1,0.2,0.3]) -> [0.1,0.2,0.3,0.1,0.2,0.3]+transforms: 1.2320507764816284,2.7990379333496094,-0.5669872760772705,2.973076105117798,11.196151733398438,34.892303466796875+getTransform() is a new object: true+setTransform(six numbers): 1.100000023841858,2.200000047683716,3.299999952316284,4.400000095367432,5.5,6.599999904632568+setTransform(dictionary): 2,0,0,3,4,0+setTransform(infinite member): 2,0,0,3,4,0+setTransform(inconsistent members): TypeError: DOMMatrix2DInit.a and DOMMatrix2DInit.m11 must have the same value if they are both present+setTransform(): 1,0,0,1,0,0+after one restore(): lineWidth 11, lineCap square, font 30px monospace+after two more restore(): lineWidth 9, font small-caps 10px sans-serif, e 0+isContextLost(): false+getContextAttributes(): {"alpha":true,"colorSpace":"srgb","colorType":"unorm8","desynchronized":false,"willReadFrequently":false}+A canvas, after reset():+ globalAlpha: 1+ globalCompositeOperation: source-over+ imageSmoothingEnabled: true+ imageSmoothingQuality: low+ strokeStyle: #000000+ fillStyle: #000000+ shadowOffsetX: 0+ shadowOffsetY: 0+ shadowBlur: 0+ shadowColor: rgba(0, 0, 0, 0)+ filter: none+ lineWidth: 1+ lineCap: butt+ lineJoin: miter+ miterLimit: 10+ lineDashOffset: 0+ font: 10px sans-serif+ textAlign: start+ textBaseline: alphabetic+ direction: inherit+ letterSpacing: 0px+ getLineDash(): []+ getTransform(): 1,0,0,1,0,0+isPointInStroke: undefined, drawFocusIfNeeded: undefined+canvas: true+An OffscreenCanvas, the initial state:+ globalAlpha: 1+ globalCompositeOperation: source-over+ imageSmoothingEnabled: true+ imageSmoothingQuality: low+ strokeStyle: #000000+ fillStyle: #000000+ shadowOffsetX: 0+ shadowOffsetY: 0+ shadowBlur: 0+ shadowColor: rgba(0, 0, 0, 0)+ filter: none+ lineWidth: 1+ lineCap: butt+ lineJoin: miter+ miterLimit: 10+ lineDashOffset: 0+ font: 10px sans-serif+ textAlign: start+ textBaseline: alphabetic+ direction: inherit+ letterSpacing: 0px+ getLineDash(): []+ getTransform(): 1,0,0,1,0,0+imageSmoothingQuality: "high" -> high, "bogus" -> high, "LOW" -> high, "" -> high, "medium" -> medium+lineCap: "round" -> round, "bogus" -> round, "SQUARE" -> round, null -> round, "square" -> square+lineJoin: "bevel" -> bevel, "miter " -> bevel, undefined -> bevel, "round" -> round+textAlign: "center" -> center, "middle" -> center, "End" -> center, "end" -> end+textBaseline: "top" -> top, "baseline" -> top, "HANGING" -> top, "hanging" -> hanging+direction: "rtl" -> rtl, "auto" -> rtl, "LTR" -> rtl, "ltr" -> ltr+globalAlpha: 0.5 -> 0.5, -0.1 -> 0.5, 1.5 -> 0.5, NaN -> 0.5, Infinity -> 0.5, 0.3 -> 0.30000001192092896+shadowOffsetX: 1.25 -> 1.25, NaN -> 1.25, -Infinity -> 1.25, -3.1 -> -3.0999999046325684+shadowOffsetY: 2.5 -> 2.5, Infinity -> 2.5, 0.1 -> 0.10000000149011612+shadowBlur: 4 -> 4, -1 -> 4, NaN -> 4, Infinity -> 4, 0.7 -> 0.699999988079071+lineWidth: 3 -> 3, 0 -> 3, -2 -> 3, NaN -> 3, Infinity -> 3, 0.1 -> 0.10000000149011612+miterLimit: 5 -> 5, 0 -> 5, -1 -> 5, NaN -> 5, 1.1 -> 1.100000023841858+lineDashOffset: 7 -> 7, NaN -> 7, Infinity -> 7, -0.2 -> -0.20000000298023224+globalCompositeOperation: "multiply" -> multiply, "bogus" -> multiply, "XOR" -> multiply, "plus-lighter" -> plus-lighter, "destination-atop" -> destination-atop+shadowColor: "red" -> #ff0000, "bogus" -> #ff0000, "rgba(1, 2, 3, 0.5)" -> rgba(1, 2, 3, 0.5), "#abc" -> #aabbcc+strokeStyle: "blue" -> #0000ff, "not a color" -> #0000ff, "hsl(120, 100%, 50%)" -> #00ff00+fillStyle: "#123456" -> #123456, "rgb(1 2 3 / 50%)" -> rgba(1, 2, 3, 0.5), "nope" -> rgba(1, 2, 3, 0.5), "transparent" -> rgba(0, 0, 0, 0)+filter: "blur(2px)" -> blur(2px), "bogus" -> blur(2px), "none" -> none, "brightness(50%) blur(1em)" -> brightness(50%) blur(1em), "inherit" -> brightness(50%) blur(1em)+font: "20px serif" -> 20px serif, "bogus" -> 20px serif, "italic bold 12px/30px monospace" -> italic 700 12px monospace, "inherit" -> italic 700 12px monospace, "small-caps 1em sans-serif" -> small-caps 10px sans-serif+letterSpacing: "2px" -> 2px, "bogus" -> 2px, "1em" -> 1em, "0" -> 0px, "3.5pt" -> 3.5pt+imageSmoothingEnabled: false+setLineDash([1,2]) -> [1,2]+setLineDash([3]) -> [3,3]+setLineDash([1,-1]) -> [3,3]+setLineDash([1,NaN]) -> [3,3]+setLineDash([]) -> []+setLineDash([0.1,0.2,0.3]) -> [0.1,0.2,0.3,0.1,0.2,0.3]+transforms: 1.2320507764816284,2.7990379333496094,-0.5669872760772705,2.973076105117798,11.196151733398438,34.892303466796875+getTransform() is a new object: true+setTransform(six numbers): 1.100000023841858,2.200000047683716,3.299999952316284,4.400000095367432,5.5,6.599999904632568+setTransform(dictionary): 2,0,0,3,4,0+setTransform(infinite member): 2,0,0,3,4,0+setTransform(inconsistent members): TypeError: DOMMatrix2DInit.a and DOMMatrix2DInit.m11 must have the same value if they are both present+setTransform(): 1,0,0,1,0,0+after one restore(): lineWidth 11, lineCap square, font 30px monospace+after two more restore(): lineWidth 9, font small-caps 10px sans-serif, e 0+isContextLost(): false+getContextAttributes(): {"alpha":false,"colorSpace":"srgb","colorType":"unorm8","desynchronized":false,"willReadFrequently":true}+An OffscreenCanvas, after reset():+ globalAlpha: 1+ globalCompositeOperation: source-over+ imageSmoothingEnabled: true+ imageSmoothingQuality: low+ strokeStyle: #000000+ fillStyle: #000000+ shadowOffsetX: 0+ shadowOffsetY: 0+ shadowBlur: 0+ shadowColor: rgba(0, 0, 0, 0)+ filter: none+ lineWidth: 1+ lineCap: butt+ lineJoin: miter+ miterLimit: 10+ lineDashOffset: 0+ font: 10px sans-serif+ textAlign: start+ textBaseline: alphabetic+ direction: inherit+ letterSpacing: 0px+ getLineDash(): []+ getTransform(): 1,0,0,1,0,0+isPointInStroke: undefined, drawFocusIfNeeded: undefined+canvas: truediff --git a/Tests/LibWeb/Text/expected/canvas/2d-image-data-arguments.txt b/Tests/LibWeb/Text/expected/canvas/2d-image-data-arguments.txtnew file mode 100644index 00000000000..ecf5909f48d--- /dev/null+++ b/Tests/LibWeb/Text/expected/canvas/2d-image-data-arguments.txt@@ -0,0 +1,104 @@+A canvas:+getImageData(0, 0, 2, 1): ImageData 2x1 [10,20,30,255,10,20,30,255]+getImageData(1.9, 0.5, 2.9, 1.2): ImageData 2x1 [10,20,30,255,0,0,0,0]+getImageData(3, 2, -2, -2): ImageData 2x2 [10,20,30,255,0,0,0,0,10,20,30,255,199,100,50,128]+getImageData(-1, -1, 2, 2): ImageData 2x2 [0,0,0,0,0,0,0,0,0,0,0,0,10,20,30,255]+getImageData(10, 10, 1, 1): ImageData 1x1 [0,0,0,0]+getImageData(0, 0, 0, 1): DOMException IndexSizeError: Width and height must not be zero+getImageData(NaN, 0, 1, 1): TypeError: Number must not be NaN or Infinity+getImageData(0, Infinity, 1, 1): TypeError: Number must not be NaN or Infinity+getImageData(2 ** 31, 0, 1, 1): TypeError: Number '2147483648' is outside of allowed range of -2147483648 to 2147483647+getImageData(0, -(2 ** 31) - 1, 1, 1): TypeError: Number '-2147483649' is outside of allowed range of -2147483648 to 2147483647+getImageData(-(2 ** 31), -(2 ** 31), 1, 1): ImageData 1x1 [0,0,0,0]+getImageData(0, 0, 1, 1e300): TypeError: Number '1e+300' is outside of allowed range of -2147483648 to 2147483647+getImageData(2 ** 31 - 1, 2 ** 31 - 1, 1, 1): ImageData 1x1 [0,0,0,0]+getImageData(0, 0, "2", [1]): ImageData 2x1 [10,20,30,255,10,20,30,255]+getImageData(0, 0, 1, 1, { colorSpace: "bogus" }): TypeError: Invalid value 'bogus' for enumeration type 'PredefinedColorSpace'+getImageData(0, 0, 1, 1, { colorSpace: "display-p3" }).colorSpace: display-p3+createImageData(2, 1): ImageData 2x1 [0,0,0,0,0,0,0,0]+createImageData(-2, -1): ImageData 2x1 [0,0,0,0,0,0,0,0]+createImageData(0, 1): DOMException IndexSizeError: Width and height must not be zero+createImageData(1, NaN): TypeError: Number must not be NaN or Infinity+createImageData(2 ** 31, 1): TypeError: Number '2147483648' is outside of allowed range of -2147483648 to 2147483647+createImageData(1.99, -1.99): ImageData 1x1 [0,0,0,0]+createImageData(-(2 ** 31), 1): DOMException IndexSizeError: The specified image size could not created+createImageData(new ImageData(3, 1)): ImageData 3x1 [0,0,0,0,0,0,0,0,0,0,0,0]+createImageData(1, 1, { colorSpace: "srgb-linear" }).colorSpace: srgb-linear+createImageData(null): TypeError: Not an object of type ImageData+putImageData(source, Infinity, 0): TypeError: Number must not be NaN or Infinity+putImageData(source, 0, 2 ** 31): TypeError: Number '2147483648' is outside of allowed range of -2147483648 to 2147483647+putImageData(source, 0, 0, 0, 0, NaN, 1): TypeError: Number must not be NaN or Infinity+putImageData(source, 3, 2): no exception+after it, getImageData(0, 0, 4, 3): ImageData 4x3 [10,20,30,255,10,20,30,255,0,0,0,0,0,0,0,0,10,20,30,255,10,20,30,255,199,100,50,128,199,100,50,128,0,0,0,0,0,0,0,0,199,100,50,128,255,0,0,255]+putImageData(source, 0, 0, 1, 1, -5, -5): no exception+after it, getImageData(0, 0, 4, 3): ImageData 4x3 [255,0,0,255,10,20,30,255,0,0,0,0,0,0,0,0,10,20,30,255,10,20,30,255,199,100,50,128,199,100,50,128,0,0,0,0,0,0,0,0,199,100,50,128,255,0,0,255]+putImageData(source, 1, 0, -1, -1, 2, 3): no exception+after it, getImageData(0, 0, 4, 3): ImageData 4x3 [255,0,0,255,255,0,0,255,0,0,0,0,0,0,0,0,10,20,30,255,0,0,255,255,199,100,50,128,199,100,50,128,0,0,0,0,0,0,0,0,199,100,50,128,255,0,0,255]+putImageData(source, -(2 ** 31), -(2 ** 31), 2 ** 31 - 1, 2 ** 31 - 1, 2 ** 31 - 1, 2 ** 31 - 1): no exception+putImageData(source, 2 ** 31 - 1, 2 ** 31 - 1, -(2 ** 31), -(2 ** 31), -(2 ** 31), -(2 ** 31)): no exception+putImageData(source, -1, -1, 0, 0, 2 ** 31 - 1, 2 ** 31 - 1): no exception+after it, getImageData(0, 0, 4, 3): ImageData 4x3 [0,0,0,4,255,0,0,255,0,0,0,0,0,0,0,0,10,20,30,255,0,0,255,255,199,100,50,128,199,100,50,128,0,0,0,0,0,0,0,0,199,100,50,128,255,0,0,255]+putImageData(detached, 0, 0): DOMException InvalidStateError: ImageData's underlying buffer is detached+createPattern(canvas, null) repeats: true+createPattern(canvas, ""): true+createPattern(canvas, "repeat-x"): true+createPattern(canvas, "Repeat"): DOMException SyntaxError: Repetition value is not valid+createPattern(canvas, undefined): DOMException SyntaxError: Repetition value is not valid+createPattern(canvas without width, "repeat"): DOMException InvalidStateError: Canvas width or height is zero+createPattern(new OffscreenCanvas(0, 1), "repeat"): DOMException InvalidStateError: OffscreenCanvas width or height is zero+createPattern(new Image(), "repeat"): null+createPattern({}, "repeat"): TypeError: No union types matched+createPattern(canvas): TypeError: createPattern() needs 2 arguments+An OffscreenCanvas:+getImageData(0, 0, 2, 1): ImageData 2x1 [10,20,30,255,10,20,30,255]+getImageData(1.9, 0.5, 2.9, 1.2): ImageData 2x1 [10,20,30,255,0,0,0,0]+getImageData(3, 2, -2, -2): ImageData 2x2 [10,20,30,255,0,0,0,0,10,20,30,255,199,100,50,128]+getImageData(-1, -1, 2, 2): ImageData 2x2 [0,0,0,0,0,0,0,0,0,0,0,0,10,20,30,255]+getImageData(10, 10, 1, 1): ImageData 1x1 [0,0,0,0]+getImageData(0, 0, 0, 1): DOMException IndexSizeError: Width and height must not be zero+getImageData(NaN, 0, 1, 1): TypeError: Number must not be NaN or Infinity+getImageData(0, Infinity, 1, 1): TypeError: Number must not be NaN or Infinity+getImageData(2 ** 31, 0, 1, 1): TypeError: Number '2147483648' is outside of allowed range of -2147483648 to 2147483647+getImageData(0, -(2 ** 31) - 1, 1, 1): TypeError: Number '-2147483649' is outside of allowed range of -2147483648 to 2147483647+getImageData(-(2 ** 31), -(2 ** 31), 1, 1): ImageData 1x1 [0,0,0,0]+getImageData(0, 0, 1, 1e300): TypeError: Number '1e+300' is outside of allowed range of -2147483648 to 2147483647+getImageData(2 ** 31 - 1, 2 ** 31 - 1, 1, 1): ImageData 1x1 [0,0,0,0]+getImageData(0, 0, "2", [1]): ImageData 2x1 [10,20,30,255,10,20,30,255]+getImageData(0, 0, 1, 1, { colorSpace: "bogus" }): TypeError: Invalid value 'bogus' for enumeration type 'PredefinedColorSpace'+getImageData(0, 0, 1, 1, { colorSpace: "display-p3" }).colorSpace: display-p3+createImageData(2, 1): ImageData 2x1 [0,0,0,0,0,0,0,0]+createImageData(-2, -1): ImageData 2x1 [0,0,0,0,0,0,0,0]+createImageData(0, 1): DOMException IndexSizeError: Width and height must not be zero+createImageData(1, NaN): TypeError: Number must not be NaN or Infinity+createImageData(2 ** 31, 1): TypeError: Number '2147483648' is outside of allowed range of -2147483648 to 2147483647+createImageData(1.99, -1.99): ImageData 1x1 [0,0,0,0]+createImageData(-(2 ** 31), 1): DOMException IndexSizeError: The specified image size could not created+createImageData(new ImageData(3, 1)): ImageData 3x1 [0,0,0,0,0,0,0,0,0,0,0,0]+createImageData(1, 1, { colorSpace: "srgb-linear" }).colorSpace: srgb-linear+createImageData(null): TypeError: Not an object of type ImageData+putImageData(source, Infinity, 0): TypeError: Number must not be NaN or Infinity+putImageData(source, 0, 2 ** 31): TypeError: Number '2147483648' is outside of allowed range of -2147483648 to 2147483647+putImageData(source, 0, 0, 0, 0, NaN, 1): TypeError: Number must not be NaN or Infinity+putImageData(source, 3, 2): no exception+after it, getImageData(0, 0, 4, 3): ImageData 4x3 [10,20,30,255,10,20,30,255,0,0,0,0,0,0,0,0,10,20,30,255,10,20,30,255,199,100,50,128,199,100,50,128,0,0,0,0,0,0,0,0,199,100,50,128,255,0,0,255]+putImageData(source, 0, 0, 1, 1, -5, -5): no exception+after it, getImageData(0, 0, 4, 3): ImageData 4x3 [255,0,0,255,10,20,30,255,0,0,0,0,0,0,0,0,10,20,30,255,10,20,30,255,199,100,50,128,199,100,50,128,0,0,0,0,0,0,0,0,199,100,50,128,255,0,0,255]+putImageData(source, 1, 0, -1, -1, 2, 3): no exception+after it, getImageData(0, 0, 4, 3): ImageData 4x3 [255,0,0,255,255,0,0,255,0,0,0,0,0,0,0,0,10,20,30,255,0,0,255,255,199,100,50,128,199,100,50,128,0,0,0,0,0,0,0,0,199,100,50,128,255,0,0,255]+putImageData(source, -(2 ** 31), -(2 ** 31), 2 ** 31 - 1, 2 ** 31 - 1, 2 ** 31 - 1, 2 ** 31 - 1): no exception+putImageData(source, 2 ** 31 - 1, 2 ** 31 - 1, -(2 ** 31), -(2 ** 31), -(2 ** 31), -(2 ** 31)): no exception+putImageData(source, -1, -1, 0, 0, 2 ** 31 - 1, 2 ** 31 - 1): no exception+after it, getImageData(0, 0, 4, 3): ImageData 4x3 [0,0,0,4,255,0,0,255,0,0,0,0,0,0,0,0,10,20,30,255,0,0,255,255,199,100,50,128,199,100,50,128,0,0,0,0,0,0,0,0,199,100,50,128,255,0,0,255]+putImageData(detached, 0, 0): DOMException InvalidStateError: ImageData's underlying buffer is detached+createPattern(canvas, null) repeats: true+createPattern(canvas, ""): true+createPattern(canvas, "repeat-x"): true+createPattern(canvas, "Repeat"): DOMException SyntaxError: Repetition value is not valid+createPattern(canvas, undefined): DOMException SyntaxError: Repetition value is not valid+createPattern(canvas without width, "repeat"): DOMException InvalidStateError: Canvas width or height is zero+createPattern(new OffscreenCanvas(0, 1), "repeat"): DOMException InvalidStateError: OffscreenCanvas width or height is zero+createPattern(new Image(), "repeat"): null+createPattern({}, "repeat"): TypeError: No union types matched+createPattern(canvas): TypeError: createPattern() needs 2 arguments+createPattern(closed ImageBitmap, "repeat"): DOMException InvalidStateError: Image bitmap is detached+drawImage(closed ImageBitmap, 0, 0): DOMException InvalidStateError: Image bitmap is detacheddiff --git a/Tests/LibWeb/Text/expected/canvas/2d-is-point-in-path.txt b/Tests/LibWeb/Text/expected/canvas/2d-is-point-in-path.txtnew file mode 100644index 00000000000..2667de06ad3--- /dev/null+++ b/Tests/LibWeb/Text/expected/canvas/2d-is-point-in-path.txt@@ -0,0 +1,56 @@+A canvas:+ two rectangles, nonzero: 1101000+ two rectangles, evenodd: 1100000+ a translated rectangle: 0111001+ after a later scale: 0111001+ under a singular transform: 1010000+ a Path2D circle: 0101000+ a Path2D circle under a rotation: 0000000+ an empty Path2D: 0000000+ isPointInPath(): TypeError: Overload resolution failed+ isPointInPath(1): TypeError: Overload resolution failed+ isPointInPath(1, 2, "bogus"): TypeError: Invalid value 'bogus' for enumeration type 'CanvasFillRule'+ isPointInPath(path, 1): false+ isPointInPath({}, 1, 2): TypeError: Invalid value '2' for enumeration type 'CanvasFillRule'+ fill("bogus"): TypeError: Invalid value 'bogus' for enumeration type 'CanvasFillRule'+ fill(null): TypeError: Invalid value 'null' for enumeration type 'CanvasFillRule'+ clip(path, "bogus"): TypeError: Invalid value 'bogus' for enumeration type 'CanvasFillRule'+ stroke(null): TypeError: Not an object of type Path2D+ drawImage(null, 0, 0): TypeError: No union types matched+ drawImage(canvas, 0): TypeError: Overload resolution failed+ drawImage(canvas, 0, 0, 1): TypeError: Overload resolution failed+ drawImage(canvas, 0, 0, 1, 1, 1, 1): TypeError: Overload resolution failed+ setTransform(1, 2): TypeError: Overload resolution failed+ putImageData(new ImageData(1, 1), 0, 0, 0): TypeError: Overload resolution failed+ createImageData(): TypeError: Overload resolution failed+ fillText("a", 1): TypeError: fillText() needs 3 arguments+ fillStyle = {}: #000000+ fillStyle = new Path2D(): #000000+An OffscreenCanvas:+ two rectangles, nonzero: 1101000+ two rectangles, evenodd: 1100000+ a translated rectangle: 0111001+ after a later scale: 0111001+ under a singular transform: 1010000+ a Path2D circle: 0101000+ a Path2D circle under a rotation: 0000000+ an empty Path2D: 0000000+ isPointInPath(): TypeError: Overload resolution failed+ isPointInPath(1): TypeError: Overload resolution failed+ isPointInPath(1, 2, "bogus"): TypeError: Invalid value 'bogus' for enumeration type 'CanvasFillRule'+ isPointInPath(path, 1): false+ isPointInPath({}, 1, 2): TypeError: Invalid value '2' for enumeration type 'CanvasFillRule'+ fill("bogus"): TypeError: Invalid value 'bogus' for enumeration type 'CanvasFillRule'+ fill(null): TypeError: Invalid value 'null' for enumeration type 'CanvasFillRule'+ clip(path, "bogus"): TypeError: Invalid value 'bogus' for enumeration type 'CanvasFillRule'+ stroke(null): TypeError: Not an object of type Path2D+ drawImage(null, 0, 0): TypeError: No union types matched+ drawImage(canvas, 0): TypeError: Overload resolution failed+ drawImage(canvas, 0, 0, 1): TypeError: Overload resolution failed+ drawImage(canvas, 0, 0, 1, 1, 1, 1): TypeError: Overload resolution failed+ setTransform(1, 2): TypeError: Overload resolution failed+ putImageData(new ImageData(1, 1), 0, 0, 0): TypeError: Overload resolution failed+ createImageData(): TypeError: Overload resolution failed+ fillText("a", 1): TypeError: fillText() needs 3 arguments+ fillStyle = {}: #000000+ fillStyle = new Path2D(): #000000diff --git a/Tests/LibWeb/Text/expected/canvas/2d-measure-text.txt b/Tests/LibWeb/Text/expected/canvas/2d-measure-text.txtnew file mode 100644index 00000000000..06afbc3a388--- /dev/null+++ b/Tests/LibWeb/Text/expected/canvas/2d-measure-text.txt@@ -0,0 +1,114 @@+A canvas:+ 10px sans-serif+ "": 0, 0, 0, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ " ": 5, 0, 5, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ "Hello, world!": 61.953125, 0, 61.953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ "a\tb\nc\fd\re": 47.6875, 0, 47.6875, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ "é😀漢字 mixed": 55.578125, 0, 55.578125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ "\ud800 lone": 29.21875, 0, 29.21875, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ 23px serif+ "": 0, 0, 0, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ " ": 11.5, 0, 11.5, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ "Hello, world!": 142.59375, 0, 142.59375, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ "a\tb\nc\fd\re": 109.65625, 0, 109.65625, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ "é😀漢字 mixed": 127.8125, 0, 127.8125, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ "\ud800 lone": 67.234375, 0, 67.234375, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ 700 17.5px monospace+ "": 0, 0, 0, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ " ": 8.75, 0, 8.75, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ "Hello, world!": 108.4375, 0, 108.4375, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ "a\tb\nc\fd\re": 83.421875, 0, 83.421875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ "é😀漢字 mixed": 97.203125, 0, 97.203125, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ "\ud800 lone": 51.140625, 0, 51.140625, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ italic 9px sans-serif+ "": 0, 0, 0, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ " ": 4.5, 0, 4.5, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ "Hello, world!": 55.78125, 0, 55.78125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ "a\tb\nc\fd\re": 42.90625, 0, 42.90625, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ "é😀漢字 mixed": 49.96875, 0, 49.96875, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ "\ud800 lone": 26.296875, 0, 26.296875, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ textBaseline top+ "Baseline": 59.90625, 0, 59.90625, 0, 15, 0, 15, 0, 15, -2.3994140625, -11.9970703125, -15+ textBaseline hanging+ "Baseline": 59.90625, 0, 59.90625, 2.3994140625, 12.6005859375, 2.3994140625, 12.6005859375, 2.3994140625, 12.6005859375, 0, -9.59765625, -12.6005859375+ textBaseline middle+ "Baseline": 59.90625, 0, 59.90625, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 5.1005859375, -4.4970703125, -7.5+ textBaseline alphabetic+ "Baseline": 59.90625, 0, 59.90625, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textBaseline ideographic+ "Baseline": 59.90625, 0, 59.90625, 15, 0, 15, 0, 15, 0, 12.6005859375, 3.0029296875, 0+ textBaseline bottom+ "Baseline": 59.90625, 0, 59.90625, 15, 0, 15, 0, 15, 0, 12.6005859375, 3.0029296875, 0+ letterSpacing 3px+ "Spaced out": 115.5, 0, 115.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ letterSpacing -1px+ "Spaced out": 75.5, 0, 75.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ letterSpacing 0.5em+ "Spaced out": 160.5, 0, 160.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textAlign start+ "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textAlign end+ "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textAlign left+ "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textAlign right+ "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textAlign center+ "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+An OffscreenCanvas:+ 10px sans-serif+ "": 0, 0, 0, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ " ": 5, 0, 5, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ "Hello, world!": 61.953125, 0, 61.953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ "a\tb\nc\fd\re": 47.6875, 0, 47.6875, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ "é😀漢字 mixed": 55.578125, 0, 55.578125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ "\ud800 lone": 29.21875, 0, 29.21875, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125+ 23px serif+ "": 0, 0, 0, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ " ": 11.5, 0, 11.5, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ "Hello, world!": 142.59375, 0, 142.59375, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ "a\tb\nc\fd\re": 109.65625, 0, 109.65625, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ "é😀漢字 mixed": 127.8125, 0, 127.8125, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ "\ud800 lone": 67.234375, 0, 67.234375, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875+ 700 17.5px monospace+ "": 0, 0, 0, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ " ": 8.75, 0, 8.75, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ "Hello, world!": 108.4375, 0, 108.4375, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ "a\tb\nc\fd\re": 83.421875, 0, 83.421875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ "é😀漢字 mixed": 97.203125, 0, 97.203125, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ "\ud800 lone": 51.140625, 0, 51.140625, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875+ italic 9px sans-serif+ "": 0, 0, 0, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ " ": 4.5, 0, 4.5, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ "Hello, world!": 55.78125, 0, 55.78125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ "a\tb\nc\fd\re": 42.90625, 0, 42.90625, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ "é😀漢字 mixed": 49.96875, 0, 49.96875, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ "\ud800 lone": 26.296875, 0, 26.296875, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125+ textBaseline top+ "Baseline": 59.90625, 0, 59.90625, 0, 15, 0, 15, 0, 15, -2.3994140625, -11.9970703125, -15+ textBaseline hanging+ "Baseline": 59.90625, 0, 59.90625, 2.3994140625, 12.6005859375, 2.3994140625, 12.6005859375, 2.3994140625, 12.6005859375, 0, -9.59765625, -12.6005859375+ textBaseline middle+ "Baseline": 59.90625, 0, 59.90625, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 5.1005859375, -4.4970703125, -7.5+ textBaseline alphabetic+ "Baseline": 59.90625, 0, 59.90625, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textBaseline ideographic+ "Baseline": 59.90625, 0, 59.90625, 15, 0, 15, 0, 15, 0, 12.6005859375, 3.0029296875, 0+ textBaseline bottom+ "Baseline": 59.90625, 0, 59.90625, 15, 0, 15, 0, 15, 0, 12.6005859375, 3.0029296875, 0+ letterSpacing 3px+ "Spaced out": 115.5, 0, 115.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ letterSpacing -1px+ "Spaced out": 75.5, 0, 75.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ letterSpacing 0.5em+ "Spaced out": 160.5, 0, 160.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textAlign start+ "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textAlign end+ "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textAlign left+ "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textAlign right+ "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875+ textAlign center+ "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875diff --git a/Tests/LibWeb/Text/input/canvas/2d-attribute-setters.html b/Tests/LibWeb/Text/input/canvas/2d-attribute-setters.htmlnew file mode 100644index 00000000000..913b2062679--- /dev/null+++ b/Tests/LibWeb/Text/input/canvas/2d-attribute-setters.html@@ -0,0 +1,145 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ function printState(context) {+ const names = [+ "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled", "imageSmoothingQuality",+ "strokeStyle", "fillStyle", "shadowOffsetX", "shadowOffsetY", "shadowBlur", "shadowColor", "filter",+ "lineWidth", "lineCap", "lineJoin", "miterLimit", "lineDashOffset", "font", "textAlign", "textBaseline",+ "direction", "letterSpacing",+ ];+ for (const name of names)+ println(` ${name}: ${context[name]}`);+ println(` getLineDash(): [${context.getLineDash()}]`);+ const transform = context.getTransform();+ println(` getTransform(): ${[transform.a, transform.b, transform.c, transform.d, transform.e, transform.f]}`);+ }++ function exercise(label, context) {+ println(`${label}, the initial state:`);+ printState(context);++ const enumeratedValues = {+ imageSmoothingQuality: ["high", "bogus", "LOW", "", "medium"],+ lineCap: ["round", "bogus", "SQUARE", null, "square"],+ lineJoin: ["bevel", "miter ", undefined, "round"],+ textAlign: ["center", "middle", "End", "end"],+ textBaseline: ["top", "baseline", "HANGING", "hanging"],+ direction: ["rtl", "auto", "LTR", "ltr"],+ };+ for (const [name, values] of Object.entries(enumeratedValues)) {+ const results = [];+ for (const value of values) {+ context[name] = value;+ results.push(`${JSON.stringify(value)} -> ${context[name]}`);+ }+ println(`${name}: ${results.join(", ")}`);+ }++ const numericValues = {+ globalAlpha: [0.5, -0.1, 1.5, NaN, Infinity, 0.3],+ shadowOffsetX: [1.25, NaN, -Infinity, -3.1],+ shadowOffsetY: [2.5, Infinity, 0.1],+ shadowBlur: [4, -1, NaN, Infinity, 0.7],+ lineWidth: [3, 0, -2, NaN, Infinity, 0.1],+ miterLimit: [5, 0, -1, NaN, 1.1],+ lineDashOffset: [7, NaN, Infinity, -0.2],+ };+ for (const [name, values] of Object.entries(numericValues)) {+ const results = [];+ for (const value of values) {+ context[name] = value;+ results.push(`${value} -> ${context[name]}`);+ }+ println(`${name}: ${results.join(", ")}`);+ }++ const stringValues = {+ globalCompositeOperation: ["multiply", "bogus", "XOR", "plus-lighter", "destination-atop"],+ shadowColor: ["red", "bogus", "rgba(1, 2, 3, 0.5)", "#abc"],+ strokeStyle: ["blue", "not a color", "hsl(120, 100%, 50%)"],+ fillStyle: ["#123456", "rgb(1 2 3 / 50%)", "nope", "transparent"],+ filter: ["blur(2px)", "bogus", "none", "brightness(50%) blur(1em)", "inherit"],+ font: ["20px serif", "bogus", "italic bold 12px/30px monospace", "inherit", "small-caps 1em sans-serif"],+ letterSpacing: ["2px", "bogus", "1em", "0", "3.5pt"],+ };+ for (const [name, values] of Object.entries(stringValues)) {+ const results = [];+ for (const value of values) {+ context[name] = value;+ results.push(`${JSON.stringify(value)} -> ${context[name]}`);+ }+ println(`${name}: ${results.join(", ")}`);+ }++ context.imageSmoothingEnabled = false;+ println(`imageSmoothingEnabled: ${context.imageSmoothingEnabled}`);++ const dashes = [[1, 2], [3], [1, -1], [1, NaN], [], [0.1, 0.2, 0.3]];+ for (const dash of dashes) {+ context.setLineDash(dash);+ println(`setLineDash([${dash}]) -> [${context.getLineDash()}]`);+ }++ context.resetTransform();+ context.translate(10, 20);+ context.scale(2, 3);+ context.rotate(Math.PI / 6);+ context.transform(1, 0.5, 0.25, 1, 3, 4);+ context.translate(NaN, 1);+ let transform = context.getTransform();+ println(`transforms: ${[transform.a, transform.b, transform.c, transform.d, transform.e, transform.f]}`);+ println(`getTransform() is a new object: ${context.getTransform() !== context.getTransform()}`);+ context.setTransform(1.1, 2.2, 3.3, 4.4, 5.5, 6.6);+ transform = context.getTransform();+ println(`setTransform(six numbers): ${[transform.a, transform.b, transform.c, transform.d, transform.e, transform.f]}`);+ context.setTransform({ a: 2, d: 3, e: 4 });+ transform = context.getTransform();+ println(`setTransform(dictionary): ${[transform.a, transform.b, transform.c, transform.d, transform.e, transform.f]}`);+ context.setTransform({ m11: Infinity });+ transform = context.getTransform();+ println(`setTransform(infinite member): ${[transform.a, transform.b, transform.c, transform.d, transform.e, transform.f]}`);+ try {+ context.setTransform({ a: 1, m11: 2 });+ println("setTransform(inconsistent members): no exception");+ } catch (e) {+ println(`setTransform(inconsistent members): ${e.constructor.name}: ${e.message}`);+ }+ context.setTransform();+ transform = context.getTransform();+ println(`setTransform(): ${[transform.a, transform.b, transform.c, transform.d, transform.e, transform.f]}`);++ context.lineWidth = 9;+ context.save();+ context.lineWidth = 11;+ context.font = "30px monospace";+ context.translate(5, 5);+ context.save();+ context.lineCap = "square";+ context.restore();+ println(`after one restore(): lineWidth ${context.lineWidth}, lineCap ${context.lineCap}, font ${context.font}`);+ context.restore();+ context.restore();+ println(`after two more restore(): lineWidth ${context.lineWidth}, font ${context.font}, e ${context.getTransform().e}`);++ println(`isContextLost(): ${context.isContextLost()}`);+ println(`getContextAttributes(): ${JSON.stringify(context.getContextAttributes())}`);++ context.reset();+ println(`${label}, after reset():`);+ printState(context);+ println(`isPointInStroke: ${typeof context.isPointInStroke}, drawFocusIfNeeded: ${typeof context.drawFocusIfNeeded}`);+ }++ test(() => {+ const canvas = document.createElement("canvas");+ exercise("A canvas", canvas.getContext("2d"));+ const context = canvas.getContext("2d", { alpha: false });+ println(`canvas: ${context.canvas === canvas}`);++ const offscreenCanvas = new OffscreenCanvas(10, 10);+ const offscreenContext = offscreenCanvas.getContext("2d", { alpha: false, willReadFrequently: true });+ exercise("An OffscreenCanvas", offscreenContext);+ println(`canvas: ${offscreenContext.canvas === offscreenCanvas}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/canvas/2d-image-data-arguments.html b/Tests/LibWeb/Text/input/canvas/2d-image-data-arguments.htmlnew file mode 100644index 00000000000..8d4efc1b221--- /dev/null+++ b/Tests/LibWeb/Text/input/canvas/2d-image-data-arguments.html@@ -0,0 +1,97 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<canvas id="canvas" width="4" height="3"></canvas>+<script>+ function tryOperation(description, operation) {+ try {+ const result = operation();+ if (result instanceof ImageData)+ println(`${description}: ImageData ${result.width}x${result.height} [${Array.from(result.data)}]`);+ else if (result === undefined)+ println(`${description}: no exception`);+ else+ println(`${description}: ${result}`);+ } catch (e) {+ const kind = e instanceof DOMException ? `DOMException ${e.name}` : e.constructor.name;+ println(`${description}: ${kind}: ${e.message}`);+ }+ }++ function exercise(label, context) {+ println(`${label}:`);+ context.fillStyle = "rgb(10, 20, 30)";+ context.fillRect(0, 0, 2, 2);+ context.fillStyle = "rgba(200, 100, 50, 0.5)";+ context.fillRect(2, 1, 2, 2);++ tryOperation("getImageData(0, 0, 2, 1)", () => context.getImageData(0, 0, 2, 1));+ tryOperation("getImageData(1.9, 0.5, 2.9, 1.2)", () => context.getImageData(1.9, 0.5, 2.9, 1.2));+ tryOperation("getImageData(3, 2, -2, -2)", () => context.getImageData(3, 2, -2, -2));+ tryOperation("getImageData(-1, -1, 2, 2)", () => context.getImageData(-1, -1, 2, 2));+ tryOperation("getImageData(10, 10, 1, 1)", () => context.getImageData(10, 10, 1, 1));+ tryOperation("getImageData(0, 0, 0, 1)", () => context.getImageData(0, 0, 0, 1));+ tryOperation("getImageData(NaN, 0, 1, 1)", () => context.getImageData(NaN, 0, 1, 1));+ tryOperation("getImageData(0, Infinity, 1, 1)", () => context.getImageData(0, Infinity, 1, 1));+ tryOperation("getImageData(2 ** 31, 0, 1, 1)", () => context.getImageData(2 ** 31, 0, 1, 1));+ tryOperation("getImageData(0, -(2 ** 31) - 1, 1, 1)", () => context.getImageData(0, -(2 ** 31) - 1, 1, 1));+ tryOperation("getImageData(-(2 ** 31), -(2 ** 31), 1, 1)", () => context.getImageData(-(2 ** 31), -(2 ** 31), 1, 1));+ tryOperation("getImageData(0, 0, 1, 1e300)", () => context.getImageData(0, 0, 1, 1e300));+ tryOperation("getImageData(2 ** 31 - 1, 2 ** 31 - 1, 1, 1)", () => context.getImageData(2 ** 31 - 1, 2 ** 31 - 1, 1, 1));+ tryOperation("getImageData(0, 0, \"2\", [1])", () => context.getImageData(0, 0, "2", [1]));+ tryOperation("getImageData(0, 0, 1, 1, { colorSpace: \"bogus\" })", () => context.getImageData(0, 0, 1, 1, { colorSpace: "bogus" }));+ tryOperation("getImageData(0, 0, 1, 1, { colorSpace: \"display-p3\" }).colorSpace", () => context.getImageData(0, 0, 1, 1, { colorSpace: "display-p3" }).colorSpace);++ tryOperation("createImageData(2, 1)", () => context.createImageData(2, 1));+ tryOperation("createImageData(-2, -1)", () => context.createImageData(-2, -1));+ tryOperation("createImageData(0, 1)", () => context.createImageData(0, 1));+ tryOperation("createImageData(1, NaN)", () => context.createImageData(1, NaN));+ tryOperation("createImageData(2 ** 31, 1)", () => context.createImageData(2 ** 31, 1));+ tryOperation("createImageData(1.99, -1.99)", () => context.createImageData(1.99, -1.99));+ tryOperation("createImageData(-(2 ** 31), 1)", () => context.createImageData(-(2 ** 31), 1));+ tryOperation("createImageData(new ImageData(3, 1))", () => context.createImageData(new ImageData(3, 1)));+ tryOperation("createImageData(1, 1, { colorSpace: \"srgb-linear\" }).colorSpace", () => context.createImageData(1, 1, { colorSpace: "srgb-linear" }).colorSpace);+ tryOperation("createImageData(null)", () => context.createImageData(null));++ const source = new ImageData(new Uint8ClampedArray([255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 1, 2, 3, 4]), 2, 2);+ tryOperation("putImageData(source, Infinity, 0)", () => context.putImageData(source, Infinity, 0));+ tryOperation("putImageData(source, 0, 2 ** 31)", () => context.putImageData(source, 0, 2 ** 31));+ tryOperation("putImageData(source, 0, 0, 0, 0, NaN, 1)", () => context.putImageData(source, 0, 0, 0, 0, NaN, 1));+ tryOperation("putImageData(source, 3, 2)", () => context.putImageData(source, 3, 2));+ tryOperation("after it, getImageData(0, 0, 4, 3)", () => context.getImageData(0, 0, 4, 3));+ tryOperation("putImageData(source, 0, 0, 1, 1, -5, -5)", () => context.putImageData(source, 0, 0, 1, 1, -5, -5));+ tryOperation("after it, getImageData(0, 0, 4, 3)", () => context.getImageData(0, 0, 4, 3));+ tryOperation("putImageData(source, 1, 0, -1, -1, 2, 3)", () => context.putImageData(source, 1, 0, -1, -1, 2, 3));+ tryOperation("after it, getImageData(0, 0, 4, 3)", () => context.getImageData(0, 0, 4, 3));+ tryOperation("putImageData(source, -(2 ** 31), -(2 ** 31), 2 ** 31 - 1, 2 ** 31 - 1, 2 ** 31 - 1, 2 ** 31 - 1)", () => context.putImageData(source, -(2 ** 31), -(2 ** 31), 2 ** 31 - 1, 2 ** 31 - 1, 2 ** 31 - 1, 2 ** 31 - 1));+ tryOperation("putImageData(source, 2 ** 31 - 1, 2 ** 31 - 1, -(2 ** 31), -(2 ** 31), -(2 ** 31), -(2 ** 31))", () => context.putImageData(source, 2 ** 31 - 1, 2 ** 31 - 1, -(2 ** 31), -(2 ** 31), -(2 ** 31), -(2 ** 31)));+ tryOperation("putImageData(source, -1, -1, 0, 0, 2 ** 31 - 1, 2 ** 31 - 1)", () => context.putImageData(source, -1, -1, 0, 0, 2 ** 31 - 1, 2 ** 31 - 1));+ tryOperation("after it, getImageData(0, 0, 4, 3)", () => context.getImageData(0, 0, 4, 3));+ const detached = new ImageData(1, 1);+ structuredClone(detached.data.buffer, { transfer: [detached.data.buffer] });+ tryOperation("putImageData(detached, 0, 0)", () => context.putImageData(detached, 0, 0));++ tryOperation("createPattern(canvas, null) repeats", () => context.createPattern(canvas, null) !== null);+ tryOperation("createPattern(canvas, \"\")", () => context.createPattern(canvas, "") !== null);+ tryOperation("createPattern(canvas, \"repeat-x\")", () => context.createPattern(canvas, "repeat-x") !== null);+ tryOperation("createPattern(canvas, \"Repeat\")", () => context.createPattern(canvas, "Repeat"));+ tryOperation("createPattern(canvas, undefined)", () => context.createPattern(canvas, undefined));+ const emptyCanvas = document.createElement("canvas");+ emptyCanvas.width = 0;+ tryOperation("createPattern(canvas without width, \"repeat\")", () => context.createPattern(emptyCanvas, "repeat"));+ tryOperation("createPattern(new OffscreenCanvas(0, 1), \"repeat\")", () => context.createPattern(new OffscreenCanvas(0, 1), "repeat"));+ tryOperation("createPattern(new Image(), \"repeat\")", () => context.createPattern(new Image(), "repeat"));+ tryOperation("createPattern({}, \"repeat\")", () => context.createPattern({}, "repeat"));+ tryOperation("createPattern(canvas)", () => context.createPattern(canvas));+ }++ asyncTest(async done => {+ exercise("A canvas", canvas.getContext("2d"));+ exercise("An OffscreenCanvas", new OffscreenCanvas(4, 3).getContext("2d"));++ const bitmap = await createImageBitmap(new ImageData(1, 1));+ bitmap.close();+ tryOperation("createPattern(closed ImageBitmap, \"repeat\")", () => canvas.getContext("2d").createPattern(bitmap, "repeat"));+ tryOperation("drawImage(closed ImageBitmap, 0, 0)", () => canvas.getContext("2d").drawImage(bitmap, 0, 0));+ done();+ });+</script>diff --git a/Tests/LibWeb/Text/input/canvas/2d-is-point-in-path.html b/Tests/LibWeb/Text/input/canvas/2d-is-point-in-path.htmlnew file mode 100644index 00000000000..80b14a38df7--- /dev/null+++ b/Tests/LibWeb/Text/input/canvas/2d-is-point-in-path.html@@ -0,0 +1,65 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ function exercise(label, context) {+ println(`${label}:`);+ const points = [[5, 5], [15, 15], [25, 5], [10.5, 10.5], [NaN, 5], [Infinity, 5], [29.99, 15]];+ const report = (description, test) => println(` ${description}: ${points.map(([x, y]) => test(x, y) ? 1 : 0).join("")}`);++ context.rect(0, 0, 20, 20);+ context.rect(5, 5, 10, 10);+ report("two rectangles, nonzero", (x, y) => context.isPointInPath(x, y));+ report("two rectangles, evenodd", (x, y) => context.isPointInPath(x, y, "evenodd"));++ context.beginPath();+ context.translate(10, 0);+ context.rect(0, 0, 20, 20);+ report("a translated rectangle", (x, y) => context.isPointInPath(x, y));+ context.scale(0.5, 2);+ report("after a later scale", (x, y) => context.isPointInPath(x, y));+ context.setTransform(0, 0, 0, 0, 0, 0);+ report("under a singular transform", (x, y) => context.isPointInPath(x, y));+ context.resetTransform();++ const path = new Path2D();+ path.arc(15, 15, 10, 0, 2 * Math.PI);+ report("a Path2D circle", (x, y) => context.isPointInPath(path, x, y));+ context.rotate(Math.PI / 4);+ report("a Path2D circle under a rotation", (x, y) => context.isPointInPath(path, x, y, "evenodd"));+ context.resetTransform();+ report("an empty Path2D", (x, y) => context.isPointInPath(new Path2D(), x, y));++ for (const [description, call] of [+ ["isPointInPath()", () => context.isPointInPath()],+ ["isPointInPath(1)", () => context.isPointInPath(1)],+ ["isPointInPath(1, 2, \"bogus\")", () => context.isPointInPath(1, 2, "bogus")],+ ["isPointInPath(path, 1)", () => context.isPointInPath(path, 1)],+ ["isPointInPath({}, 1, 2)", () => context.isPointInPath({}, 1, 2)],+ ["fill(\"bogus\")", () => context.fill("bogus")],+ ["fill(null)", () => context.fill(null)],+ ["clip(path, \"bogus\")", () => context.clip(path, "bogus")],+ ["stroke(null)", () => context.stroke(null)],+ ["drawImage(null, 0, 0)", () => context.drawImage(null, 0, 0)],+ ["drawImage(canvas, 0)", () => context.drawImage(context.canvas, 0)],+ ["drawImage(canvas, 0, 0, 1)", () => context.drawImage(context.canvas, 0, 0, 1)],+ ["drawImage(canvas, 0, 0, 1, 1, 1, 1)", () => context.drawImage(context.canvas, 0, 0, 1, 1, 1, 1)],+ ["setTransform(1, 2)", () => context.setTransform(1, 2)],+ ["putImageData(new ImageData(1, 1), 0, 0, 0)", () => context.putImageData(new ImageData(1, 1), 0, 0, 0)],+ ["createImageData()", () => context.createImageData()],+ ["fillText(\"a\", 1)", () => context.fillText("a", 1)],+ ["fillStyle = {}", () => { context.fillStyle = {}; return context.fillStyle; }],+ ["fillStyle = new Path2D()", () => { context.fillStyle = new Path2D(); return context.fillStyle; }],+ ]) {+ try {+ println(` ${description}: ${call()}`);+ } catch (e) {+ println(` ${description}: ${e.constructor.name}: ${e.message}`);+ }+ }+ }++ test(() => {+ exercise("A canvas", document.createElement("canvas").getContext("2d"));+ exercise("An OffscreenCanvas", new OffscreenCanvas(30, 30).getContext("2d"));+ });+</script>diff --git a/Tests/LibWeb/Text/input/canvas/2d-measure-text.html b/Tests/LibWeb/Text/input/canvas/2d-measure-text.htmlnew file mode 100644index 00000000000..1bdd6b3848a--- /dev/null+++ b/Tests/LibWeb/Text/input/canvas/2d-measure-text.html@@ -0,0 +1,47 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ const members = [+ "width", "actualBoundingBoxLeft", "actualBoundingBoxRight", "fontBoundingBoxAscent", "fontBoundingBoxDescent",+ "actualBoundingBoxAscent", "actualBoundingBoxDescent", "emHeightAscent", "emHeightDescent", "hangingBaseline",+ "alphabeticBaseline", "ideographicBaseline",+ ];++ function measure(context, text) {+ const metrics = context.measureText(text);+ println(` ${JSON.stringify(text)}: ${members.map(member => metrics[member]).join(", ")}`);+ }++ function exercise(label, context) {+ println(`${label}:`);+ for (const font of ["10px sans-serif", "23px serif", "bold 17.5px monospace", "italic 9px sans-serif"]) {+ context.font = font;+ println(` ${context.font}`);+ for (const text of ["", " ", "Hello, world!", "a\tb\nc\fd\re", "é😀漢字 mixed", "\ud800 lone"])+ measure(context, text);+ }+ context.font = "15px sans-serif";+ for (const baseline of ["top", "hanging", "middle", "alphabetic", "ideographic", "bottom"]) {+ context.textBaseline = baseline;+ println(` textBaseline ${baseline}`);+ measure(context, "Baseline");+ }+ context.textBaseline = "alphabetic";+ for (const spacing of ["3px", "-1px", "0.5em"]) {+ context.letterSpacing = spacing;+ println(` letterSpacing ${spacing}`);+ measure(context, "Spaced out");+ }+ context.letterSpacing = "0px";+ for (const align of ["start", "end", "left", "right", "center"]) {+ context.textAlign = align;+ println(` textAlign ${align}`);+ measure(context, "Aligned");+ }+ }++ test(() => {+ exercise("A canvas", document.createElement("canvas").getContext("2d"));+ exercise("An OffscreenCanvas", new OffscreenCanvas(10, 10).getContext("2d"));+ });+</script>