Search code examples
javascripthtml5-canvasfabricjs

What does the scaleToWidth 'ignore viewport' flag do?


I'm using scaleToWidth and it works but I'm not seeing any difference if I set the ignore viewport flag to true or false. I've tested this with content that is larger and smaller than the canvas. Does this concern a zoomed or otherwise transformed canvas rather than the canvas boundaries?

Can someone explain, please?

enter image description here


Solution

  • Viewport refers to the canvas zoom.

    The scaleToWidth() method scales the object with respect to the current zoom level so that running obj.scaleToWidth(100) while the canvas zoom is at 1.2 will actually make the object appear with a width of 120.

    I believe the absolute flag is there primarily for internal use as part of the zooming logic since passing a value of true will actually multiply the object's size by the canvas's zoom value again which isn't particularly useful.