Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
* Check a type tag before unwrapping a native object, so a forged prototype chain can no longer crash the process (#2628)
* Load images from Node.js object URLs (#2525)
* `isPointInPath()` now ignores the current transform and no longer counts points that are only inside the stroke (#2634)

3.2.3
==================
Expand Down
4 changes: 3 additions & 1 deletion src/CanvasRenderingContext2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,9 @@ Context2d::IsPointInPath(const Napi::CallbackInfo& info) {
cairo_t *ctx = context();
double x = info[0].As<Napi::Number>(), y = info[1].As<Napi::Number>();
setFillRule(info[2]);
return Napi::Boolean::New(env, cairo_in_fill(ctx, x, y) || cairo_in_stroke(ctx, x, y));
// x and y are in canvas coordinates, not affected by the transform
cairo_device_to_user(ctx, &x, &y);
return Napi::Boolean::New(env, cairo_in_fill(ctx, x, y));
}
return Napi::Boolean::New(env, false);
}
Expand Down
23 changes: 23 additions & 0 deletions test/canvas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,29 @@ describe('Canvas', function () {
assert.ok(!ctx.isPointInPath(50, 120))
})

it('Context2d#isPointInPath() ignores the current transform', function () {
const ctx = createCanvas(200, 100).getContext('2d')
ctx.translate(100, 0)
ctx.rect(0, 0, 50, 50) // x = 100..150 on the canvas
assert.ok(ctx.isPointInPath(125, 25))
assert.ok(!ctx.isPointInPath(25, 25))

const ctx2 = createCanvas(100, 100).getContext('2d')
ctx2.scale(2, 2)
ctx2.rect(10, 10, 10, 10) // 20..40 on the canvas
assert.ok(ctx2.isPointInPath(30, 30))
assert.ok(!ctx2.isPointInPath(15, 15))
})

it('Context2d#isPointInPath() does not include the stroke', function () {
const ctx = createCanvas(100, 100).getContext('2d')
ctx.rect(10, 10, 80, 80)
ctx.lineWidth = 10
assert.ok(ctx.isPointInPath(10, 50))
assert.ok(!ctx.isPointInPath(7, 50))
assert.ok(!ctx.isPointInPath(50, 90.01))
})

it('Context2d#textAlign', function () {
const canvas = createCanvas(200, 200)
const ctx = canvas.getContext('2d')
Expand Down
Loading