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

DRAFT: SVG export and isPath removal #9488

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
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]

- DRAFT: SVG export and isPath removal [#9488](https://github.com/fabricjs/fabric.js/pull/9488)
- chore(): remove some Type assertions [#8950](https://github.com/fabricjs/fabric.js/pull/8950)
- chore(): expose `sendVectorToPlane` [#9479](https://github.com/fabricjs/fabric.js/pull/9479)
- BREAKING: remove absolute true/false from the api. [#9395](https://github.com/fabricjs/fabric.js/pull/9395)
Expand Down
5 changes: 2 additions & 3 deletions src/gradient/Gradient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
SVGOptions,
} from './typedefs';
import { classRegistry } from '../ClassRegistry';
import { isPath } from '../util/typeAssertions';

/**
* Gradient class
Expand Down Expand Up @@ -199,8 +198,8 @@ export class Gradient<
offsetX += object.width / 2;
offsetY += object.height / 2;
}
// todo what about polygon/polyline?
if (isPath(object) && this.gradientUnits !== 'percentage') {

if (object.pathOffset && this.gradientUnits !== 'percentage') {
offsetX -= object.pathOffset.x;
offsetY -= object.pathOffset.y;
}
Expand Down
7 changes: 0 additions & 7 deletions src/util/typeAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { TFiller } from '../typedefs';
import type { FabricText } from '../shapes/Text/Text';
import type { Pattern } from '../Pattern';
import type { ActiveSelection } from '../shapes/ActiveSelection';
import type { Path } from '../shapes/Path';

export const isFiller = (
filler: TFiller | string | null
Expand Down Expand Up @@ -38,9 +37,3 @@ export const isTextObject = (
// @todo discuss what to do and how to do
return !!fabricObject && fabricObject.isType('Text', 'IText', 'Textbox');
};

export const isPath = (fabricObject?: FabricObject): fabricObject is Path => {
// we could use instanceof but that would mean pulling in Text code for a simple check
// @todo discuss what to do and how to do
return !!fabricObject && fabricObject.isType('Path');
};
35 changes: 35 additions & 0 deletions test/visual/assets/svg_linear_8_gradient_offset.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/multipleGradientsOffset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/visual/svg_import.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
'light-bulb',
'accordion',
'car',
'svg_linear_8_gradient_offset',
].map(createTestFromSVG);

tests.forEach(visualTestLoop(QUnit));
Expand Down
16 changes: 16 additions & 0 deletions test/visual/z_svg_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,22 @@
height: 760,
});

function multipleGradientsOffset(canvas, callback) {
fabric.loadSVGFromURL(getAssetName('svg_linear_8_gradient_offset')).then(({ objects }) => {
canvas.add(...objects);
toSVGCanvas(canvas, callback);
});
}

tests.push({
test: 'Multiple gradients import for offset',
code: multipleGradientsOffset,
golden: 'multipleGradientsOffset.png',
percentage: 0.06,
width: 450,
height: 470,
});

function pathWithGradientSvg(canvas, callback) {
var pathWithGradient = new fabric.Path('M 0 0 L 0 100 L 100 100 L 100 0 Z', {
fill: new fabric.Gradient({
Expand Down