Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codesandbox/templates/vanilla/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fabric from 'fabric';
import './styles.css';
import { testCase } from './testcases/nestedSelections';
import { testCase } from './testcases/flippedInteractive';

const el = document.getElementById('canvas');
const canvas = (window.canvas = new fabric.Canvas(el));
Expand Down
69 changes: 69 additions & 0 deletions .codesandbox/templates/vanilla/src/testcases/flippedInteractive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as fabric from 'fabric';

export function testCase(canvas: fabric.Canvas, objectCaching = true) {
function renderNamedControl(
this: fabric.Control,
ctx: CanvasRenderingContext2D,
left: number,
top: number,
styleOverride: any,
fabricObject: fabric.FabricObject
) {
ctx.save();
ctx.font = '12px Arial';
ctx.fillStyle = 'black';
ctx.fillText(this.name || '??', left - 12, top - 3);
ctx.restore();
}

canvas.preserveObjectStacking = true;
const rect = new fabric.Rect({
left: 100,
top: 50,
width: 100,
height: 100,
flipX: false,
fill: 'blue',
padding: 20,
});

const controls = rect.controls;

Object.entries(controls).forEach(([key, control]) => {
control.name = key;
control.render = renderNamedControl;
});

const rect2 = new fabric.Rect({
top: 200,
width: 50,
height: 50,
fill: 'red',
flipX: true,
opacity: 1,
controls,
padding: 20,
});

const g = new fabric.Group([rect], {
subTargetCheck: true,
interactive: true,
objectCaching,
skewX: 0,
angle: 90,
flipY: true,
controls,
});
const g2 = new fabric.Group([rect2], {
top: 100,
left: 100,
subTargetCheck: true,
interactive: true,
objectCaching,
angle: 0,
flipY: false,
controls,
});
canvas.add(g);
canvas.add(g2);
}
9 changes: 7 additions & 2 deletions src/shapes/Object/InteractiveObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,13 @@ export class InteractiveFabricObject<
]),
transformOptions = this.group
? qrDecompose(this.calcTransformMatrix())
: undefined,
dim = this._calculateCurrentDimensions(transformOptions),
: undefined;
// decomposing could bring negative scaling and `_calculateCurrentDimensions` can't take it
if (transformOptions) {
transformOptions.scaleX = Math.abs(transformOptions.scaleX);
transformOptions.scaleY = Math.abs(transformOptions.scaleY);
}
const dim = this._calculateCurrentDimensions(transformOptions),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having _getTransformedDimensions returning always absolute numbers could be the more correct solution but i don't want to shake that now for an edge case fix.
There could be something that is relying on the case of negative dimensions.
having this.scaleX or this.scaleY negative is not supported in general and this is the only place where we use the options for calcDimensions with unchecked values

coords: Record<string, TOCoord> = {};

this.forEachControl((control, key) => {
Expand Down
3 changes: 3 additions & 0 deletions src/shapes/Object/ObjectOrigin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export class ObjectOrigin<EventSpec>
*/
_getTransformedDimensions(options: any = {}): Point {
const dimOptions = {
// if scaleX or scaleY are negative numbers,
// this will return dimensions that are negative.
// and this will break assumptions around the codebase
scaleX: this.scaleX,
scaleY: this.scaleY,
skewX: this.skewX,
Expand Down