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

Support Focal property in Radial Gradient #1558

Closed
hermet opened this issue Jul 30, 2023 · 7 comments
Closed

Support Focal property in Radial Gradient #1558

hermet opened this issue Jul 30, 2023 · 7 comments
Assignees
Labels
feature New feature additions
Milestone

Comments

@hermet
Copy link
Member

hermet commented Jul 30, 2023

The Radial Gradient lacks the "focal" property, which is commonly utilized in vector formats. It's necessary to provide support for this property.

#1555

@hermet hermet added the feature New feature additions label Jul 30, 2023
@mgrudzinska
Copy link
Collaborator

@reptofrog
regarding the example: it would be great if you provide some samples svgs that you have in mind.
I tried to reconstruct your sample:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
  <defs>
    <radialGradient id="radialGradient3f" r="50" cx="100" cy="100" 
      fr="0" fx="65" fy="65"
      gradientUnits="userSpaceOnUse">
      <stop style="stop-color:#ff00ff;stop-opacity:1;" offset="0"/>
      <stop style="stop-color:#00ff00;stop-opacity:1;" offset="1"/>
    </radialGradient>
  </defs>

  <circle cx="100" cy="100" r="50" fill="url(#radialGradient3f)"/>
</svg>

result:
Zrzut ekranu 2023-08-7 o 21 22 54

but on your screen the focal point is outside the circle, right? or does inkskape prevent such cases?

the focal support is reachable, but I'm no so sure about all of the corner cases...

@mgrudzinska mgrudzinska self-assigned this Aug 7, 2023
@mgrudzinska
Copy link
Collaborator

I found the answer to my previous comment - the behavior may be as I guessed if inkskape supports svg1.1, this was changed in svg2: https://www.w3.org/TR/SVG2/pservers.html#RadialGradientNotes

mgrudzinska added a commit to mgrudzinska/thorvg that referenced this issue Aug 7, 2023
Till now only the end circle values of the radial grad
were supported. Now also the start circle values are.
These are the focal point and the radius of the start
circle.
In the svg_loader support for the 'fr' attrib of the radial
grad is added.

@issue: thorvg#1558
mgrudzinska added a commit to mgrudzinska/thorvg that referenced this issue Aug 7, 2023
Till now only the end circle values of the radial grad
were supported. Now also the start circle values are.
These are the focal point and the radius of the start
circle.
In the svg_loader support for the 'fr' attrib of the radial
grad is added.

@issue: thorvg#1558
mgrudzinska added a commit to mgrudzinska/thorvg that referenced this issue Aug 7, 2023
Till now only the end circle values of the radial grad
were supported. Now also the start circle values are.
These are the focal point and the radius of the start
circle.
In the svg_loader support for the 'fr' attrib of the radial
grad is added.

@issue: thorvg#1558
@hermet hermet added this to the 1.0 milestone Aug 8, 2023
@reptofrog
Copy link

reptofrog commented Aug 8, 2023

@mgrudzinska

Inkscape allows to place the focal point anywhere, there are no limits.


Here is the example file with focal point set to be outside of circle and outside of canvas: https://github.com/thorvg/thorvg/assets/36744029/1c8cf513-2ff1-46c6-b6da-c4ea88b0d7c2

Here is one with focal point set to be outside of circle but inside the canvas: https://github.com/thorvg/thorvg/assets/36744029/7aa9172c-b2ef-40fd-b717-2cb61ec37d41

And finally, an example with focal point both inside the circle and inside the canvas: https://github.com/thorvg/thorvg/assets/36744029/86af735a-979f-4b0f-bba6-9e1cccc95524


It probably doesn't matter if the focal point lies outside of canvas or not, I added that example just in case.

Interestingly, only the last one is displayed properly inside web browsers. (No SVG2 support yet?)

However, none of these are displayed propely inside ThorVG Viewer.

@mgrudzinska
Copy link
Collaborator

@reptofrog thanks for the svgs. could I also ask you to show what results do you expect?
regarding svg2 std if focal lies outside the end circle, a cone is created. It would be much easier to support the svg1.1 std and I wondered, whether you really need a full svg2 support right now.

@reptofrog
Copy link

@mgrudzinska

You can see the expected result here: #1555 (first image, a screenshot from Inkscape)


I reported the bug because I was developing a game with Godot Engine and I noticed that my game's icon I've made (in .svg format) doesn't look the same as it does in Inkscape. I then identified that the focal point is what's not displayed properly.

I figured out that it would be beneficial to other developers if this is fixed in ThorVG, since it's used in Godot.

But as I understand now, a focal point that lies outside the circle is actually a new feature from SVG2, is that correct? It seems that even web browsers can't display such gradients properly yet.


Thank you for working on this issue!

@mgrudzinska
Copy link
Collaborator

@reptofrog thx for clarifications.
looking at #1555, one can deduce that Inkscape supports the SVG 1.1 std.
Back then, it was standardized such that if the focal point was placed outside the end circle (cx, cy, r), it would be interpreted as being on the edge of it. This was changed in the SVG 2.0 std, and now, in such cases, some cones are drawn.
I'll try to finish asap, but still need to take care of the edges (like in svg1.1 for now)

mgrudzinska added a commit to mgrudzinska/thorvg that referenced this issue Aug 14, 2023
Till now only the end circle values of the radial grad
were supported. Now also the start circle values are
interpreted - these are the focal point and the radius
of the start circle.
In the svg_loader support for the 'fr' attrib of the radial
grad is added.

