导出印花等所有信息

This commit is contained in:
李志鹏
2026-01-06 14:17:04 +08:00
parent 73aca07391
commit 466d278b29
12 changed files with 301 additions and 111 deletions

View File

@@ -919,6 +919,26 @@ export function calculateRotatedTopLeftDeg(
return { x: newX, y: newY };
}
/**
* 根据左上角坐标计算中心点坐标
* @param {number} W - 宽度
* @param {number} H - 高度
* @param {number} currentX - 当前左上角x坐标
* @param {number} currentY - 当前左上角y坐标
* @param {number} currentAngleDeg - 当前角度(度)
* @returns {Object} 中心点坐标 {x, y}
*/
export function calculateCenterPoint(W, H, currentX, currentY, currentAngleDeg) {
const currentAngle = (currentAngleDeg * Math.PI) / 180;
const cosCurrent = Math.cos(currentAngle);
const sinCurrent = Math.sin(currentAngle);
const Cx = currentX + (W / 2) * cosCurrent - (H / 2) * sinCurrent;
const Cy = currentY + (W / 2) * sinCurrent + (H / 2) * cosCurrent;
return { x: Cx, y: Cy };
}
/**
* 创建缩放+旋转的变换矩阵
* @param {number} scale - 缩放比例

View File

@@ -211,6 +211,7 @@ export function simplifyLayers(layers) {
fill: layer?.fill || null,
fillColor: layer.fillColor,
selectObject: layer.selectObject,
blendMode: layer.blendMode || null,
};
return simplifiedLayer;

View File

@@ -1,6 +1,6 @@
// 栅格化帮助
import { fabric } from "fabric-with-all";
import { SpecialLayerId } from "./layerHelper";
/**
* 创建栅格化图像 - 重构版本
* 采用复制原对象+裁剪路径的方式,保持原始质量和准确位置
@@ -691,6 +691,16 @@ const cloneObjectAsync = (obj) => {
return new Promise((resolve, reject) => {
obj.clone((cloned) => {
if (cloned) {
cloned.set({
scaleX: obj.scaleX,
scaleY: obj.scaleY,
top: obj.top,
left: obj.left,
width: obj.width,
height: obj.height,
zoomX: obj.zoomX,
zoomY: obj.zoomY,
})
resolve(cloned);
} else {
reject(new Error("对象克隆失败"));
@@ -845,9 +855,8 @@ const renderContentToImage = async ({
});
// 克隆并添加所有需要渲染的对象
for (const obj of fabricObjects) {
const clonedObj = await cloneObjectAsync(obj);
for (let obj of fabricObjects) {
let clonedObj = await cloneObjectAsync(obj);
// 调整对象位置:将选区左上角作为新的原点(0,0)
clonedObj.set({
left: (clonedObj.left - selectionBounds.left) * qualityMultiplier,
@@ -859,19 +868,19 @@ const renderContentToImage = async ({
});
// 如果有裁剪路径,也需要调整裁剪路径
if (clonedObj.clipPath) {
if (clonedObj.clipPath && obj.id !== SpecialLayerId.COLOR) {
clonedObj.clipPath.set({
left:
(clonedObj.clipPath.left - selectionBounds.left) *
qualityMultiplier,
top:
(clonedObj.clipPath.top - selectionBounds.top) * qualityMultiplier,
left: (clonedObj.clipPath.left - selectionBounds.left) * qualityMultiplier,
top: (clonedObj.clipPath.top - selectionBounds.top) * qualityMultiplier,
scaleX: (clonedObj.clipPath.scaleX || 1) * qualityMultiplier,
scaleY: (clonedObj.clipPath.scaleY || 1) * qualityMultiplier,
});
clonedObj.clipPath.setCoords(); // 更新裁剪路径坐标
}
// if(obj.globalCompositeOperation === "multiply"){
// clonedObj.clipPath = null;
// }
console.log("==========", obj.id, obj.layerName);
contentCanvas.add(clonedObj);
}