Skip to content

Commit

Permalink
[shapes-merge] Fix merge of CImageShape
Browse files Browse the repository at this point in the history
- include copy of blipFill with recalculated srcRect in result
  • Loading branch information
belozertsev committed Dec 11, 2024
1 parent 42ffab2 commit 3e977fe
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions common/Drawings/CommonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11377,12 +11377,14 @@
let resultShapes;
if (operation === 'divide') {
const resultPathsArray = AscCommon.PathBoolean.CompoundPath.prototype.divide(compoundPathLst);
resultShapes = resultPathsArray.map(createShapeByCompoundPath);
resultShapes = resultPathsArray.map(function (path) {
return createShapeByCompoundPath(path, selectedShapes[0]);
});
} else {
const resultPath = compoundPathLst.reduce(function (resultPath, currentPath) {
return resultPath[operation](currentPath);
});
resultShapes = [createShapeByCompoundPath(resultPath)];
resultShapes = [createShapeByCompoundPath(resultPath, selectedShapes[0])];
}

if (Asc.editor.isDocumentEditor) return de_replaceShapes(selectedShapes, resultShapes);
Expand Down Expand Up @@ -11480,18 +11482,46 @@
return formatPath;
}

function createShapeByCompoundPath(compoundPath /* compoundPath can be either Path or CompoundPath */) {
function createShapeByCompoundPath(compoundPath /* compoundPath can be either Path or CompoundPath */, referenceShape) {
const supportedConstructors = [AscFormat.CShape, AscFormat.CImageShape];
const constructor = supportedConstructors.indexOf(referenceShape.constructor) === -1
? supportedConstructors[0]
: referenceShape.constructor;

const compoundPathBounds = compoundPath.getBounds();
const formatPath = convertCompoundPathToFormatPath(compoundPath);
const pathLst = [formatPath];

const resultGeometry = new AscFormat.Geometry();
pathLst.forEach(function (path) {
resultGeometry.AddPath(path);
})
});

const resultShape = new AscFormat.CShape();
const resultShape = new constructor();
resultShape.setBDeleted(false);

if (AscCommon.isRealObject(referenceShape.blipFill)) {
const blipFill = referenceShape.blipFill.createDuplicate();

const refX = referenceShape.bounds.x;
const refY = referenceShape.bounds.y;
const refW = referenceShape.bounds.w;
const refH = referenceShape.bounds.h;
const resX = compoundPathBounds.x;
const resY = compoundPathBounds.y;
const resW = compoundPathBounds.width;
const resH = compoundPathBounds.height;

blipFill.srcRect = {
l: 100 * (resX - refX) / refW,
t: 100 * (resY - refY) / refH,
r: 100 * (resX + resW - refX) / refW,
b: 100 * (resY + resH - refY) / refH,
};

resultShape.setBlipFill(blipFill);
}

resultShape.setSpPr(new AscFormat.CSpPr());
resultShape.spPr.setParent(resultShape);
resultShape.spPr.setXfrm(new AscFormat.CXfrm());
Expand Down

0 comments on commit 3e977fe

Please sign in to comment.