Fabric.js: Add support for disabling object flipping when scaling

Created on 14 Jun 2013  路  8Comments  路  Source: fabricjs/fabric.js

I just want to know that can we stop flipping object while scaling object on opposite side in newer version of fabricjs

feature

Most helpful comment

This has been implemented.
Set the property of the object lockScalingFlip to true to prevent flipping during scaling.

All 8 comments

No way to stop it at the moment, but marking as possible feature.

In previous version it was not happening i.e flipping object while scaling.

You might be able to prevent flipping in the _scaleObject method of the canvas as shown below :

// Actually scale the object
      var newScaleX = target.scaleX, newScaleY = target.scaleY;

      if (by === 'equally' && !lockScalingX && !lockScalingY) {
        var dist = localMouse.y + localMouse.x;
        var lastDist = (target.height + (target.strokeWidth)) * t.original.scaleY +
                       (target.width + (target.strokeWidth)) * t.original.scaleX;

        // We use t.scaleX/Y instead of target.scaleX/Y because the object may have a min scale and we'll loose the proportions
        newScaleX = t.original.scaleX * dist/lastDist;
        newScaleY = t.original.scaleY * dist/lastDist;

        // Prevent flipping
        if(newScaleX<0 || newScaleY<0) return;

        target.set('scaleX', newScaleX);
        target.set('scaleY', newScaleY);
      }

Example just shown for an equal scale, but easy to do for a by "x" or by "y" scale then.
Line preventing flipping is :

// Prevent flipping
        if(newScaleX<0 || newScaleY<0) return;

+1 I need this too. Tried, but haven't managed to make it work yet.

Marking as feature.

Has there been any progress on this, or any workaround? This page seems to come up pretty high on Google.

if still interested i have a PR #1572

This has been implemented.
Set the property of the object lockScalingFlip to true to prevent flipping during scaling.

Was this page helpful?
0 / 5 - 0 ratings