From b4cd1d92352fbee779c171289c5979720265415e Mon Sep 17 00:00:00 2001 From: Szymon Nowak Date: Sun, 11 Jun 2017 17:34:20 +0200 Subject: [PATCH] Release 2.2.0 --- CHANGELOG.md | 7 +++++-- README.md | 2 +- example/js/signature_pad.js | 22 +++++++++++++--------- package.json | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bd177cc..7240e30f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ ## Changelog -### master +### 2.2.0 +#### Bug Fixes +* Export to SVG with correct pen colors. ([DynamoEffects](https://github.com/DynamoEffects) in [#260](https://github.com/szimek/signature_pad/pull/260)) -* Allow custom ratio/width/height when loading data URL onto canvas +#### Features +* Allow custom ratio/width/height when loading data URL onto canvas. ([halo](https://github.com/halo) in [#253](https://github.com/szimek/signature_pad/pull/253)) ### 2.1.1 * Fixed a bug where default value was applied for throttle when throttle was set to 0. ([mkrause](https://github.com/mkrause) in [#247](https://github.com/szimek/signature_pad/pull/247)) diff --git a/README.md b/README.md index 03252745..1525410b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Signature Pad [![npm](https://d25lcipzij17d.cloudfront.net/badge.svg?id=js&type=6&v=2.1.1&x2=0)](https://www.npmjs.com/package/signature_pad) [![Code Climate](https://codeclimate.com/github/szimek/signature_pad.png)](https://codeclimate.com/github/szimek/signature_pad) +# Signature Pad [![npm](https://d25lcipzij17d.cloudfront.net/badge.svg?id=js&type=6&v=2.2.0&x2=0)](https://www.npmjs.com/package/signature_pad) [![Code Climate](https://codeclimate.com/github/szimek/signature_pad.png)](https://codeclimate.com/github/szimek/signature_pad) Signature Pad is a JavaScript library for drawing smooth signatures. It's HTML5 canvas based and uses variable width Bézier curve interpolation based on [Smoother Signatures](http://corner.squareup.com/2012/07/smoother-signatures.html) post by [Square](https://squareup.com). diff --git a/example/js/signature_pad.js b/example/js/signature_pad.js index 2a76c545..2340cebb 100644 --- a/example/js/signature_pad.js +++ b/example/js/signature_pad.js @@ -1,5 +1,5 @@ /*! - * Signature Pad v2.1.1 + * Signature Pad v2.2.0 * https://github.com/szimek/signature_pad * * Copyright 2017 Szymon Nowak @@ -199,10 +199,12 @@ SignaturePad.prototype.clear = function () { SignaturePad.prototype.fromDataURL = function (dataUrl) { var _this = this; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var image = new Image(); - var ratio = window.devicePixelRatio || 1; - var width = this._canvas.width / ratio; - var height = this._canvas.height / ratio; + var ratio = options.ratio || window.devicePixelRatio || 1; + var width = options.width || this._canvas.width / ratio; + var height = options.height || this._canvas.height / ratio; this._reset(); image.src = dataUrl; @@ -274,7 +276,8 @@ SignaturePad.prototype._strokeUpdate = function (event) { this._data[this._data.length - 1].push({ x: point.x, y: point.y, - time: point.time + time: point.time, + color: this.penColor }); }; @@ -459,6 +462,7 @@ SignaturePad.prototype._fromData = function (pointGroups, drawCurve, drawDot) { for (var j = 0; j < group.length; j += 1) { var rawPoint = group[j]; var point = new Point(rawPoint.x, rawPoint.y, rawPoint.time); + var color = rawPoint.color; if (j === 0) { // First point in a group. Nothing to draw yet. @@ -471,7 +475,7 @@ SignaturePad.prototype._fromData = function (pointGroups, drawCurve, drawDot) { widths = _addPoint2.widths; if (curve && widths) { - drawCurve(curve, widths); + drawCurve(curve, widths, color); } } else { // Last point in a group. Do nothing. @@ -500,7 +504,7 @@ SignaturePad.prototype._toSVG = function () { svg.setAttributeNS(null, 'width', canvas.width); svg.setAttributeNS(null, 'height', canvas.height); - this._fromData(pointGroups, function (curve, widths) { + this._fromData(pointGroups, function (curve, widths, color) { var path = document.createElement('path'); // Need to check curve for NaN values, these pop up when drawing @@ -511,7 +515,7 @@ SignaturePad.prototype._toSVG = function () { path.setAttribute('d', attr); path.setAttribute('stroke-width', (widths.end * 2.25).toFixed(3)); - path.setAttribute('stroke', _this2.penColor); + path.setAttribute('stroke', color); path.setAttribute('fill', 'none'); path.setAttribute('stroke-linecap', 'round'); @@ -523,7 +527,7 @@ SignaturePad.prototype._toSVG = function () { circle.setAttribute('r', dotSize); circle.setAttribute('cx', rawPoint.x); circle.setAttribute('cy', rawPoint.y); - circle.setAttribute('fill', _this2.penColor); + circle.setAttribute('fill', rawPoint.color); svg.appendChild(circle); }); diff --git a/package.json b/package.json index 19bc5f9a..0238c6db 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "signature_pad", "description": "Library for drawing smooth signatures.", - "version": "2.1.1", + "version": "2.2.0", "homepage": "https://github.com/szimek/signature_pad", "author": { "name": "Szymon Nowak",