Skip to content

fix(svg-export): prevent duplicated viewBox attribute #66

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,19 @@ export class DrawingPad extends DrawingPadBase {
if (!this.nativeView.isEmpty()) {
const data: string = this.nativeView.getSignatureSvg();

// Append viewbox to the svg for correct scaling
const svgHeaderRegEx = /<svg (.*) height="(\d+)" width="(\d+)"(.*)>/i;
resolve(
data.replace(
svgHeaderRegEx,
`<svg $1 viewBox="0, 0, $3, $2" height="$2" width="$3"$4>`
)
);
// Append viewbox to the svg for correct scaling (IF NEEDED)
if (data.indexOf('viewBox') === -1) {
const svgHeaderRegEx = /<svg (.*) height="(\d+)" width="(\d+)"(.*)>/i;
resolve(
data.replace(
svgHeaderRegEx,
`<svg $1 viewBox="0, 0, $3, $2" height="$2" width="$3"$4>`
)
);
} else {
resolve(data);
}

} else {
reject('DrawingPad is empty.');
}
Expand Down