Compare commits
2 Commits
master
...
zsviczian-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3ad69c661f | ||
![]() |
56ea3c5bd0 |
@ -251,6 +251,7 @@ const drawImagePlaceholder = (
|
|||||||
size,
|
size,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawElementOnCanvas = (
|
const drawElementOnCanvas = (
|
||||||
element: NonDeletedExcalidrawElement,
|
element: NonDeletedExcalidrawElement,
|
||||||
rc: RoughCanvas,
|
rc: RoughCanvas,
|
||||||
@ -300,17 +301,35 @@ const drawElementOnCanvas = (
|
|||||||
const img = isInitializedImageElement(element)
|
const img = isInitializedImageElement(element)
|
||||||
? renderConfig.imageCache.get(element.fileId)?.image
|
? renderConfig.imageCache.get(element.fileId)?.image
|
||||||
: undefined;
|
: undefined;
|
||||||
|
context.save();
|
||||||
|
const { width, height } = element;
|
||||||
|
if (element.roundness) {
|
||||||
|
const r = getCornerRadius(Math.min(width, height), element) / 4;
|
||||||
|
context.beginPath();
|
||||||
|
context.moveTo(r, 0);
|
||||||
|
context.lineTo(width - r, 0);
|
||||||
|
context.quadraticCurveTo(width, 0, width, r);
|
||||||
|
context.lineTo(width, height - r);
|
||||||
|
context.quadraticCurveTo(width, height, width - r, height);
|
||||||
|
context.lineTo(r, height);
|
||||||
|
context.quadraticCurveTo(0, height, 0, height - r);
|
||||||
|
context.lineTo(0, r);
|
||||||
|
context.quadraticCurveTo(0, 0, r, 0);
|
||||||
|
context.closePath();
|
||||||
|
context.clip();
|
||||||
|
}
|
||||||
if (img != null && !(img instanceof Promise)) {
|
if (img != null && !(img instanceof Promise)) {
|
||||||
context.drawImage(
|
context.drawImage(
|
||||||
img,
|
img,
|
||||||
0 /* hardcoded for the selection box*/,
|
0 /* hardcoded for the selection box*/,
|
||||||
0,
|
0,
|
||||||
element.width,
|
width,
|
||||||
element.height,
|
height,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
drawImagePlaceholder(element, context, renderConfig.zoom.value);
|
drawImagePlaceholder(element, context, renderConfig.zoom.value);
|
||||||
}
|
}
|
||||||
|
context.restore();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -1390,7 +1409,14 @@ export const renderElementToSvg = (
|
|||||||
image.setAttribute("width", "100%");
|
image.setAttribute("width", "100%");
|
||||||
image.setAttribute("height", "100%");
|
image.setAttribute("height", "100%");
|
||||||
image.setAttribute("href", fileData.dataURL);
|
image.setAttribute("href", fileData.dataURL);
|
||||||
|
if (element.roundness) {
|
||||||
|
const r =
|
||||||
|
getCornerRadius(
|
||||||
|
Math.min(element.width, element.height),
|
||||||
|
element,
|
||||||
|
) / 4;
|
||||||
|
image.setAttribute("clip-path", `inset(0% round ${r}px)`);
|
||||||
|
}
|
||||||
symbol.appendChild(image);
|
symbol.appendChild(image);
|
||||||
|
|
||||||
root.prepend(symbol);
|
root.prepend(symbol);
|
||||||
|
@ -29,7 +29,8 @@ export const canChangeRoundness = (type: string) =>
|
|||||||
type === "rectangle" ||
|
type === "rectangle" ||
|
||||||
type === "arrow" ||
|
type === "arrow" ||
|
||||||
type === "line" ||
|
type === "line" ||
|
||||||
type === "diamond";
|
type === "diamond" ||
|
||||||
|
type === "image";
|
||||||
|
|
||||||
export const hasText = (type: string) => type === "text";
|
export const hasText = (type: string) => type === "text";
|
||||||
|
|
||||||
|
@ -118,6 +118,7 @@ describe("export", () => {
|
|||||||
scale: [1, 1],
|
scale: [1, 1],
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 100,
|
height: 100,
|
||||||
|
roundness: null,
|
||||||
angle: normalizeAngle(315),
|
angle: normalizeAngle(315),
|
||||||
}),
|
}),
|
||||||
API.createElement({
|
API.createElement({
|
||||||
@ -128,6 +129,7 @@ describe("export", () => {
|
|||||||
scale: [-1, 1],
|
scale: [-1, 1],
|
||||||
width: 50,
|
width: 50,
|
||||||
height: 50,
|
height: 50,
|
||||||
|
roundness: null,
|
||||||
angle: normalizeAngle(45),
|
angle: normalizeAngle(45),
|
||||||
}),
|
}),
|
||||||
API.createElement({
|
API.createElement({
|
||||||
@ -138,6 +140,7 @@ describe("export", () => {
|
|||||||
scale: [1, -1],
|
scale: [1, -1],
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 100,
|
height: 100,
|
||||||
|
roundness: null,
|
||||||
angle: normalizeAngle(45),
|
angle: normalizeAngle(45),
|
||||||
}),
|
}),
|
||||||
API.createElement({
|
API.createElement({
|
||||||
@ -148,6 +151,7 @@ describe("export", () => {
|
|||||||
scale: [-1, -1],
|
scale: [-1, -1],
|
||||||
width: 50,
|
width: 50,
|
||||||
height: 50,
|
height: 50,
|
||||||
|
roundness: null,
|
||||||
angle: normalizeAngle(315),
|
angle: normalizeAngle(315),
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user