Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Current transformation implementation adds a
<g>
element and set<g>
's transform attribute with string concatenation ofrotate
,matrix
,rotate
,scale
.This pull request implements CanvasTransform interface using
DOMMatrix
and SVG'smatrix(a b c d e f)
transform function. Compared to adding string concatenation results to transform attribute of<g>
element, it is more reliable to use the transformation matrix whichDOMMatrix
API calculates and applied directly to<path>
,<rect>
and other elements every time.Example
Rendered in Canvas:
Rendered with v1.0.19’s implementation:
Rendered with this pull request's implementation:
For
lineTo
,bezierCurveTo
,quadraticCurveTo
, each step’s point x and y were now calculated based on current transformation matrix.New methods
This pull request also implemented 3 missing methods defined in CanvasTransform interface:
ctx.prototype.setTransform(a, b, c, d, e, f)
: SetTransform changes the current transformation matrix to the matrix given by the arguments as described below.ctx.prototype.getTransform()
: Returns a copy of the current transformation matrix, as a newly created DOMMAtrix Object.ctx.prototype.resetTransform()
: ResetTransform resets the current transformation matrix to the identity matrix.Reference