mirror of
https://github.com/documenso/documenso.git
synced 2026-08-15 02:53:32 +10:00
Use our fork of `skia-canvas` for rendering which handles encoding characters correctly with the caveat font and other similar fonts that can group glyphs like ligatures. This resolves issues with pdf text extraction where characters were unable to be extracted due to lacking any data within the cmaps.
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
/**
|
|
* !: This is a workaround to fix the memory leak in the skia-canvas library.
|
|
* !: Internals are ported from the original `konva/skia-backend.js` file.
|
|
*/
|
|
|
|
import { Canvas, DOMMatrix, Image, Path2D } from '@documenso/skia-canvas';
|
|
import { Konva } from 'konva/lib/_CoreInternals';
|
|
|
|
// @ts-expect-error skia-canvas satisfies the requirements
|
|
global.DOMMatrix = DOMMatrix;
|
|
|
|
// @ts-expect-error skia-canvas satisfies the requirements
|
|
global.Path2D = Path2D;
|
|
Path2D.prototype.toString = () => '[object Path2D]';
|
|
|
|
Konva.Util['createCanvasElement'] = () => {
|
|
const node = new Canvas(300, 300);
|
|
node.gpu = false;
|
|
|
|
if (!('style' in node) || !node['style']) {
|
|
Object.assign(node, { style: {} });
|
|
}
|
|
|
|
node.toString = () => '[object HTMLCanvasElement]';
|
|
const ctx = node.getContext('2d');
|
|
|
|
Object.defineProperty(ctx, 'canvas', {
|
|
get: () => node,
|
|
});
|
|
|
|
return node as unknown as HTMLCanvasElement;
|
|
};
|
|
|
|
Konva.Util.createImageElement = () => {
|
|
const node = new Image();
|
|
node.toString = () => '[object HTMLImageElement]';
|
|
|
|
return node as unknown as HTMLImageElement;
|
|
};
|
|
|
|
Konva._renderBackend = '@documenso/skia-canvas';
|
|
|
|
export default Konva;
|