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 svg base markup #2364

Merged
merged 1 commit into from
Aug 9, 2015
Merged

Fix svg base markup #2364

merged 1 commit into from
Aug 9, 2015

Conversation

asturur
Copy link
Member

@asturur asturur commented Jul 27, 2015

Side effects to be checked:

Group class does not export svgStyles, so it will not have shadow in any case. ( special svg style method required to output fewer properties).

Image class export svg style twice, ( for image and rect border) side effects to be checked with shadow and with other properties.

Pathgroup class should be ok.

Also i noticed that all classes exports:
svgTransform + svgTrasnformMatrix
while pathgroup exports:
svgTransformMatrix + svgTransform

closes #2363
closes #2390 ( should be separated PR but would conflict with this)

@asturur
Copy link
Member Author

asturur commented Jul 27, 2015

/cc: @MohamedElamry

@asturur
Copy link
Member Author

asturur commented Aug 8, 2015

@kangax i noticed that group class does not take in account shadow, while pathgroup does.
Is this an intended behaviour?

@asturur
Copy link
Member Author

asturur commented Aug 8, 2015

canvas:
image

this is the export result:
image

This is the result svg

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="700" height="600" xml:space="preserve">
<desc>Created with Fabric.js 1.5.0</desc>
<defs></defs>
<filter id="SVGID_6" y="-45%" height="190%" x="-45%" width="190%" >
    <feGaussianBlur in="SourceAlpha" stdDeviation="5"></feGaussianBlur>
    <feOffset dx="10" dy="10" result="oBlur" ></feOffset>
    <feFlood flood-color="rgba(0,0,0,0.3)"/>
    <feComposite in2="oBlur" operator="in" />
    <feMerge>
        <feMergeNode></feMergeNode>
        <feMergeNode in="SourceGraphic"></feMergeNode>
    </feMerge>
</filter>
<g transform="translate(206.5 209.5) scale(5 5)" style="filter: url(#SVGID_6);">
    <rect x="-25" y="-25" rx="0" ry="0" width="50" height="50" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(255,0,0); fill-rule: nonzero; opacity: 1;" transform="translate(-15 -15)"/>
    <circle cx="0" cy="0" r="40" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,255,0); fill-rule: nonzero; opacity: 1;" transform="translate(0 0) "/>
</g>
<filter id="SVGID_7" y="-22%" height="144%" x="-23%" width="146%" >
    <feGaussianBlur in="SourceAlpha" stdDeviation="5"></feGaussianBlur>
    <feOffset dx="10" dy="10" result="oBlur" ></feOffset>
    <feFlood flood-color="rgba(0,0,0,0.3)"/>
    <feComposite in2="oBlur" operator="in" />
    <feMerge>
        <feMergeNode></feMergeNode>
        <feMergeNode in="SourceGraphic"></feMergeNode>
    </feMerge>
