fix: fontstyle after save text signature issue

This commit is contained in:
RaktimaNXG
2024-01-03 13:46:44 +05:30
parent 081dae0b90
commit ac9367a715
@@ -53,6 +53,7 @@ function SignPad({
const currentUserName = jsonSender && jsonSender.name;
//function for clear signature
setSignValue(currentUserName);
setFontSelect("Fasthand");
}, []);
//function for clear signature
const handleClear = () => {
@@ -132,6 +133,22 @@ function SignPad({
);
};
useEffect(() => {
const loadFont = async () => {
try {
await document.fonts.load(`20px ${fontSelect}`);
const selectFontSTyle = fontOptions.find(
(font) => font.value === fontSelect
);
setFontSelect(selectFontSTyle?.value || fontOptions[0].value);
} catch (error) {
console.error("Error loading font:", error);
}
};
loadFont();
}, [fontSelect]);
useEffect(() => {
// Load the default signature after the component mounts
if (canvasRef.current) {
@@ -149,7 +166,8 @@ function SignPad({
? fontStyle
: fontSelect
? fontSelect
: fontOptions[0].value;
: "Fasthand";
console.log("font family", fontfamily);
// Calculate the width of the text content
const textWidth = getTextWidth(textContent, fontfamily);
// Increase pixel ratio for higher resolution