fabricjs / fabric.js

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

[Feature]: Cloned Rect Object with border , shadow not showing #9974

Open RathodAnnu13 opened 4 months ago

RathodAnnu13 commented 4 months ago

CheckList

Description

I am adding a shadow to a rect with a border on a canvas using the following code. setBasicShadow(color, blur, x, y, isButton: boolean = false, valueType, keyName, KeyType, isSlider: boolean = false) { console.log(color,blur,x,y); this.shadowType = '8'; this.props.shadowColor = color; this.canvas.getActiveObject().set({ shadow: { affectStroke: false, color: color, blur: blur, offsetX: x, offsetY: y } }); this.canvas.getActiveObject().set({ objectCaching: true, statefullCache: true }) this.canvas.renderAll(); }

Now clone object and add on canvas :

`activeObject.clone(cloned => {
                    clone = cloned;
                    clone.set({
                        objectCaching: false

}) });`

Using above code shadow not showing to cloned Object.


Using below code , shadow is showing but on rect fill area.

activeObject.clone(cloned => { clone = cloned; clone.set({ objectCaching: false, shadow: new latestFabric.fabric.Shadow({ color: activeObject.shadow.color, blur: activeObject.shadow.blur, offsetX: activeObject.shadow.offsetX, offsetY: activeObject.shadow.offsetY, affectStroke: true, }) }) });

Current State

Shadow bring on rect, not behind it. image image2

cloned object should same as original Object.

Additional Context

No response

asturur commented 4 months ago

Can you make a reproducible example in a jsfiddle or something similar? thanks.