Skip to content

Commit

Permalink
fix: 修复圆形裁切调整上下左右缩放成椭圆时,取消选择回复圆的问题 (ikuaitu#426)
Browse files Browse the repository at this point in the history
Co-authored-by: weicheng.liang <weicheng.liang@tuodi.cn>
  • Loading branch information
ByeWord and weicheng.liang authored Jun 7, 2024
1 parent aa4325e commit 6c32372
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/core/plugin/SimpleClipImagePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,25 @@ const createRectClip = (activeObject: fabric.Object, inverted: boolean) => {
const createCircleClip = (activeObject: fabric.Object, inverted: boolean) => {
const point = activeObject.getCenterPoint();
const { width } = getBounds(activeObject);
const shell = new fabric.Circle({
const shell = new fabric.Ellipse({
fill: 'rgba(0,0,0,0)',
originX: 'center',
originY: 'center',
left: point.x,
top: point.y,
radius: width / 2,
rx: width / 4,
ry: width / 4,
});
bindInfo(shell, activeObject);
const clipPath = new fabric.Circle({
const clipPath = new fabric.Ellipse({
absolutePositioned: true,
originX: 'center',
originY: 'center',
left: shell.left,
top: shell.top,
radius: width / 2,
inverted: inverted,
rx: shell.rx,
ry: shell.ry,
});
return { shell, clipPath };
};
Expand Down Expand Up @@ -159,8 +161,8 @@ export default class SimpleClipImagePlugin {
activeObject.set('dirty', true);
});
shell.on('deselected', () => {
if (clipPath instanceof fabric.Circle) {
clipPath.set({ radius: (shell as fabric.Circle).getRadiusX() });
if (clipPath instanceof fabric.Ellipse && shell instanceof fabric.Ellipse) {
clipPath.set({ rx: shell.getRx(), ry: shell.getRy() });
} else {
clipPath.set({
width: shell.getScaledWidth(),
Expand Down

0 comments on commit 6c32372

Please sign in to comment.