legalthings / angular-signature

HTML5 canvas based smooth signature drawing as angularJS directive (http://szimek.github.io/signature_pad/)
MIT License
105 stars 91 forks source link

Resizing causes canvas size to double #31

Closed blairjo closed 7 years ago

blairjo commented 7 years ago

Hi,

I was having issues using the signature pad on a modal popup, so I tried taking your latest github code. What I found is that when the screen is resized (say by rotating a mobile from portrait to landscape) the canvas size is doubling each time, because in the onResize() method below the "ratio" is 2.

Is this something you're aware of / looking at?

I've fixed it on a local version by doing this, but there may be a better way:

scope.onResize = function () {
  var canvas = element.find('canvas')[0];
   // Make it visually fill the positioned parent
  canvas.style.width = '100%';
  canvas.style.height = '100%';
  // ...then set the internal size to match
   canvas.width = canvas.offsetWidth;
  canvas.height = canvas.offsetHeight;

  // reset dataurl
  scope.dataurl = null;
};
zcsongor commented 7 years ago

+1