Bug 423802

Summary: SVG file opens empty if defs structure element is not before structure element that references it.
Product: [Applications] krita Reporter: steampoweredtaco
Component: File formatsAssignee: Dmitry Kazakov <dimula73>
Status: ASSIGNED ---    
Severity: normal CC: dimula73, halla
Priority: NOR    
Version First Reported In: 4.2.9   
Target Milestone: ---   
Platform: Other   
OS: Other   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Simple svg that reproduces the issue
This file is a working version of repoBroken where the def and g elements are swapped

Description steampoweredtaco 2020-07-02 17:06:51 UTC
Created attachment 129847 [details]
Simple svg that reproduces the issue

SUMMARY
Loading an SVG file that has a <defs> structure statement after another same level structure element, such as <g>, results in a broken import. Funny enough, the preview of recently open files will show the image just fine.

These files work in Inkscape and the newest browsers just fine.

Via the SVG spec these structure elements may be defined in any order at the same level which is typical of most xml schema and specs based off them.  The Krita parser probably needs to do two separate passes of the DOM to work correctly.

STEPS TO REPRODUCE
1. Open this fairly minimal reproduction 'repoBroken.svg' in Krita

OBSERVED RESULT
Notice no image is visible

EXPECTED RESULT
An image of two eye like shapes are visible.

SOFTWARE/OS VERSIONS
Windows: 10 64bit
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: Not sure

ADDITIONAL INFORMATION
If you edit the repoBroken.svg and move the <def> element above <g>, save, then open in Krita the expected result of an image of two eye like objects show up.

Attached is repoBroken.svg.
Comment 1 steampoweredtaco 2020-07-02 17:08:34 UTC
Created attachment 129848 [details]
This file is a working version of repoBroken where the def and g elements are swapped

repoBroken.svg is the broken version and repoWorking.svg is the version where I moved the <defs /> element above the <g /> element on the same level that does load in Krita.
Comment 2 Halla Rempt 2020-07-03 08:39:46 UTC
The preview is handled by Qt's svg support, while loading the file is done with our own svg parser. Thanks for the test file, I can reproduce the issue.