canvas-get-transform
Implement getTransform in Canvas contexts and expose the implementation.
Last updated 5 years ago by mellowmelon .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install canvas-get-transform 
SYNC missed versions from official npm registry.

canvas-transform

This provides an implementation of getTransform for Canvas contexts and exposes much of the underlying implementation so that it can be plugged into other context wrappers.

Install

With npm installed, run

npm install canvas-get-transform

API

var Transform = require("canvas-get-transform");

The type TransformMatrix used in this API documentation is a six element array [a, b, c, d, e, f] representing the 3 by 3 matrix

a c e
b d f
0 0 1

Transform.translate(x, y)

Returns a TransformMatrix to multiply by when a context's translate method is called.

Transform.rotate(angle)

Returns a TransformMatrix to multiply by when a context's rotate method is called.

Transform.scale(x, y)

Returns a TransformMatrix to multiply by when a context's scale method is called.

Transform.transform(a, b, c, d, e, f)

Returns a TransformMatrix to multiply by when a context's transform method is called.

Transform.multiply(m1, m2)

Returns a TransformMatrix with the result of multiplying m1 and m2 as 3 by 3 matrices.

Transform.process(m, methodName, args)

Returns a TransformMatrix with the result of multiplying m by the transformation matrix that results from applying the Canvas method with name methodName and arguments args. The supported methodName values are translate, rotate, scale, transform, setTransform, and resetTransform. Providing an invalid methodName will return m unchanged. The arguments to the method, args, can be either an array or array-like object.

As an example, Transform.process([1, 0, 0, 1, 0, 0], "translate", [10, 20]) is equivalent to Transform.translate(10, 20).

Transform.augmentContext(context)

Pass in a Canvas context, and a getTransform method will be added to it if it does not already exist. getTransform returns a TransformMatrix.

This method will also add resetTransform to the context if it does not exist, implemented by calling setTransform(1, 0, 0, 1, 0, 0).

Test

With npm installed, run

npm test

To lint with ESLint, run

npm run check

License

MIT

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

1 Versions

  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |