Skip to content

Commit cf88eb2

Browse files
fix: font-style issue after save text signature
1 parent ee60906 commit cf88eb2

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

microfrontends/SignDocuments/src/Component/component/signPad.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function SignPad({
9595
} else {
9696
if (isTab === "type") {
9797
setIsSignImg("");
98-
onSaveSign(false, textWidth, 30);
98+
onSaveSign(false, textWidth, 25);
9999
} else {
100100
setIsSignImg("");
101101
onSaveSign();
@@ -142,37 +142,42 @@ function SignPad({
142142
}
143143
}, [isTab]);
144144
//function for convert input text value in image
145-
const convertToImg = async () => {
145+
const convertToImg = async (fontStyle) => {
146146
//get text content to convert in image
147147
const textContent = signValue;
148+
const fontfamily = fontStyle ? fontStyle : fontSelect;
148149
// Calculate the width of the text content
149-
const textWidth = getTextWidth(textContent);
150+
const textWidth = getTextWidth(textContent, fontfamily);
150151
// Increase pixel ratio for higher resolution
151152
const pixelRatio = window.devicePixelRatio || 1;
152-
153153
// Create a canvas with the calculated width
154154
const canvas = document.createElement("canvas");
155-
canvas.width = textWidth * pixelRatio + 30 * pixelRatio;
155+
canvas.width = textWidth * pixelRatio + 10 * pixelRatio;
156156
canvas.height = 20 * pixelRatio; // You can adjust the height as needed
157157
setTextWidth(textWidth * pixelRatio);
158+
158159
// Draw the text content on the canvas
159160
const context = canvas.getContext("2d");
161+
162+
context.clearRect(0, 0, canvas.width, canvas.height);
160163
context.scale(pixelRatio, pixelRatio);
161-
context.font = `13px ${fontSelect}`; // You can adjust the font size and style
164+
context.font = `13px ${fontfamily}`; // You can adjust the font size and style
162165
context.fillText(textContent, 0, 10); // Adjust the y-coordinate as needed
163166

164167
// Convert the canvas to image data
165168
const dataUrl = canvas.toDataURL("image/png");
169+
166170
setSignature(dataUrl);
167171
};
168172

169173
//for getting text content width render text in span tag and get width
170-
const getTextWidth = (text) => {
174+
const getTextWidth = (text, fontfamily) => {
171175
const tempSpan = document.createElement("span");
172176
tempSpan.innerText = text;
173177
tempSpan.style.visibility = "hidden";
178+
tempSpan.style.fontFamily = fontfamily;
174179
document.body.appendChild(tempSpan);
175-
const width = tempSpan.offsetWidth;
180+
const width = tempSpan.getBoundingClientRect().width;
176181
document.body.removeChild(tempSpan);
177182
return width;
178183
};
@@ -426,9 +431,16 @@ function SignPad({
426431
)
427432
) : isTab === "type" ? (
428433
<div>
429-
<div style={{ display: "flex", justifyContent: "space-between" }}>
430-
<span>Signature: </span>
434+
<div
435+
style={{
436+
display: "flex",
437+
justifyContent: "space-between",
438+
alignItems: "center"
439+
}}
440+
>
441+
<span className="signatureText">Signature:</span>
431442
<input
443+
maxLength={15}
432444
style={{ fontFamily: fontSelect }}
433445
type="text"
434446
className="signatureInput"
@@ -450,9 +462,17 @@ function SignPad({
450462
backgroundColor:
451463
fontSelect === font.value && "rgb(206 225 247)"
452464
}}
453-
onClick={() => setFontSelect(font.value)}
465+
onClick={() => {
466+
setFontSelect(font.value);
467+
convertToImg(font.value);
468+
}}
454469
>
455-
<div style={{ padding: "5px 10px 5px 10px" }}>
470+
<div
471+
style={{
472+
padding: "5px 10px 5px 10px",
473+
fontSize: "20px"
474+
}}
475+
>
456476
{signValue ? signValue : "Your signature"}
457477
</div>
458478
</div>

microfrontends/SignDocuments/src/css/signature.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
.signatureInput {
131131
width: 80%;
132132
border-radius: 4px;
133-
font-size: 0.75rem;
133+
font-size: 20px;
134134
border: 1px solid #e2dddd;
135135
color: black;
136136
font-family: inherit;
@@ -791,6 +791,10 @@ option {
791791
.mobileHead {
792792
display: flex;
793793
}
794+
.signatureText{
795+
margin-right: 5px;
796+
font-size: 12px;
797+
}
794798
}
795799

796800
@media screen and (max-width:487px) and (min-width:351px) {
@@ -819,7 +823,7 @@ option {
819823

820824
font-weight: 500 !important;
821825

822-
font-size: 10px !important;
826+
font-size: 12px !important;
823827
}
824828

825829
}

0 commit comments

Comments
 (0)