Skip to content

Commit 39d31c6

Browse files
authored
Merge pull request rpmsoftware#12 from rpmsoftware/issue-10-increase-res
Increase resolution of the signature pad
2 parents b10274a + af61fab commit 39d31c6

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class SignaturePad extends Component {
2020
style: View.propTypes.style,
2121
penColor: PropTypes.string,
2222
dataURL: PropTypes.string,
23+
height: PropTypes.number,
24+
width: PropTypes.number,
2325
penMinWidth: PropTypes.number,
2426
penMaxWidth: PropTypes.number,
2527
useFont: PropTypes.bool,
@@ -49,7 +51,9 @@ class SignaturePad extends Component {
4951
props.penMinWidth,
5052
props.penMaxWidth,
5153
props.useFont,
52-
escapedName
54+
escapedName,
55+
props.height,
56+
props.width
5357
);
5458
var html = htmlContent(injectedJavaScript, props.fontStyle);
5559
this.source = { html };
@@ -75,7 +79,9 @@ class SignaturePad extends Component {
7579
this.props.penMinWidth,
7680
this.props.penMaxWidth,
7781
this.props.useFont,
78-
escapedName
82+
escapedName,
83+
this.props.height,
84+
this.props.width
7985
);
8086
var html = htmlContent(injectedJavaScript, this.props.fontStyle);
8187
this.source = { html };

injectedHtml/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ var content = (script, fontStyle) =>
1616
-ms-transform:rotate(-90deg) translate(-100%, 0px);
1717
-webkit-transform:rotate(-90deg) translate(-100%, 0px);*/
1818
}
19+
20+
html, body {
21+
height: 100%;
22+
width: 100%;
23+
margin: 0;
24+
}
1925
</style>
2026
2127
<style type="text/css">
2228
${fontStyle}
2329
</style>
2430
2531
<body>
26-
<canvas style="margin-left: 0; margin-top: 0;"></canvas>
32+
<div><canvas style="margin-left: 0; margin-top: 0; width: 100%; height: 100%;"></canvas></div>
2733
<script>
2834
${script}
2935
</script>

injectedJavaScript/application.js

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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

Comments
 (0)