Skip to content

Commit

Permalink
fix: don't panic if current ts is not able to invert when transform (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn authored Feb 22, 2025
1 parent 4586bc7 commit 27e1cc8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 9 additions & 0 deletions __test__/regression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,12 @@ test('draw-canvas-on-canvas', async (t) => {

await snapshotImage(t, { ctx: backCtx, canvas: backCanvas })
})

// https://github.com/Brooooooklyn/canvas/issues/1000
test('transform-with-non-inverted-matrix', (t) => {
const canvas = createCanvas(100, 100)
const ctx = canvas.getContext('2d')
t.notThrows(() => {
ctx.transform(0, 0, 0, 0, 1019, 1165)
})
})
8 changes: 3 additions & 5 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,9 @@ impl Context {

pub fn transform(&mut self, ts: Matrix) -> result::Result<(), SkError> {
let current_state = &mut self.state;
self.path.transform_self(
&ts
.invert()
.ok_or_else(|| SkError::InvalidTransform(ts.clone()))?,
);
if let Some(inverse) = ts.invert() {
self.path.transform_self(&inverse);
}
current_state.transform = ts.multiply(&current_state.transform);
self.surface.set_transform(&current_state.transform);
Ok(())
Expand Down
6 changes: 6 additions & 0 deletions src/sk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3106,6 +3106,12 @@ impl Matrix {
}
}

impl Default for Matrix {
fn default() -> Self {
Self::identity()
}
}

impl Clone for Matrix {
fn clone(&self) -> Self {
Matrix(unsafe { ffi::skiac_matrix_clone(self.0) })
Expand Down

0 comments on commit 27e1cc8

Please sign in to comment.