Skip to content

Commit

Permalink
Merge pull request #712 from canvg/2.0.0
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
gabelerner committed May 18, 2019
2 parents d04bb60 + 9eb51a5 commit 98a12cb
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 66 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
@@ -1,7 +1,9 @@
# Change Log

## v2.0.0 (beta)
## v2.0.0
- **Breaking change**: for use on server, peer dependencies [canvas 2.x](https://github.com/Automattic/node-canvas), [jsdom 13.x](https://github.com/jsdom/jsdom) and [xmldom 0.x](https://github.com/jindw/xmldom) must be installed.
- Fix exponential notation ([#710](https://github.com/canvg/canvg/pull/710))
- Fix font parsing ([#707](https://github.com/canvg/canvg/pull/707))
- Implement `textPath` ([#687](https://github.com/canvg/canvg/pull/687))
- Implement focal gradient radius ([#675](https://github.com/canvg/canvg/pull/675))
- Fixes 0 height rects ([#674](https://github.com/canvg/canvg/pull/674))
Expand Down
20 changes: 5 additions & 15 deletions README.md
Expand Up @@ -43,15 +43,15 @@ Locally, you can run `npm start` and view the examples at [http://localhost:3123

## Usage on the server

`npm install canvg@^1.5`

**2.0.0 beta** (see [CHANGELOG](https://github.com/canvg/canvg/blob/master/CHANGELOG.md))

`npm install canvg@2.0.0-beta.1 canvas@^2 jsdom@^13 xmldom@^0`
`npm install canvg canvas@^2 jsdom@^13 xmldom@^0`

The dependencies required on the server only are peers so must be installed
alongside the canvg package.

**Older version**

`npm install canvg@^1.5`

## Usage on the browser

For browser applications with a build process, canvg can be installed using `npm` similar to use on the server. Note in this case the peer dependencies are not required so do not need to be installed.
Expand All @@ -66,16 +66,6 @@ Alternatively, canvg can be included directly into a webpage:
<script src="https://cdn.jsdelivr.net/npm/canvg/dist/browser/canvg.min.js"></script>
```

For the **2.0.0 beta** (see [CHANGELOG](https://github.com/canvg/canvg/blob/master/CHANGELOG.md)), use this:
```html
<!-- Required to convert named colors to RGB -->
<script src="https://cdn.jsdelivr.net/npm/rgbcolor@^1/index.js"></script>
<!-- Optional if you want blur -->
<script src="https://cdn.jsdelivr.net/npm/stackblur-canvas@^1/dist/stackblur.min.js"></script>
<!-- Main canvg code -->
<script src="https://cdn.jsdelivr.net/npm/canvg@2.0.0-beta.1/dist/browser/canvg.min.js"></script>
```

Put a canvas on your page
```html
<canvas id="canvas" width="1000px" height="600px"></canvas>
Expand Down
30 changes: 17 additions & 13 deletions dist/browser/canvg.js
@@ -1,7 +1,7 @@

/*
* canvg.js - Javascript SVG parser and renderer on Canvas
* version 2.0.0-beta.1
* version 2.0.0
* MIT Licensed
* Gabe Lerner (gabelerner@gmail.com)
* https://github.com/canvg/canvg
Expand Down Expand Up @@ -498,7 +498,7 @@

// points and paths
svg.ToNumberArray = function (s) {
var a = (s || '').match(/-?(\d+(\.\d+)?|\.\d+)(?=\D|$)/gm) || [];
var a = (s || '').match(/-?(\d+(?:\.\d*(?:[eE][+-]?\d+)?)?|\.\d+)(?=\D|$)/gm) || [];
for (var i = 0; i < a.length; i++) {
a[i] = parseFloat(a[i]);
}
Expand Down Expand Up @@ -1072,17 +1072,21 @@

// font
if (typeof ctx.font != 'undefined') {
ctx.font = svg.Font.CreateFont(
this.style('font-style').value,
this.style('font-variant').value,
this.style('font-weight').value,
this.style('font-size').hasValue() ? this.style('font-size').toPixels() + 'px' : '',
this.style('font-family').value).toString();

// update em size if needed
var currentFontSize = this.style('font-size', false, false);
if (currentFontSize.isPixels()) {
svg.emSize = currentFontSize.toPixels();
if (this.style('font').hasValue()) {
ctx.font = this.style('font').value;
} else {
ctx.font = svg.Font.CreateFont(
this.style('font-style').value,
this.style('font-variant').value,
this.style('font-weight').value,
this.style('font-size').hasValue() ? this.style('font-size').toPixels() + 'px' : '',
this.style('font-family').value).toString();

// update em size if needed
var currentFontSize = this.style('font-size', false, false);
if (currentFontSize.isPixels()) {
svg.emSize = currentFontSize.toPixels();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/browser/canvg.min.js

Large diffs are not rendered by default.

30 changes: 17 additions & 13 deletions dist/node/canvg.js
@@ -1,7 +1,7 @@

/*
* canvg.js - Javascript SVG parser and renderer on Canvas
* version 2.0.0-beta.1
* version 2.0.0
* MIT Licensed
* Gabe Lerner (gabelerner@gmail.com)
* https://github.com/canvg/canvg
Expand Down Expand Up @@ -497,7 +497,7 @@

// points and paths
svg.ToNumberArray = function (s) {
var a = (s || '').match(/-?(\d+(\.\d+)?|\.\d+)(?=\D|$)/gm) || [];
var a = (s || '').match(/-?(\d+(?:\.\d*(?:[eE][+-]?\d+)?)?|\.\d+)(?=\D|$)/gm) || [];
for (var i = 0; i < a.length; i++) {
a[i] = parseFloat(a[i]);
}
Expand Down Expand Up @@ -1071,17 +1071,21 @@

// font
if (typeof ctx.font != 'undefined') {
ctx.font = svg.Font.CreateFont(
this.style('font-style').value,
this.style('font-variant').value,
this.style('font-weight').value,
this.style('font-size').hasValue() ? this.style('font-size').toPixels() + 'px' : '',
this.style('font-family').value).toString();

// update em size if needed
var currentFontSize = this.style('font-size', false, false);
if (currentFontSize.isPixels()) {
svg.emSize = currentFontSize.toPixels();
if (this.style('font').hasValue()) {
ctx.font = this.style('font').value;
} else {
ctx.font = svg.Font.CreateFont(
this.style('font-style').value,
this.style('font-variant').value,
this.style('font-weight').value,
this.style('font-size').hasValue() ? this.style('font-size').toPixels() + 'px' : '',
this.style('font-family').value).toString();

// update em size if needed
var currentFontSize = this.style('font-size', false, false);
if (currentFontSize.isPixels()) {
svg.emSize = currentFontSize.toPixels();
}
}
}

Expand Down
61 changes: 40 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -24,7 +24,7 @@
"main": "dist/node/canvg.js",
"types": "dist/node/canvg.d.ts",
"browser": "dist/browser/canvg.min.js",
"version": "2.0.0-beta.1",
"version": "2.0.0",
"scripts": {
"test-browser": "ava test/browser.test.js --tap | tap-diff",
"test-node": "ava test/node.test.js --tap | tap-diff",
Expand Down Expand Up @@ -71,7 +71,7 @@
"jsdom": "^13.0.0",
"mkdirp": "^0.5.1",
"pngjs-image": "^0.11.7",
"puppeteer": "^1.10.0",
"puppeteer": "^1.16.0",
"rollup": "^0.67.3",
"rollup-plugin-alias": "^1.4.0",
"rollup-plugin-commonjs": "^9.2.0",
Expand Down

0 comments on commit 98a12cb

Please sign in to comment.