Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export to SVG with correct pen colors #260

Merged
merged 1 commit into from
Jun 11, 2017
Merged

Export to SVG with correct pen colors #260

merged 1 commit into from
Jun 11, 2017

Conversation

DynamoEffects
Copy link
Contributor

Hey @szimek this is a simple modification to export to SVG with the correct pen color for each stroke.

@@ -404,7 +406,7 @@ SignaturePad.prototype._toSVG = function () {

path.setAttribute('d', attr);
path.setAttribute('stroke-width', (widths.end * 2.25).toFixed(3));
path.setAttribute('stroke', this.penColor);
path.setAttribute('stroke', color);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no default value for color here (and for drawing dots as well), will it work with the existing exported SVG strings? Won't it set color to undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's test and see...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this works:

  1. Create a design with multiple colors.
  2. Export to SVG saves design with correct color combinations.
  3. Import from the same SVG shows color combinations correctly.

What doesn't work:

At that point you cannot export to SVG again using 2.1.1 even without the proposed change since the SVG export feature relies on recording the strokes to the this._data array.

The only solution I see would be to repopulate the this._data array by reinterpreting the imported SVG data instead of relying on the canvas itself to draw the imported data.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've added a note in the README that calling #toData won't really work if signature was loaded using #fromDataURL.

@szimek szimek merged commit 7326284 into szimek:master Jun 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants