Fit the Canvas object to the canvas width or height

function fitToScale()
        {
            activeObject = canvas.getActiveObject();
            if (activeObject.width >= activeObject.height) {
                expectedScaleX = (canvas.width - 20) / activeObject.width;
                proportion = expectedScaleX / activeObject.scaleX;
                activeObject.scaleX = expectedScaleX;
                activeObject.scaleY = activeObject.scaleY * proportion;
                horizontal_center_object();
            }
            else {
                expectedScaleY = (canvas.height - 20) / activeObject.height;
                proportion = expectedScaleY / activeObject.scaleY;

                activeObject.scaleY = expectedScaleY;
                activeObject.scaleX = activeObject.scaleX * proportion;
                vertical_center_object();
            }
            canvas.renderAll();
        }

Popular posts from this blog

[Solved] Hive installation error: java.net.URISyntaxException: Relative path in absolute URI

Install Android SDK in centOs

Installing arules package (Association Rules) in R