2021-06-05 14:44:05 +08:00
|
|
|
# SVGCanvas
|
|
|
|
|
|
|
|
Draw on SVG using Canvas's 2D Context API.
|
|
|
|
A maintained fork of [gliffy's canvas2svg](https://github.com/gliffy/canvas2svg).
|
|
|
|
|
|
|
|
## Demo
|
|
|
|
|
2021-06-10 20:39:09 +08:00
|
|
|
https://zenozeng.github.io/svgcanvas/test/
|
2014-01-07 14:39:29 -08:00
|
|
|
|
2021-06-05 14:44:05 +08:00
|
|
|
## How it works
|
2021-06-13 23:50:26 +08:00
|
|
|
|
|
|
|
We create a mock 2d canvas context. Use the canvas context like you would on a normal canvas. As you call methods, we build up a scene graph in SVG.
|
2014-01-07 14:39:29 -08:00
|
|
|
|
2021-06-05 14:44:05 +08:00
|
|
|
## Usage
|
|
|
|
|
2014-01-07 14:39:29 -08:00
|
|
|
```javascript
|
2021-06-13 23:50:26 +08:00
|
|
|
import {Context} from 'svgcanvas'
|
|
|
|
|
|
|
|
const ctx = new Context(500, 500);
|
2014-01-07 14:39:29 -08:00
|
|
|
|
|
|
|
//draw your canvas like you would normally
|
|
|
|
ctx.fillStyle="red";
|
|
|
|
ctx.fillRect(100,100,100,100);
|
|
|
|
|
2021-06-13 23:50:26 +08:00
|
|
|
// serialize your SVG
|
|
|
|
const mySerializedSVG = ctx.getSerializedSvg();
|
2014-01-07 14:39:29 -08:00
|
|
|
```
|
|
|
|
|
2021-06-13 23:50:26 +08:00
|
|
|
## CHANGELOG
|
2015-09-09 00:37:10 -07:00
|
|
|
|
2022-02-03 12:12:35 +08:00
|
|
|
### v2.0.7
|
|
|
|
|
|
|
|
- fix typo
|
|
|
|
- rollup 2.67.0
|
|
|
|
|
2022-02-03 12:05:24 +08:00
|
|
|
### v2.0.6
|
|
|
|
|
|
|
|
- utils.toString for https://github.com/zenozeng/p5.js-svg/issues/204
|
|
|
|
|
2021-11-13 13:52:42 +08:00
|
|
|
### v2.0.5
|
|
|
|
|
|
|
|
- Fix adding CanvasPattern ([Xavier Delamotte](https://github.com/x4d3)) [#7](https://github.com/zenozeng/svgcanvas/pull/7)
|
|
|
|
|
2021-07-07 00:32:49 +08:00
|
|
|
### v2.0.4
|
|
|
|
|
|
|
|
- fix: push/pop transformMatrixStack when save/restore, for https://github.com/zenozeng/p5.js-svg/issues/191
|
|
|
|
|
2021-06-14 21:45:27 +08:00
|
|
|
### v2.0.3
|
|
|
|
|
|
|
|
- feat: sync element's width and height to context
|
|
|
|
|
2021-06-13 23:50:26 +08:00
|
|
|
### v2.0.2
|
2015-09-09 00:37:10 -07:00
|
|
|
|
2021-06-13 23:50:26 +08:00
|
|
|
- feat: Implement CanvasTransform Interface, https://github.com/gliffy/canvas2svg/pull/83
|
|
|
|
- feat: ClearCanvas in fillRect
|
|
|
|
- feat: Element API
|
|
|
|
- feat: ESM
|
|
|
|
- fix: Recreate root `<g>` when __clearCanvas to remove all attributes
|
|
|
|
- chore: Bundle JavaScript using Rollup
|
|
|
|
- chore: GitHub Actions
|
2015-09-09 00:37:10 -07:00
|
|
|
|
2021-06-13 23:50:26 +08:00
|
|
|
### v1.x
|
2021-06-05 14:44:05 +08:00
|
|
|
|
2016-04-21 12:00:27 -07:00
|
|
|
- v1.0.19 Fix __parseFont to not crash
|
2016-04-21 11:50:41 -07:00
|
|
|
- v1.0.18 clip was not working, the path never made it to the clip area
|
2016-01-22 08:51:37 -08:00
|
|
|
- v1.0.17 Fix bug with drawing in an empty context. Fix image translation problem. Fix globalAlpha issue.
|
2015-09-09 12:15:32 -07:00
|
|
|
- v1.0.16 Add npm publishing support, bower file and optimize for arcs with no angles.
|
2015-06-18 17:07:08 -07:00
|
|
|
- v1.0.15 Setup travis, add testharness and debug playground, and fix regression for __createElement refactor
|
2015-06-13 17:06:25 -07:00
|
|
|
- v1.0.14 bugfix for gradients, move __createElement to scoped createElement function, so all classes have access.
|
2015-06-16 15:13:16 -07:00
|
|
|
- v1.0.13 set paint order before stroke and fill to make them behavior like canvas
|
2015-06-16 15:08:17 -07:00
|
|
|
- v1.0.12 Implementation of ctx.prototype.arcTo.
|
2015-06-15 17:26:31 -07:00
|
|
|
- v1.0.11 call lineTo instead moveTo in ctx.arc, fixes closePath issue and straight line issue
|
2015-06-02 11:10:42 -07:00
|
|
|
- v1.0.10 when lineTo called, use M instead of L unless subpath exists
|
2015-05-29 10:25:53 -07:00
|
|
|
- v1.0.9 use currentDefaultPath instead of <path>'s d attribute, fixes stroke's different behavior in SVG and canvas.
|
2015-05-21 15:11:30 -07:00
|
|
|
- v1.0.8 reusing __createElement and adding a properties undefined check
|
2015-04-25 13:18:54 -07:00
|
|
|
- v1.0.7 fixes for multiple transforms and fills and better text support from stafyniaksacha
|
2014-09-20 16:01:08 -07:00
|
|
|
- v1.0.6 basic support for text baseline (contribution from KoKuToru)
|
2014-09-14 09:42:26 -07:00
|
|
|
- v1.0.5 fixes for #5 and #6 (with contributions from KoKuToru)
|
2014-07-15 13:58:20 -07:00
|
|
|
- v1.0.4 generate ids that start with a letter
|
2014-04-03 20:32:52 -07:00
|
|
|
- v1.0.3 fixed #4 where largeArcFlag was set incorrectly in some cases
|
2014-02-21 17:35:01 -08:00
|
|
|
- v1.0.2 Split up rgba values set in fill/stroke to allow illustrator import support.
|
|
|
|
- v1.0.1 Allow C2S to be called as a function. https://github.com/gliffy/canvas2svg/issues/2
|
|
|
|
- v1.0.0 Initial release
|
|
|
|
|
2021-06-05 14:44:05 +08:00
|
|
|
## License
|
2015-09-09 11:02:48 -07:00
|
|
|
|
2014-01-11 15:08:51 -08:00
|
|
|
This library is licensed under the MIT license.
|