Wednesday, 30 January 2019

How to get Text object font-size after modifying object

How can I get Text object font size after modifying object in fabric.js?

Below is my code.

var text = new fabric.Text(imgText, {
  left: 10,
  top: 5,
  fontSize: 15,
  fontFamily: 'Verdana',
  fill: 'white'
});
text.scaleToWidth(canvas.width * 0.5);
text.setControlsVisibility(canvasConfig);
canvas.add(text);
canvas.renderAll();
var objects = canvas.getActiveObject();

var obj = objects;
if (!obj) {
  return;
}
//console.log(obj.get('fontSize') *= obj.scaleX); 
var angle = obj.get('angle');

var objWidth = obj.get('width') * obj.scaleX;
var objWidthPercent = objWidth / canvas.width * 100;

var objHeight = obj.get('height') * obj.scaleY;
var objHeightPercent = objHeight / canvas.height * 100;

var bound = obj.getBoundingRect();
var objLeft = obj.get('left') / canvas.width * 100;
var objTop = obj.get('top') / canvas.height * 100;

Above I set default FontSize to 15. then I modify object I can get proper Height, Width, Left, Top, but I am not able to get FontSize.



from How to get Text object font-size after modifying object

No comments:

Post a Comment