Skip to content

Commit 2f7ef0f

Browse files
committed
Fixed doubling images on mobile devices (iOS) - see https://surveyjs.answerdesk.io/ticket/details/T302
1 parent 81ea54a commit 2f7ef0f

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/signature_pad.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
import * as SignaturePad from "signature_pad";
22

3+
function resizeCanvas(canvas) {
4+
var context = canvas.getContext("2d");
5+
var devicePixelRatio = window.devicePixelRatio || 1;
6+
var backingStoreRatio =
7+
context.webkitBackingStorePixelRatio ||
8+
context.mozBackingStorePixelRatio ||
9+
context.msBackingStorePixelRatio ||
10+
context.oBackingStorePixelRatio ||
11+
context.backingStorePixelRatio ||
12+
1;
13+
14+
var ratio = devicePixelRatio / backingStoreRatio;
15+
16+
var oldWidth = canvas.width;
17+
var oldHeight = canvas.height;
18+
19+
canvas.width = oldWidth * ratio;
20+
canvas.height = oldHeight * ratio;
21+
22+
canvas.style.width = oldWidth + "px";
23+
canvas.style.height = oldHeight + "px";
24+
25+
context.scale(ratio, ratio);
26+
}
27+
328
function init(Survey) {
429
var widget = {
530
name: "signaturepad",
@@ -25,8 +50,6 @@ function init(Survey) {
2550
afterRender: function(question, el) {
2651
var rootWidget = this;
2752
var canvas = el.children[0].children[0];
28-
canvas.width = question.width;
29-
canvas.height = question.height;
3053
var signaturePad = new SignaturePad(canvas);
3154
if (question.isReadOnly) {
3255
signaturePad.off();
@@ -37,7 +60,10 @@ function init(Survey) {
3760
question.value = data;
3861
};
3962
var updateValueHandler = function() {
40-
//signaturePad.clear();
63+
signaturePad.clear();
64+
canvas.width = question.width;
65+
canvas.height = question.height;
66+
resizeCanvas(canvas);
4167
signaturePad.fromDataURL(question.value);
4268
};
4369
question.valueChangedCallback = updateValueHandler;

0 commit comments

Comments
 (0)