1
0
mirror of https://github.com/excalidraw/excalidraw.git synced 2024-11-10 11:35:52 +01:00

feat: support supplying custom scale when exporting canvas (#2904)

This commit is contained in:
David Luzar 2021-02-04 14:54:08 +01:00 committed by GitHub
parent e18e945cd3
commit f0f5430313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

@ -36,7 +36,7 @@ export const exportToCanvas = ({
canvas.width = ret.width;
canvas.height = ret.height;
return canvas;
return { canvas, scale: ret.scale };
},
);
};

@ -29,14 +29,14 @@ export const exportToCanvas = (
viewBackgroundColor: string;
shouldAddWatermark: boolean;
},
createCanvas: (width: number, height: number) => HTMLCanvasElement = (
width,
height,
) => {
createCanvas: (
width: number,
height: number,
) => { canvas: HTMLCanvasElement; scale: number } = (width, height) => {
const tempCanvas = document.createElement("canvas");
tempCanvas.width = width * scale;
tempCanvas.height = height * scale;
return tempCanvas;
return { canvas: tempCanvas, scale: 1 };
},
) => {
const sceneElements = getElementsAndWatermark(elements, shouldAddWatermark);
@ -47,13 +47,16 @@ export const exportToCanvas = (
shouldAddWatermark,
);
const tempCanvas = createCanvas(width, height);
const { canvas: tempCanvas, scale: newScale = scale } = createCanvas(
width,
height,
);
renderScene(
sceneElements,
appState,
null,
scale,
newScale,
rough.canvas(tempCanvas),
tempCanvas,
{