Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Path) Issue 8852 fix a bug in path parsing #8853

Merged
merged 10 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [next]

- fix(Path, Obect) Fix path parsing edge case for zeroed arc command and for too small canvas patterns [#8853](https://github.com/fabricjs/fabric.js/pull/8853)

## [6.0.0-beta3]

- chore(TS): Path type fixes [#8842](https://github.com/fabricjs/fabric.js/pull/8842)
- fix(TS): add types to some untyped empty arrays [#8830](https://github.com/fabricjs/fabric.js/pull/8830)
- chore(TS): Complete typings for toObject/fromObject [#8756](https://github.com/fabricjs/fabric.js/pull/8756)
Expand Down
6 changes: 4 additions & 2 deletions src/shapes/Object/Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,8 +1238,10 @@ export class FabricObject<
retinaScaling = this.getCanvasRetinaScaling(),
width = dims.x / this.scaleX / retinaScaling,
height = dims.y / this.scaleY / retinaScaling;
pCanvas.width = width;
pCanvas.height = height;
// in case width and height are less than 1px, we have to round up.
// since the pattern is no-repeat, this is fine
pCanvas.width = Math.ceil(width);
pCanvas.height = Math.ceil(height);
const pCtx = pCanvas.getContext('2d');
if (!pCtx) {
return;
Expand Down
3 changes: 3 additions & 0 deletions src/util/path/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ const arcToSegments = (
sweep: number,
rotateX: TRadian
): TParsedAbsoluteCubicCurveCommand[] => {
if (rx === 0 || ry === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I understand...
What does rx/ry stand for in arc?

return [];
}
let fromX = 0,
fromY = 0,
root = 0;
Expand Down
5 changes: 5 additions & 0 deletions test/unit/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,9 @@
done();
});
});

QUnit.test('can parse arcs with rx and ry set to 0', function(assert) {
var path = new fabric.Path('M62.87543,168.19448H78.75166a0,0,0,0,1,0,0v1.9884a6.394,6.394,0,0,1-6.394,6.394H69.26939a6.394,6.394,0,0,1-6.394-6.394v-1.9884A0,0,0,0,1,62.87543,168.19448Z');
assert.equal(path.path.length, 9);
});
})();
800 changes: 800 additions & 0 deletions test/visual/assets/accordion.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions test/visual/assets/light-bulb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/visual/golden/accordion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/visual/golden/light-bulb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/visual/svg_import.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
'177',
'polygons',
'polygons-rounded',
'light-bulb',
'accordion',
].map(createTestFromSVG);

tests.forEach(visualTestLoop(QUnit));
Expand Down