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(Object): support specyfing toCanvasElement canvas #9652

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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]

- fix(Object): support specyfing toCanvasElement canvas [#9652](https://github.com/fabricjs/fabric.js/pull/9652)
- fix(textStyles): Split text into graphemes correctly [#9646](https://github.com/fabricjs/fabric.js/pull/9646)
- fix(ActiveSelection): static default inheritance [#9635](https://github.com/fabricjs/fabric.js/pull/9635)
- fix(StaticCanvas): StaticCanvas setDimensions typings [#9618](https://github.com/fabricjs/fabric.js/pull/9618)
Expand Down
17 changes: 11 additions & 6 deletions src/shapes/Object/Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,7 @@ export class FabricObject<
* @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
* @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
* @param {Boolean} [options.viewportTransform] Account for canvas viewport transform
* @param {(el: HTMLCanvasElement) => Canvas} [options.canvasProvider] Create the output canvas
* @return {HTMLCanvasElement} Returns DOM element <canvas> with the FabricObject
*/
toCanvasElement(options: any = {}) {
Expand All @@ -1366,7 +1367,15 @@ export class FabricObject<
originalShadow = this.shadow,
abs = Math.abs,
retinaScaling = options.enableRetinaScaling ? getDevicePixelRatio() : 1,
multiplier = (options.multiplier || 1) * retinaScaling;
multiplier = (options.multiplier || 1) * retinaScaling,
canvasProvider: (el: HTMLCanvasElement) => StaticCanvas =
options.canvasProvider ||
((el: HTMLCanvasElement) =>
new StaticCanvas(el, {
enableRetinaScaling: false,
renderOnAddRemove: false,
skipOffscreen: false,
}));
delete this.group;
if (options.withoutTransform) {
resetObjectTransform(this);
Expand Down Expand Up @@ -1401,11 +1410,7 @@ export class FabricObject<
// we need to make it so.
el.width = Math.ceil(width);
el.height = Math.ceil(height);
const canvas = new StaticCanvas(el, {
enableRetinaScaling: false,
renderOnAddRemove: false,
skipOffscreen: false,
});
const canvas = canvasProvider(el);
if (options.format === 'jpeg') {
canvas.backgroundColor = '#fff';
}
Expand Down
Loading