Skip to content

Commit

Permalink
fix(Controls): allow for smooth scaling fo text at any zoom level (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
Soldier-B authored Oct 3, 2024
1 parent 9a7a1d3 commit 557b146
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- fix(Controls): changeWidth can change width with decimals [#10186](https://github.com/fabricjs/fabric.js/pull/10186)
- ci(): Add some prebuilt fabric in the dist folder [#10178](https://github.com/fabricjs/fabric.js/pull/10178)
- chore(): Add more generic font families to FabricText.genericFonts [#10167](https://github.com/fabricjs/fabric.js/pull/10167)

Expand Down
9 changes: 9 additions & 0 deletions src/controls/changeWidth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ describe('changeWidth', () => {
expect(target.top).toBe(0);
});

test('changeWidth changes the width with decimals', () => {
expect(target.width).toBe(100);
const changed = changeWidth(eventData, transform, 200.2, 300);
expect(changed).toBe(true);
expect(target.width).toBe(199.2);
expect(target.left).toBe(0);
expect(target.top).toBe(0);
});

test('changeWidth does not change the width', () => {
const target = new Rect({ width: 100, height: 100, canvas });
jest.spyOn(target, '_set').mockImplementation(function _set(this: Rect) {
Expand Down
7 changes: 3 additions & 4 deletions src/controls/changeWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ export const changeObjectWidth: TransformActionHandler = (
target.strokeWidth / (target.strokeUniform ? target.scaleX : 1),
multiplier = isTransformCentered(transform) ? 2 : 1,
oldWidth = target.width,
newWidth = Math.ceil(
Math.abs((localPoint.x * multiplier) / target.scaleX) - strokePadding,
);
target.set('width', Math.max(newWidth, 0));
newWidth =
Math.abs((localPoint.x * multiplier) / target.scaleX) - strokePadding;
target.set('width', Math.max(newWidth, 1));
// check against actual target width in case `newWidth` was rejected
return oldWidth !== target.width;
}
Expand Down

0 comments on commit 557b146

Please sign in to comment.