fabricjs / fabric.js

Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser
http://fabricjs.com
Other
29.2k stars 3.52k forks source link

[Bug]: Problem with updating Textbox width when resize the textbox object. #9814

Open niketaOptimumnbrew opened 7 months ago

niketaOptimumnbrew commented 7 months ago

CheckList

Version

5.3.0

In What environments are you experiencing the problem?

Firefox, Chrome

Node Version (if applicable)

14.20.0

Link To Reproduction

http://fabricjs.com/kitchensink

Steps To Reproduce

  1. Add below code to execute section of fabric.js demo which is linked above.
  2. canvas.add(new fabric.Textbox("Hello World",{ left: 10, top: 10, fontFamily: 'Roboto-Regular', angle: 0, fontSize:37, width:200, splitByGrapheme: true, }));
  3. resize the textbox width using middle-right control from right to left.
  4. when mouse cursor move from right to left using middle right control then object width behave unexpected, it increase the width instead of decrease the width.

Expected Behavior

Actual Behavior

Error Message & Stack Trace

Can you please tell me that why it's happening and what is the correct solution for that?
asturur commented 7 months ago

ok that is weird, could be interaction with scale flipping, i don't remember seeing that before. Does it happen also in v6.x?

Try to change the value of lockScalingFlip between either true and false and see if it avoids that?

niketaOptimumnbrew commented 7 months ago

@asturur I have tried lockScalingFlip with true and false value , but it's not working.

mhieupham1 commented 4 months ago

function changeWidth(eventData, transform, x, y) { var target = transform.target, localPoint = getLocalPoint(transform, transform.originX, transform.originY, x, y), strokePadding = target.strokeWidth / (target.strokeUniform ? target.scaleX : 1), multiplier = isTransformCentered(transform) ? 2 : 1, oldWidth = target.width, //before //newWidth = Math.abs(localPoint.x * multiplier / target.scaleX) - strokePadding; //after newWidth = localPoint.x * multiplier / target.scaleX - strokePadding; target.set('width', Math.max(newWidth, 0)); return oldWidth !== newWidth; } I see the localPoint.x becomes negative when dragging the mouse from right to left. Math.abs makes it positive, and obj increase the width See example: https://jsfiddle.net/mhieupham/wgser7xv/5/