@issue: thorvg#1558
mgrudzinska added a commit to mgrudzinska/thorvg that referenced this issue Aug 14, 2023
Till now only the end circle values of the radial grad
were supported. Now also the start circle values are
interpreted - these are the focal point and the radius
of the start circle.
In the svg_loader support for the 'fr' attrib of the radial
grad is added.

@issue: thorvg#1558
mgrudzinska added a commit to mgrudzinska/thorvg that referenced this issue Aug 14, 2023
Till now only the end circle values of the radial grad
were supported. Now also the start circle values are
interpreted - these are the focal point and the radius
of the start circle.
In the svg_loader support for the 'fr' attrib of the radial
grad is added.

@issue: thorvg#1558
mgrudzinska added a commit to mgrudzinska/thorvg that referenced this issue Aug 14, 2023
Till now only the end circle values of the radial grad
were supported. Now also the start circle values are
interpreted - these are the focal point and the radius
of the start circle.
In the svg_loader support for the 'fr' attrib of the radial
grad is added.

@issue: thorvg#1558
@mgrudzinska
Copy link
Collaborator

mgrudzinska commented Aug 14, 2023

I'm not sure what should happen according the SVG 2, if a part of the starting circle is outside the ending circle, like in the sample below:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
    <defs>
        <radialGradient id="grad" r="50" cx="100" cy="100"
                        fr="26" fx="100" fy="75"
                        spreadMethod="reflect" 
                        gradientUnits="userSpaceOnUse">
            <stop style="stop-color:#ff00ff;stop-opacity:1;" offset="0"/>
            <stop style="stop-color:#0000ff;stop-opacity:1;" offset="0.5"/>
            <stop style="stop-color:#00ff00;stop-opacity:1;" offset="1"/>
        </radialGradient>
    </defs>

    <circle cx="100" cy="100" r="50" fill="url(#grad)"/>
</svg>

but I think, after #1585 is merged we can close this issue as solved and if someone has a sample svg with such a problematic case, we can open a new issue

mgrudzinska added a commit to mgrudzinska/thorvg that referenced this issue Aug 22, 2023
Till now only the end circle values of the radial grad
were supported. Now also the start circle values are
interpreted - these are the focal point and the radius
of the start circle.
In the svg_loader support for the 'fr' attrib of the radial
grad is added.

@issue: thorvg#1558
@hermet hermet modified the milestones: 1.0, 0.11 Sep 4, 2023
@hermet hermet closed this as completed Sep 4, 2023
capnm added a commit to capnm/godot4 that referenced this issue Sep 29, 2023
See https://github.com/thorvg/thorvg/releases/tag/v0.11.0

+ Infrastructure
    Repository folder structure was make it more intuitive and coherent.
        "thorvg/src/lib" -> "thorvg/src/common"
            (providing essential common functionalities
                used internally among the renderer and sub-modules)
        "thorvg/src/lib" -> "thorvg/src/renderer"
            (for vector drawing features)

+ SVG related
    Fix stroke regression thorvg/thorvg#1670
    Support stroke dash offset function thorvg/thorvg#1591 (comment)
    Support Focal property in Radial Gradient thorvg/thorvg#1558
capnm added a commit to capnm/godot4 that referenced this issue Sep 29, 2023
See https://github.com/thorvg/thorvg/releases/tag/v0.11.0

+ Infrastructure
    Repository folder structure was make it more intuitive and coherent.
        "thorvg/src/lib" -> "thorvg/src/common"
            (providing essential common functionalities
                used internally among the renderer and sub-modules)
        "thorvg/src/lib" -> "thorvg/src/renderer"
            (for vector drawing features)

+ SVG related
    Fix stroke regression thorvg/thorvg#1670
    Support stroke dash offset function thorvg/thorvg#1591 (comment)
    Support Focal property in Radial Gradient thorvg/thorvg#1558
capnm added a commit to capnm/godot4 that referenced this issue Sep 29, 2023
See https://github.com/thorvg/thorvg/releases/tag/v0.11.0

+ Infrastructure
    Repository folder structure was make it more intuitive and coherent.
        "thorvg/src/lib" -> "thorvg/src/common"
            (providing essential common functionalities
                used internally among the renderer and sub-modules)
        "thorvg/src/lib" -> "thorvg/src/renderer"
            (for vector drawing features)

+ SVG related
    Fix stroke regression thorvg/thorvg#1670
    Support stroke dash offset function thorvg/thorvg#1591 (comment)
    Support Focal property in Radial Gradient thorvg/thorvg#1558
mandryskowski pushed a commit to mandryskowski/godot that referenced this issue Oct 11, 2023
See https://github.com/thorvg/thorvg/releases/tag/v0.11.0

+ Infrastructure
    Repository folder structure was make it more intuitive and coherent.
        "thorvg/src/lib" -> "thorvg/src/common"
            (providing essential common functionalities
                used internally among the renderer and sub-modules)
        "thorvg/src/lib" -> "thorvg/src/renderer"
            (for vector drawing features)

+ SVG related
    Fix stroke regression thorvg/thorvg#1670
    Support stroke dash offset function thorvg/thorvg#1591 (comment)
    Support Focal property in Radial Gradient thorvg/thorvg#1558
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature additions
Projects
Status: Done 0.11
Development

No branches or pull requests

3 participants