[英]Textbox enable scaleY
I'm creating a custom class that extends Textbox and It needs to have y scale enabled. 我正在创建一个扩展Textbox的自定义类,并且需要启用y缩放。 It's y scale must have the same behavior as x scale to just change the element width/height not the fontSize.
它的y缩放必须具有与x缩放相同的行为,才能更改元素的宽度/高度而不是fontSize。
But I have already checked the whole Textbox's code and can't find what to override to have this behavior. 但是我已经检查了整个Textbox的代码,无法找到要覆盖此行为的内容。
Here is some code of what I'm doing: 这是我在做什么的一些代码:
https://fiddle.jshell.net/filiperoberto/zLz6cy2L/3/ https://fiddle.jshell.net/filiperoberto/zLz6cy2L/3/
I found a function at textbox_behavior.mixin.js in fabricjs that changes textbox scale behavior, I extended that function on my custom element to have the expected behavior. 我在fabricjs的textbox_behavior.mixin.js上找到了一个可更改文本框缩放行为的函数,我在自定义元素上扩展了该函数以具有预期的行为。
*Still needs some work *还需要一些工作
(function(){
var setObjectScaleOverridden = fabric.Canvas.prototype._setObjectScale;
fabric.Canvas.prototype._setObjectScale = function(localMouse, transform,lockScalingX, lockScalingY, by, lockScalingFlip, _dim) {
var t = transform.target;
if (t instanceof fabric.FeedText) {
var w = t.width * ((localMouse.x / transform.scaleX) / (t.width + t.strokeWidth));
var h = t.height * ((localMouse.y / transform.scaleY) / (t.height + t.strokeWidth));
if (w >= t.getMinWidth() && h >= t.minHeight) {
t.set('width', w);
t.set('height',h);
return true;
}
}
else {
return setObjectScaleOverridden.call(fabric.Canvas.prototype, localMouse, transform,
lockScalingX, lockScalingY, by, lockScalingFlip, _dim);
}
};
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.