</filter>
<g transform="translate(554.4 198.6) scale(0.34 0.34)">
<image xlink:href="file:///C:/web/fab/pug.jpg" x="-384" y="-512" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;filter: url(#SVGID_7);" width="768" height="1024" preserveAspectRatio="none"></image>
</g>
<filter id="SVGID_8" y="-41%" height="182%" x="-32%" width="164%" >
    <feGaussianBlur in="SourceAlpha" stdDeviation="5"></feGaussianBlur>
    <feOffset dx="10" dy="10" result="oBlur" ></feOffset>
    <feFlood flood-color="rgba(0,0,0,0.3)"/>
    <feComposite in2="oBlur" operator="in" />
    <feMerge>
        <feMergeNode></feMergeNode>
        <feMergeNode in="SourceGraphic"></feMergeNode>
    </feMerge>
</filter>
<g style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;filter: url(#SVGID_8);" transform="translate(304 456)" >
<path d="M 9.87 47.9 c 0.35 0 0.25 0.11 0.45 0.48 C 10.03 48.51 9.8 48.1 9.87 47.9 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 102.61 15.02 c 0.36 0.06 0.18 0.43 0.04 0.62 C 102.41 15.59 102.66 15.21 102.61 15.02 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 66.13 28.45 c 0.32 -0.05 0.09 0.26 0.29 0.54 C 66.05 28.94 66.03 28.74 66.13 28.45 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 66.69 30.26 c -0.05 0.29 -0.26 0.2 -0.54 0.29 C 66.12 30.21 66.43 30.18 66.69 30.26 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 69.5 34 c -0.23 0.25 -0.29 0.04 -0.54 0.01 C 68.97 33.76 69.44 33.6 69.5 34 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 117.55 17.14 c 0.46 0.05 -0.17 0.48 -0.09 0.77 c -0.06 0.04 -0.09 0 -0.11 -0.05 c -0.01 -0.07 -0.06 -0.06 -0.11 -0.05 C 117.29 17.56 117.48 17.38 117.55 17.14 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 48.88 42.25 c 0.07 0.22 0.19 0.11 0.12 0.32 c -0.16 0.18 -0.37 -0.23 -0.35 0.03 C 48.34 42.57 48.77 42.32 48.88 42.25 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 117.16 18.1 c 0.15 0.19 0.53 -0.09 0.58 0.34 c -0.35 0.27 -0.39 -0.13 -0.65 -0.04 c -0.01 -0.07 0.05 -0.11 0.02 -0.19 C 117.18 18.2 117.17 18.15 117.16 18.1 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 102.97 24.13 c 0.16 -0.06 0.32 -0.12 0.49 -0.18 c -0.18 0.16 -0.17 0.41 -0.45 0.53 C 103.04 24.39 103.03 24.27 102.97 24.13 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 152.88 6.6 c 0.03 0.15 -0.07 0.23 -0.26 0.28 c -0.03 -0.08 -0.06 -0.16 -0.09 -0.24 C 152.68 6.54 152.76 6.61 152.88 6.6 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 9.27 58.91 c 0.01 -0.36 0.46 0.22 0.43 -0.06 c 0.16 0 0.12 0.17 -0.02 0.19 c 0.04 0.11 0.08 0.21 0.12 0.32 c -0.14 -0.04 -0.33 0.03 -0.46 -0.02 c -0.01 -0.26 0.09 -0.13 0.29 -0.2 C 9.51 59.07 9.44 58.87 9.27 58.91 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 119.31 20.25 c 0.01 -0.41 -0.11 -0.46 0.09 -0.76 C 119.48 19.66 119.68 20.06 119.31 20.25 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 11.41 58.78 c 0 0.11 -0.04 0.2 -0.19 0.25 c 0.01 0.07 0.06 0.07 0.11 0.05 C 11.14 59.49 10.98 58.47 11.41 58.78 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 117.28 20.71 c 0.31 -0.05 0.25 0.34 0.18 0.49 C 117.17 21.18 117.44 20.89 117.28 20.71 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 71.07 38.1 c 0.21 -0.17 0.21 0.13 0.28 0.27 c -0.16 0.1 -0.23 0.02 -0.35 0.04 C 71.01 38.3 71.15 38.25 71.07 38.1 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 123.61 20.26 c -0.29 -0.2 -0.26 -0.31 -0.31 -0.62 c 0.11 -0.04 0.21 -0.08 0.32 -0.12 C 123.8 20.08 123.5 19.94 123.61 20.26 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 12.1 63.74 c 0.26 -0.13 0.33 0.15 0.52 0.18 c 0.09 0.18 -0.2 0.18 -0.15 0.33 C 12.19 64.23 12.33 64 12.1 63.74 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 13.09 63.93 c 0.09 0.42 -0.35 0.5 -0.61 0.59 C 12.56 64.27 12.84 64.11 13.09 63.93 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 89.21 36.68 c 0.05 0.16 -0.18 0.18 -0.05 0.38 c -0.14 -0.14 -0.44 0.08 -0.52 -0.18 C 88.93 36.93 88.9 36.57 89.21 36.68 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 12.57 65.04 c 0.14 -0.06 0.21 0.04 0.35 -0.04 c 0 0.13 -0.05 0.25 -0.04 0.38 C 12.59 65.37 12.78 65.23 12.57 65.04 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 45.62 53.49 c -0.02 -0.1 0.12 -0.12 0.21 -0.17 c -0.01 0.23 0.03 0.3 0.2 0.57 C 45.6 53.94 45.71 53.51 45.62 53.49 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 90.37 37.36 c 0.21 0.07 0.37 0.08 0.43 -0.06 c 0.26 0.17 0.21 0.66 0.29 0.81 C 90.74 37.85 90.5 37.83 90.37 37.36 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 92.46 37.34 c 0.2 0.01 0.33 0.15 0.42 0.4 C 92.68 37.71 92.37 37.55 92.46 37.34 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 52.66 52.23 c -0.23 0.15 -0.2 -0.24 -0.46 -0.01 C 52.13 51.94 52.64 51.88 52.66 52.23 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 46.02 54.35 c 0.22 0.01 0.51 0.66 0.24 0.92 c -0.16 -0.38 -0.01 -0.61 -0.45 -0.48 C 45.81 54.61 46.21 54.62 46.02 54.35 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 89.14 39.54 c 0.31 -0.21 0.54 0.45 0.18 0.49 C 89.31 39.74 89.26 39.84 89.14 39.54 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 105.46 33.84 c 0.27 -0.08 0.38 0.46 0.09 0.51 C 105.5 34.02 105.45 34.06 105.46 33.84 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 46.27 55.54 c 0.13 0 0.25 0.04 0.38 0.04 c -0.04 0.09 -0.02 0.21 0.04 0.35 c -0.08 0.03 -0.16 0.06 -0.24 0.09 C 46.46 55.57 46.24 56.08 46.27 55.54 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 13.53 67.43 c 0.22 -0.07 0.46 0.04 0.36 0.24 C 13.68 67.77 13.58 67.65 13.53 67.43 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
<path d="M 105.19 34.85 c -0.23 0.29 -0.03 0.38 -0.2 0.71 C 104.79 35.49 104.79 34.66 105.19 34.85 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
.... deleted some....
<path d="M 119.62 56.89 c -0.15 0.23 0.18 0.26 0.09 0.51 c -0.37 0.2 -0.43 -0.14 -0.52 -0.18 c -0.02 -0.1 0.12 -0.12 0.21 -0.17 c -0.1 -0.15 -0.3 -0.07 -0.2 -0.29 c -0.05 0.07 -0.1 0.13 -0.21 0.17 c -0.03 -0.15 0.07 -0.24 0.26 -0.28 c -0.27 -0.24 0.11 -0.39 -0.1 -0.79 c 0.56 -0.22 0.33 0.36 0.82 0.25 c -0.35 0.17 -0.37 0.5 -0.11 0.96 C 119.71 57.18 119.68 57.02 119.62 56.89 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: evenodd; opacity: 1;" transform=" matrix(1 0 0 1 0.09 0.77) " stroke-linecap="round" />
</g>
</svg>

This PR would require some new tests and lot of test corrections because i added tabs and newlines to have pretty svg output.
So please before i start to fix all the tests, tell me if you agree with this:

added to base Svg markup adding to svg export
moved filter shadow to separate function
used this function to export shadow for normal groups
group class got shadow rendering for entire group ( it did have not before ).

@@ -266,6 +266,7 @@
ctx.transform.apply(ctx, this.transformMatrix);
}
this.transform(ctx);
this._setShadow(ctx);
Copy link
Member Author

Choose a reason for hiding this comment

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

Added shadow rendering for whole group.

@asturur
Copy link
Member Author

asturur commented Aug 8, 2015

In current kitchensink we get just this:

image

because image and pathgroup fail the rendering after the export.

@asturur
Copy link
Member Author

asturur commented Aug 8, 2015

Added fix for #2390

@@ -207,9 +206,14 @@
* @return {Boolean} true if all paths are of the same color (`fill`)
*/
isSameColor: function() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed this function, but i'm more for deleting it or improve the patGroup._set method that as of now is useless.
(it checks if all the paths are same color and if yes it change all the paths filling, some sort of ancient delegated properties that as of now feels unfinished work).

Copy link
Member

Choose a reason for hiding this comment

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

I agree that it's an ancient method that is hardly useful

//jscs:disable validateIndentation
'<g ',
'transform="', this.getSvgTransform(),
var markup = this._createBaseSVGMarkup();
Copy link
Member

Choose a reason for hiding this comment

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

Since we're using createBaseSVGMarkup everywhere, perhaps we should just do it in fabric.Object#toSVG and then inherit method via callSuper.

kangax added a commit that referenced this pull request Aug 9, 2015
@kangax kangax merged commit 0715f15 into fabricjs:master Aug 9, 2015
@kangax
Copy link
Member

kangax commented Aug 9, 2015

+changelog

@asturur asturur deleted the fix-svgBaseMarkup branch August 9, 2015 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can fabricJS read SVG files with Linear Gradient? missing svg shadow description for pathGroups (toSVG)
2 participants