mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Implement CanvasPattern.setTransform()
This method applies the given transformation matrix to a pattern.
This commit is contained in:
parent
9312a9f86f
commit
e1ff1e2095
Notes:
github-actions[bot]
2025-10-27 23:42:03 +00:00
Author: https://github.com/tcl3
Commit: e1ff1e2095
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6596
Reviewed-by: https://github.com/gmta ✅
10 changed files with 87 additions and 7 deletions
|
|
@ -75,4 +75,21 @@ void CanvasPattern::initialize(JS::Realm& realm)
|
|||
Base::initialize(realm);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-canvaspattern-settransform
|
||||
WebIDL::ExceptionOr<void> CanvasPattern::set_transform(Geometry::DOMMatrix2DInit& transform)
|
||||
{
|
||||
// 1. Let matrix be the result of creating a DOMMatrix from the 2D dictionary transform.
|
||||
auto matrix = TRY(Geometry::DOMMatrix::create_from_dom_matrix_2d_init(realm(), transform));
|
||||
|
||||
// 2. If one or more of matrix's m11 element, m12 element, m21 element, m22 element, m41 element, or m42 element are infinite or NaN, then return.
|
||||
if (!isfinite(matrix->m11()) || !isfinite(matrix->m12()) || !isfinite(matrix->m21()) || !isfinite(matrix->m22()) || !isfinite(matrix->m41()) || !isfinite(matrix->m42()))
|
||||
return {};
|
||||
|
||||
// 3. Reset the pattern's transformation matrix to matrix.
|
||||
Gfx::AffineTransform affine_transform(matrix->a(), matrix->b(), matrix->c(), matrix->d(), matrix->e(), matrix->f());
|
||||
m_pattern->set_transform(affine_transform);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public:
|
|||
~CanvasPattern();
|
||||
|
||||
NonnullRefPtr<Gfx::PaintStyle> to_gfx_paint_style() { return m_pattern; }
|
||||
WebIDL::ExceptionOr<void> set_transform(Geometry::DOMMatrix2DInit& transform);
|
||||
|
||||
private:
|
||||
CanvasPattern(JS::Realm&, Gfx::CanvasPatternPaintStyle&);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#import <Geometry/DOMMatrix.idl>
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#canvaspattern
|
||||
[Exposed=(Window,Worker)]
|
||||
interface CanvasPattern {
|
||||
// opaque object
|
||||
[FIXME] undefined setTransform(optional DOMMatrix2DInit transform = {});
|
||||
undefined setTransform(optional DOMMatrix2DInit transform = {});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue