servo / pathfinder

A fast, practical GPU rasterizer for fonts and vector graphics
Apache License 2.0
3.54k stars 198 forks source link

context2d.draw_subimage treats source_rect offset in destination coordinate space #481

Closed Adjective-Object closed 2 years ago

Adjective-Object commented 2 years ago

Happy to submit a fix for this, but I want to confirm if the behaviour is intentional or not first:

If you create a pattern from an image, then immediately call CanvasRenderingContext2D.draw_subimage, The x/y components of the input rect are in the destination canvas' coordinate space, while the width/height are in the image's own coordinate space.

https://github.com/servo/pathfinder/blob/20adbeed149713ae4354cede3a30ca0f622c9943/canvas/src/lib.rs#L553-L556

I assume this API is meant to be analagous to ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);, which from MDN takes the whole rect (including offset) from the image's own coordinate space.

s3bk commented 2 years ago

I am fairly certain that the Canvas API should mirror the MDN API.

Adjective-Object commented 2 years ago

https://github.com/Adjective-Object/pathfinder_canvas_drawimage_repro Repro here