You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
4.6.0 and above [Tried till the latest version of fabric js]
Problem
I want to set the scaleToWidth of a textbox to some value say n. But when it seems not to be correct, its behavior is random sometimes n+1, n+2 or n+3.
var canvas = this.__canvas = new fabric.Canvas('c');
var size = 200;
var color = "#ff0000";
var fontScale = 1;
console.log("size to be "+size);
var opt = {
fill: color,
stroke: color,
scaleX: fontScale,
scaleY: fontScale,
fontFamily: "Times New Roman",
fontSize: 40,
fontWeight: "",
fontStyle: "",
textAlign: "center"
}
var textObject = new fabric.Text("Hello", opt);
canvas.add(textObject);
textObject.setCoords(); // @asturur suggested this in the below mention github issue
textObject.scaleToWidth(size);
canvas.renderAll();
console.log("new size after render "+textObject.getScaledWidth());
The above code results in:
"size to be 200"
"new size after render 202.25054945054944" // I am expecting this value to be 200 not 202.25054945054944.
Version
4.6.0 and above [Tried till the latest version of fabric js]
Problem
I want to set the scaleToWidth of a textbox to some value say
n
. But when it seems not to be correct, its behavior is random sometimesn+1
,n+2
orn+3
.What did I try?
http://jsfiddle.net/7zjueqgm/12/
Some code:
The above code results in:
"size to be 200"
"new size after render 202.25054945054944" // I am expecting this value to be
200
not202.25054945054944
.Issue related to?
#3719
https://stackoverflow.com/questions/69900924/fabric-js-scaletowidth-not-working-for-text-items-and-resulting-in-different-wid
Any help is highly appreciated.
The text was updated successfully, but these errors were encountered: