Compare commits

...

3 Commits

Author SHA1 Message Date
dwelle
8174f9803e fix snaps 2024-10-24 13:41:03 +02:00
Ryan Di
b863262773 adding crop hash to symbol 2024-10-24 16:03:34 +08:00
Ryan Di
ef037d3de8 fix: replace view box with clip path for pdf and server exports 2024-10-24 15:39:19 +08:00
2 changed files with 14 additions and 13 deletions

View File

@ -7,7 +7,7 @@ import {
SVG_NS, SVG_NS,
} from "../constants"; } from "../constants";
import { normalizeLink, toValidURL } from "../data/url"; import { normalizeLink, toValidURL } from "../data/url";
import { getElementAbsoluteCoords } from "../element"; import { getElementAbsoluteCoords, hashString } from "../element";
import { import {
createPlaceholderEmbeddableLabel, createPlaceholderEmbeddableLabel,
getEmbedLink, getEmbedLink,
@ -411,7 +411,8 @@ const renderElementToSvg = (
const fileData = const fileData =
isInitializedImageElement(element) && files[element.fileId]; isInitializedImageElement(element) && files[element.fileId];
if (fileData) { if (fileData) {
const symbolId = `image-${fileData.id}`; const cropHash = hashString(JSON.stringify(element.crop));
const symbolId = `image-${fileData.id}-${cropHash}`;
let symbol = svgRoot.querySelector(`#${symbolId}`); let symbol = svgRoot.querySelector(`#${symbolId}`);
if (!symbol) { if (!symbol) {
symbol = svgRoot.ownerDocument!.createElementNS(SVG_NS, "symbol"); symbol = svgRoot.ownerDocument!.createElementNS(SVG_NS, "symbol");
@ -424,17 +425,17 @@ const renderElementToSvg = (
if (element.crop) { if (element.crop) {
const { width: uncroppedWidth, height: uncroppedHeight } = const { width: uncroppedWidth, height: uncroppedHeight } =
getUncroppedWidthAndHeight(element); getUncroppedWidthAndHeight(element);
symbol.setAttribute(
"viewBox",
`${
element.crop.x / (element.crop.naturalWidth / uncroppedWidth)
} ${
element.crop.y / (element.crop.naturalHeight / uncroppedHeight)
} ${width} ${height}`,
);
image.setAttribute("width", `${uncroppedWidth}`); image.setAttribute("width", `${uncroppedWidth}`);
image.setAttribute("height", `${uncroppedHeight}`); image.setAttribute("height", `${uncroppedHeight}`);
image.setAttribute(
"transform",
`translate(${
-element.crop.x / (element.crop.naturalWidth / uncroppedWidth)
} ${
-element.crop.y / (element.crop.naturalHeight / uncroppedHeight)
})`,
);
} else { } else {
image.setAttribute("width", "100%"); image.setAttribute("width", "100%");
image.setAttribute("height", "100%"); image.setAttribute("height", "100%");

File diff suppressed because one or more lines are too long