Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zenozeng committed Jun 13, 2021
1 parent 307e371 commit 134e9c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
42 changes: 17 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,37 @@ A maintained fork of [gliffy's canvas2svg](https://github.com/gliffy/canvas2svg)
https://zenozeng.github.io/svgcanvas/test/

## How it works
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. Yay!

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.

## Usage

```javascript
//Create a new mock canvas context. Pass in your desired width and height for your svg document.
var ctx = new C2S(500,500);
import {Context} from 'svgcanvas'

const ctx = new Context(500, 500);

//draw your canvas like you would normally
ctx.fillStyle="red";
ctx.fillRect(100,100,100,100);
//etc...

//serialize your SVG
var mySerializedSVG = ctx.getSerializedSvg(); //true here, if you need to convert named to numbered entities.

//If you really need to you can access the shadow inline SVG created by calling:
var svg = ctx.getSvg();
// serialize your SVG
const mySerializedSVG = ctx.getSerializedSvg();
```

## Using with node.js

You can use `canvas2svg` with node.js using [jsdom](https://github.com/tmpvar/jsdom) with [node-canvas](https://github.com/Automattic/node-canvas). To do this first create a new document object, and then create a new instance of `C2S` based on that document:

```javascript
var canvas = require('canvas'),
jsdom = require('jsdom'),
C2S = require('canvas2svg');
## CHANGELOG

var document = jsdom.jsdom();
var ctx = new C2S({document: document});
### v2.0.2

// ... drawing code goes here ...
```
- 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

N.B. You may not need node-canvas for some simple operations when using jsdom >= 6.3.0, but it's still recommended that you install it.

## CHANGELOG
### v1.x

- v1.0.19 Fix __parseFont to not crash
- v1.0.18 clip was not working, the path never made it to the clip area
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svgcanvas",
"version": "2.0.1",
"version": "2.0.2",
"description": "svgcanvas",
"main": "dist/svgcanvas.js",
"scripts": {
Expand Down

0 comments on commit 134e9c5

Please sign in to comment.