1- var content = ( penColor , backgroundColor , dataURL , penMinWidth , penMaxWidth , useFont , name ) => `
1+ var content = ( penColor , backgroundColor , dataURL , penMinWidth , penMaxWidth , useFont , name , height , width ) => `
22
33 var showSignaturePad = function (signaturePadCanvas, bodyWidth, bodyHeight) {
44 /*We're rotating by 90% -> Flip X and Y*/
@@ -9,7 +9,7 @@ var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, use
99 var height = bodyHeight;
1010
1111 var sizeSignaturePad = function () {
12- var devicePixelRatio = 1; /* window.devicePixelRatio || 1;*/
12+ var devicePixelRatio = window.devicePixelRatio || 1;
1313 var canvasWidth = width * devicePixelRatio;
1414 var canvasHeight = height * devicePixelRatio;
1515 signaturePadCanvas.width = canvasWidth;
@@ -44,55 +44,41 @@ var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, use
4444 enableSignaturePadFunctionality();
4545 };
4646
47- var bodyWidth = document.body.clientWidth;
48- var bodyHeight = document.body.clientHeight;
47+ var bodyWidth = document.body.clientWidth * 2 ;
48+ var bodyHeight = document.body.clientHeight * 2 ;
4949 if(!bodyWidth) {
50- bodyWidth = window.innerWidth;
50+ bodyWidth = window.innerWidth ? window.innerWidth : ${ width } ;
5151 }
5252 if(!bodyHeight) {
53- bodyHeight = window.innerHeight;
53+ bodyHeight = window.innerHeight ? window.innerHeight : ${ height } ;
5454 }
5555
5656 var canvasElement = document.querySelector("canvas");
5757
5858 if (${ useFont } ) {
5959 var context = canvasElement.getContext("2d");
6060 var devicePixelRatio = 1; /* window.devicePixelRatio || 1; */
61- context.canvas .width = bodyWidth * devicePixelRatio;
62- context.canvas .height = bodyHeight * devicePixelRatio;
61+ canvasElement .width = bodyWidth * devicePixelRatio;
62+ canvasElement .height = bodyHeight * devicePixelRatio;
6363
64- var ratio = Math.max(window.devicePixelRatio || 1, 1);
65- var backingStoreRatio = context.webkitBackingStorePixelRatio ||
66- context.mozBackingStorePixelRatio ||
67- context.msBackingStorePixelRatio ||
68- context.oBackingStorePixelRatio ||
69- context.backingStorePixelRatio || 1;
70- var realRatio = ratio / backingStoreRatio;
71- if (ratio !== backingStoreRatio) {
72- ratio = ratio / backingStoreRatio;
73- }
74-
75- var oldWidth = context.canvas.width;
76- var oldHeight = context.canvas.height;
77-
78- var fontSize = 45;
79- var textHeight = 12;
80- if (realRatio === 2) {
81- fontSize = 90;
82- textHeight = 18;
83- }
64+ var w = bodyWidth;
65+ var h = bodyHeight;
66+ canvasElement.width = canvasElement.offsetWidth * 2;
67+ canvasElement.height = canvasElement.offsetHeight * 2;
8468
69+ var fontToHeightRatio = 45 / 159;
70+ var fontSize = canvasElement.height * fontToHeightRatio;
71+ var textHeight = 18;
8572 var textWidth = -1;
86-
8773 do {
8874 context.font = fontSize + "px SignatureFont";
89- textWidth = context.measureText("${ name } ").width * ratio ;
75+ textWidth = context.measureText("${ name } ").width;
9076 fontSize = 7 * fontSize / 8;
91- } while (textWidth > oldWidth );
77+ } while (textWidth + (w * 0.05) > w );
9278
9379 var textPosition = {
94- x: ((oldWidth - textWidth) / 2),
95- y: ((3 * oldHeight / 4) - textHeight)
80+ x: ((w - textWidth) / 2),
81+ y: ((3 * h / 4) - textHeight)
9682 };
9783
9884 context.fillStyle = "${ penColor } ";
@@ -101,7 +87,7 @@ var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, use
10187 /* Fire a finishedStroke function to update the state */
10288 executeNativeFunction("finishedStroke", {base64DataUrl: canvasElement.toDataURL()});
10389 } else {
104- showSignaturePad(canvasElement, bodyWidth, bodyHeight);
90+ showSignaturePad(canvasElement, bodyWidth / 2 , bodyHeight / 2 );
10591 }
10692` ;
10793
0 commit comments