Skip to content

Commit

Permalink
Fixed doubling images on mobile devices (iOS) - see https://surveyjs.…
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Dec 8, 2017
1 parent 81ea54a commit 2f7ef0f
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/signature_pad.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import * as SignaturePad from "signature_pad";

function resizeCanvas(canvas) {
var context = canvas.getContext("2d");
var devicePixelRatio = window.devicePixelRatio || 1;
var backingStoreRatio =
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio ||
1;

var ratio = devicePixelRatio / backingStoreRatio;

var oldWidth = canvas.width;
var oldHeight = canvas.height;

canvas.width = oldWidth * ratio;
canvas.height = oldHeight * ratio;

canvas.style.width = oldWidth + "px";
canvas.style.height = oldHeight + "px";

context.scale(ratio, ratio);
}

function init(Survey) {
var widget = {
name: "signaturepad",
Expand All @@ -25,8 +50,6 @@ function init(Survey) {
afterRender: function(question, el) {
var rootWidget = this;
var canvas = el.children[0].children[0];
canvas.width = question.width;
canvas.height = question.height;
var signaturePad = new SignaturePad(canvas);
if (question.isReadOnly) {
signaturePad.off();
Expand All @@ -37,7 +60,10 @@ function init(Survey) {
question.value = data;
};
var updateValueHandler = function() {
//signaturePad.clear();
signaturePad.clear();
canvas.width = question.width;
canvas.height = question.height;
resizeCanvas(canvas);
signaturePad.fromDataURL(question.value);
};
question.valueChangedCallback = updateValueHandler;
Expand Down

0 comments on commit 2f7ef0f

Please sign in to comment.