Skip to content

Commit eab9cca

Browse files
committed
enhanced android svg to have viewBox for correct scaling
enhanced android svg to have viewBox for correct scaling
1 parent aeb855c commit eab9cca

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

demo/app/main-page.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<StackLayout>
77
<DrawingPad:DrawingPad backgroundColor="#222" id="drawingPad" margin="10" height="280" penColor="{{ penColor }}" penWidth="{{ penWidth }}" />
88
<StackLayout orientation="horizontal">
9-
<Button text="Get Drawing (Image)" tap="{{ getMyDrawing }}" />
10-
<Button text="Get Drawing (SVG)" tap="{{ getMyDrawingSvg }}" marginLeft="5" />
9+
<Button text="Get Image" tap="{{ getMyDrawing }}" />
10+
<Button text="Get SVG" tap="{{ getMyDrawingSvg }}" />
1111
</StackLayout>
1212
<StackLayout orientation="horizontal">
1313
<Button text="Clear" tap="{{ clearMyDrawing }}" />
14-
<Button text="Pick Color" tap="{{ openColorPicker }}" marginLeft="5" />
14+
<Button text="Pick Color" tap="{{ openColorPicker }}" />
1515
</StackLayout>
1616
<GridLayout padding="10" rows="*, *" columns="*, *">
1717
<Label text="Pen Width:" class="message" textWrap="true" row="0" col="0" />

drawingpad.android.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ export class DrawingPad extends DrawingPadBase {
7575
return new Promise((resolve, reject) => {
7676
try {
7777
if (!this.nativeView.isEmpty()) {
78-
let data = this.nativeView.getSignatureSvg();
79-
resolve(data);
78+
let data: string = this.nativeView.getSignatureSvg();
79+
80+
// Append viewbox to the svg for correct scaling
81+
const svgHeaderRegEx = /<svg (.*) height="(\d+)" width="(\d+)"(.*)>/i
82+
resolve(data.replace(svgHeaderRegEx, `<svg $1 viewBox="0, 0, $3, $2" height="$2" width="$3"$4>`));
8083
} else {
8184
reject("DrawingPad is empty.");
8285
}

0 commit comments

Comments
 (0)