Unable to maintain thickness of strokeWidth while resizing in case of Groups in Fabricjs

五迷三道 提交于 2019-12-06 12:19:08

this approach will not work for all kind of shapes. when facing text or polygons you cannot recalculate everything.

you can do something like that:

fabric.Object.prototype.resizeToScale = function () {
  if  (this.type !=='group') {
    this.strokeWidth = this._origStrokeWidth / Math.max(this.scaleX, this.scaleY);
  }
  else {
    this._objects.forEach( function(obj){
      console.log(obj);
      obj.strokeWidth = obj._origStrokeWidth / Math.max(obj.group.scaleX, obj.group.scaleY);
    });
  }
}

if you prefer the effect of your solution (border is always uniform) put this line of code in the default case of your switch construct to handle all the types for wich you cannot find a resizing solution.

edit i added group handling. The point is to make smaller strokewidth when the group / object scale. Because when you will have polygons and polylines and paths, changing width / height /radius will not help.

http://jsfiddle.net/y344vs5s/4/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!