godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
86.56k stars 19.28k forks source link

SVG: element must be defined before reference #90712

Open hansi-c opened 2 months ago

hansi-c commented 2 months ago

Tested versions

System information

Godot v4.3.dev5 - Manjaro Linux #1 SMP PREEMPT_DYNAMIC Fri Mar 1 18:09:53 UTC 2024 - X11 - GLES3 (Compatibility) - AMD Radeon Graphics (radeonsi, renoir, LLVM 16.0.6, DRM 3.49, 6.1.80-1-MANJARO) () - AMD Ryzen 7 PRO 4750U with Radeon Graphics (16 Threads)

Issue description

In SVG we can reference another element like this: <use href="#spade"/>. Godot's SVG parser requires the element with id="spade" to occur before the reference.

I don't think this is allowed by the specification. At least, other image viewers render the image properly.

Steps to reproduce

  1. In the SVG, the <defs> section has an element use11 that references another element spade.
  2. The element spade is defined later in the document.
  3. Import the SVG -> the referenced element is not shown.
  4. Modify the SVG by moving the definition of 'spade' before the reference.
  5. Re-import the SVG -> the referenced element shows.

The files are found in the minimal reproduction project below.

I used Inkscape to export individual playing cards from this bigger file: https://commons.wikimedia.org/wiki/File:Contemporary_playing_cards.svg

Minimal reproduction project (MRP)

SVGbug.zip

AThousandShips commented 2 months ago

I don't think this is allowed by the specification.

Do you mean it is allowed? Can you please confirm that in this case, just because it works in some implementations doesn't mean it's part of the specification

hansi-c commented 2 months ago

I'm not an expert on SVG, but reading through this: https://www.w3.org/TR/SVG11/struct.html#UseElement, I have not found anything that imposes order on the elements.

AThousandShips commented 2 months ago

None of the examples there do it in the other order so I'd say it's safe to assume it's not guaranteed, so I'd say the first step is to find that it is before proceeding

But in either case this is out of our hands, you should discuss this at ThorVG as we're just using it for our SVGs