Skip to content

Commit

Permalink
Sync master with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
dgorbash committed Feb 27, 2019
2 parents c22274c + f236319 commit 79c85e5
Show file tree
Hide file tree
Showing 219 changed files with 19,407 additions and 1,371 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
@@ -0,0 +1,13 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
2 changes: 2 additions & 0 deletions .eslintignore
@@ -0,0 +1,2 @@
dist
examples/flashcanvas.js
16 changes: 16 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,16 @@
{
"extends": ["eslint:recommended"],
"env": {
"es6": true
},
"overrides": {
"files": ["rollup.config.js", "ava.config.js"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
}
},
"rules": {
"no-useless-escape": 0
}
}
10 changes: 10 additions & 0 deletions .gitignore
@@ -0,0 +1,10 @@
.nyc_output
node_modules
test/actual
test/actual_node
test/actual_browser
test/diff_node
test/diff_browser
.vscode
.idea
yarn-error.log
5 changes: 5 additions & 0 deletions .npmignore
@@ -0,0 +1,5 @@
./*
!./dist
!./package.json
!./LICENSE
!./README.md
9 changes: 9 additions & 0 deletions .travis.yml
@@ -0,0 +1,9 @@
language: node_js
node_js:
- "node"
before_install:
- sudo apt-get update
- sudo apt-get install -y libgif-dev
after_failure:
- zip -r ./canvg-expected.zip ./test/actual_node ./test/diff_node
- curl --upload-file ./canvg-expected.zip https://transfer.sh/canvg-expected.zip
24 changes: 24 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,24 @@
# Change Log

## v2.0.0 (beta)
- **Breaking change**: now dependent on [canvas 2.x](https://github.com/Automattic/node-canvas)
- Implement focal gradient radius ([#675](https://github.com/canvg/canvg/pull/675))
- Fixes 0 height rects ([#674](https://github.com/canvg/canvg/pull/674))
- Fixes masks with alpha ([#672](https://github.com/canvg/canvg/pull/672))
- Misc minor issues ([#670](https://github.com/canvg/canvg/pull/670))
- Fixes opacity hierarchy ([#666](https://github.com/canvg/canvg/pull/666))
- Better number array parsing ([#665](https://github.com/canvg/canvg/pull/665))
- Better external font parsing ([#664](https://github.com/canvg/canvg/pull/664))
- Fixes parsing of negatives ([#663](https://github.com/canvg/canvg/pull/663))
- Fixes scaling on redraws ([#662](https://github.com/canvg/canvg/pull/662))
- Fixes `text-anchor` ([#660](https://github.com/canvg/canvg/pull/660))
- Fixes <animate> under <text> ([#656](https://github.com/canvg/canvg/pull/656))
- Handle milliseconds appropriately ([#653](https://github.com/canvg/canvg/pull/653))
- Optimizing updates ([#650](https://github.com/canvg/canvg/pull/650))

## v1.5.4
- Created Change Log
- Fixed Image class for node ([#631](https://github.com/canvg/canvg/pull/631))
- Corrected typings ([#638](https://github.com/canvg/canvg/pull/638))
- Do not blow up when using `feDropShadow` ([#639](https://github.com/canvg/canvg/pull/639))
- Latter CSS specifity wins over former ([#642](https://github.com/canvg/canvg/pull/642))
File renamed without changes.
89 changes: 63 additions & 26 deletions README.md
@@ -1,42 +1,84 @@
Introduction
============
# canvg

[![Build Status](https://travis-ci.com/canvg/canvg.svg?branch=master)](https://travis-ci.com/canvg/canvg)
[![npm](https://img.shields.io/npm/dm/canvg.svg)](https://www.npmjs.com/package/canvg)
[![](https://data.jsdelivr.com/v1/package/npm/canvg/badge?style=rounded)](https://www.jsdelivr.com/package/npm/canvg)

## Looking for Contributors

In an attempt to keep this repo more active and merge PRs and do releases, if you would like to be a contributor, please start a conversation with me at gabelerner at gmail. The prerequisite is to have a few PRs open to prove out an understanding of the code. Thanks!

## Introduction

canvg is a SVG parser and renderer. It takes a URL to a SVG file or the text of an SVG file, parses it in JavaScript, and renders the result on a [Canvas](http://dev.w3.org/html5/2dcontext/) element. The rendering speed of the examples is about as fast as native SVG.

What's implemented?
===================
## What's implemented?

The end goal is everything from the [SVG spec](http://www.w3.org/TR/SVG/). The majority of the rendering and animation is working. If you would like to see a feature implemented, don't hesitate to contact me or add it to the issues list.

Potential uses
===============
## Potential uses

* Allows for inline embedding of SVG through JavaScript (w/o having to request another file or break validation)
* Allows for single SVG version across all browsers that support Canvas
* Allows for mobile devices supporting Canvas but not SVG to render SVG
* Allows for SVG -> Canvas -> png transition all on the client side (through [toDataUrl](http://www.w3.org/TR/html5/the-canvas-element.html#dom-canvas-todataurl))

Example Demonstration
=====================
[view here](http://canvg.github.io/canvg/examples/index.htm)
Tested in Chrome, Firefox, Opera, and IE (through FlashCanvas)
## Example Demonstration

[hosted](http://canvg.github.io/canvg/examples/index.htm)

[jsfiddle playground](http://jsfiddle.net/6r2jug6o/2590/)

Locally, you can run `npm start` and view the examples at [http://localhost:3123/examples/index.htm](http://localhost:3123/examples/index.htm)

## Building

[jsfiddle playground](http://jsfiddle.net/6r2jug6o/)
`npm run build` then look in the `dist` folder

## Testing

- `npm run test-node` runs tests on `node`
- `npm run test-browser` runs tests on `browser`
- `npm run generate-expected foo.svg` to create the expected png for a given svg in the `svgs` folder

## Usage on the server

`npm install canvg`

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

`npm install canvg@2.0.0-beta.0`

## Usage on the Browser

Usage
=====
Include the following files in your page:
```html
<script type="text/javascript" src="http://canvg.github.io/canvg/rgbcolor.js"></script>
<script type="text/javascript" src="http://canvg.github.io/canvg/StackBlur.js"></script>
<script type="text/javascript" src="http://canvg.github.io/canvg/canvg.js"></script>
<!-- Required to convert named colors to RGB -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/canvg/1.4/rgbcolor.min.js"></script>
<!-- Optional if you want blur -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/stackblur-canvas/1.4.1/stackblur.min.js"></script>
<!-- Main canvg code -->
<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://cdnjs.cloudflare.com/ajax/libs/canvg/1.4/rgbcolor.min.js"></script>
<!-- Optional if you want blur -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/stackblur-canvas/1.4.1/stackblur.min.js"></script>
<!-- Main canvg code -->
<script src="https://cdn.jsdelivr.net/npm/canvg@2.0.0-beta.0/dist/browser/canvg.min.js"></script>
```

Put a canvas on your page
```html
<canvas id="canvas" width="1000px" height="600px"></canvas>
<canvas id="canvas" width="1000px" height="600px"></canvas>
```

Example canvg calls:
```html
<script type="text/javascript">
<script>
window.onload = function() {
//load '../path/to/your.svg' in the canvas with id = 'canvas'
canvg('canvas', '../path/to/your.svg')
Expand All @@ -45,7 +87,7 @@ window.onload = function() {
canvg(document.getElementById('drawingArea'), '<svg>...</svg>')
//ignore mouse events and animation
canvg('canvas', 'file.svg', { ignoreMouse: true, ignoreAnimation: true })
canvg('canvas', 'file.svg', { ignoreMouse: true, ignoreAnimation: true })
}
</script>
```
Expand All @@ -64,17 +106,12 @@ The third parameter is options:
* forceRedraw: function => will call the function on every frame, if it returns true, will redraw
* useCORS: true => will attempt to use CORS on images to not taint canvas

You can call canvg without parameters to replace all svg images on a page. See the [example](http://canvg.github.io/canvg/examples/convert.htm).
You can call canvg without parameters to replace all svg images on a page. See the
[example](http://canvg.github.io/canvg/examples/convert.htm).

There is also a built in extension method to the canvas context to draw svgs similar to the way [drawImage](http://www.w3.org/TR/2dcontext/#dom-context-2d-drawimage) works:
```javascript
var c = document.getElementById('canvas');
var ctx = c.getContext('2d');
ctx.drawSvg(SVG_XML_OR_PATH_TO_SVG, dx, dy, dw, dh);
```

Related Repositories
====================
* [Output javascript instead of rendering to canvas](http://code.google.com/p/jscapturecanvas/)
* [A combo of canvg & jscapturecanvas to compile SVG to Canvas (Server side)](https://github.com/nathan-muir/canvgc)
* [Edit SVG files in your browser](https://code.google.com/p/svg-edit/)

0 comments on commit 79c85e5

Please sign in to comment.