字体加载后使用这个
await loadFontsInCanvas(canvas, fontData);
fabric.util.clearFabricFontCache();
canvas.getObjects()?.forEach((object) => {
if (object?.Type === 'text') {
handleTextOverflow(object);
}
});
canvas.renderAll();
function handleTextOverflow(textbox) {
const textWidth = textbox.calcTextWidth();
const textHeight = textbox.calcTextHeight();
textbox.set({
width: textWidth,
height: textHeight,
});
}
所以它要做的是清除字体缓存,这就是它计算错误的框大小的原因