feat: support supplying custom scale when exporting canvas (#2904)
This commit is contained in:
parent
e18e945cd3
commit
f0f5430313
@ -36,7 +36,7 @@ export const exportToCanvas = ({
|
|||||||
canvas.width = ret.width;
|
canvas.width = ret.width;
|
||||||
canvas.height = ret.height;
|
canvas.height = ret.height;
|
||||||
|
|
||||||
return canvas;
|
return { canvas, scale: ret.scale };
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -29,14 +29,14 @@ export const exportToCanvas = (
|
|||||||
viewBackgroundColor: string;
|
viewBackgroundColor: string;
|
||||||
shouldAddWatermark: boolean;
|
shouldAddWatermark: boolean;
|
||||||
},
|
},
|
||||||
createCanvas: (width: number, height: number) => HTMLCanvasElement = (
|
createCanvas: (
|
||||||
width,
|
width: number,
|
||||||
height,
|
height: number,
|
||||||
) => {
|
) => { canvas: HTMLCanvasElement; scale: number } = (width, height) => {
|
||||||
const tempCanvas = document.createElement("canvas");
|
const tempCanvas = document.createElement("canvas");
|
||||||
tempCanvas.width = width * scale;
|
tempCanvas.width = width * scale;
|
||||||
tempCanvas.height = height * scale;
|
tempCanvas.height = height * scale;
|
||||||
return tempCanvas;
|
return { canvas: tempCanvas, scale: 1 };
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
const sceneElements = getElementsAndWatermark(elements, shouldAddWatermark);
|
const sceneElements = getElementsAndWatermark(elements, shouldAddWatermark);
|
||||||
@ -47,13 +47,16 @@ export const exportToCanvas = (
|
|||||||
shouldAddWatermark,
|
shouldAddWatermark,
|
||||||
);
|
);
|
||||||
|
|
||||||
const tempCanvas = createCanvas(width, height);
|
const { canvas: tempCanvas, scale: newScale = scale } = createCanvas(
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
);
|
||||||
|
|
||||||
renderScene(
|
renderScene(
|
||||||
sceneElements,
|
sceneElements,
|
||||||
appState,
|
appState,
|
||||||
null,
|
null,
|
||||||
scale,
|
newScale,
|
||||||
rough.canvas(tempCanvas),
|
rough.canvas(tempCanvas),
|
||||||
tempCanvas,
|
tempCanvas,
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user