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

Lost information after reading Svg #1170

Open
benberlin7 opened this issue Dec 16, 2024 · 7 comments
Open

Lost information after reading Svg #1170

benberlin7 opened this issue Dec 16, 2024 · 7 comments

Comments

@benberlin7
Copy link

Description

When I read a SVG with your library in Debug or Release mode from within Visual Studio everything works fine.
However after building an installation and trying it without Visual Studio some SVG data gets lost.
The input SVG is exactly the same. The elements read from that via
SvgDocument.Open(svgFilePath);
or
SvgDocument.FromSvg<SvgDocument>(File.ReadAllText(svgPath));
don't represent all the information of the SVG.

Below you can see some examples (example data). It's just the beginning of the document to show you the problem.
[A] is the SvgContent read via SvgNet in Visual Studio (Debug or Release), plotted via svgDoc.GetXML(). [B] is the exact same Svg Input read from the installation. As you can see the transforms, width, height, stroke-width and x,y values are missing.
I already checked the following:

  • both refer to the exact same Svg.DLL
  • both work on the same .NET Framework 4.8 (v4.0.30319).
  • the input SVGs are exactly the same
  • System.Drawing is in the same version
  • copied all missing DLLs from Visual Studio to the installation folder just to make sure it's not a forgotten reference
  • both have the same culture + ui-culture settings

If I read the elements in the installation via XmlDocument and log the InnerXML to a textfile the transforms etc. are displayed correctly.

I have no clue what I am missing or doing wrong.

Example data

[A] SVG Content read in Visual Studio (DEBUG or RELEASE)


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xml="http://www.w3.org/XML/1998/namespace" width="1122.52" height="793.7008" viewBox="0, 0, 1122.52, 793.7008">
  <rect x="37.79527" y="75.59055" width="1046.929" height="680.3149" stroke-width="1.322835" fill-opacity="0" style="fill:white;stroke:black;" />
  <g transform="translate(404.4094, 604.7244)">
    <g>
      <rect x="0" y="0" width="170.0787" height="37.79527" stroke-width="1.322835" fill-opacity="0" stroke-opacity="0" style="fill:white;stroke:white;" />
      <text transform="translate(3.779528, 5.889764) translate(2, 0) translate(0, 3)" text-anchor="start" font-family="Segoe UI" font-size="10" style="dominant-baseline:hanging;fill:black;">TestText</text>
    </g>
(...)

[B] the same SVG Content read from the installation

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xml="http://www.w3.org/XML/1998/namespace" viewBox="0, 0, 1122.52, 793.7008">
  <rect fill-opacity="0" style="fill:white;stroke:black;" />
  <g>
    <g>
      <rect x="0" y="0" fill-opacity="0" stroke-opacity="0" style="fill:white;stroke:white;" />
      <text text-anchor="start" font-family="Segoe UI" font-size="10" style="dominant-baseline:hanging;fill:black;">TestText</text>
    </g>
(...)

Used Versions

NET Framework 4.8
SVG.net Version 3.4.7
Win 11
Visual Studio 2022 Professional.

@benberlin7
Copy link
Author

@mrbean-bremen still looking for help... :(

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Dec 19, 2024

Sorry, I'm long out of this... still looking for a new maintainer (see #1111). Maybe @H1Gdev has an idea.

@H1Gdev
Copy link
Contributor

H1Gdev commented Dec 21, 2024

I've never had this issue before, so I don't think I'll be able to find the cause right away...

  • Does this issue occur with certain SVG elements ?
  • Does this issue occur with older versions of SVG lib ?

@benberlin7
Copy link
Author

benberlin7 commented Dec 23, 2024

Hey @H1Gdev

Does this issue occur with older versions of SVG lib ?

I tried SVG.NET 3.4.0 and 3.4.7. Both had the same issue.

Does this issue occur with certain SVG elements ?

I think all elements which have these attributes (width, height, transforms,...) are faulty. Some are correctly represented like polygon and path, but they don't use these attributes at all. Heres an analysis from ChatGPT about the differences in 2 SVGs (1 correct from VisualStudio, 1 faulty from the installation):

The analysis shows that in the faulty file (File 2), the following elements and attributes are missing or incorrectly translated:
Missing Elements and Attributes in File 2:

SVG Element:
    Attributes missing:
        width="1122.52"
        height="793.7008"

Rectangles (<rect>):
    A rectangle with the following attributes is missing:
        x="37.79527", y="75.59055", width="1046.929", height="680.3149", stroke-width="1.322835", style="fill:#FFFFFF;stroke:#000000;".

Groups (<g>):
    A group with transform="translate(404.4094, 604.7244)" is missing.

Text Elements (<text>):
    Missing transformations and style details:
        Example: transform="translate(3.779528,5.889764) translate(2, 0) translate(0, 3)".

Lines and Other Transformations:
    Precise transformation attributes and styles are absent.

Additional or Divergent Elements in File 2:

SVG Element:
    The width and height attributes are completely missing, but viewBox is present.

Rectangles (<rect>):
    Divergent style definitions:
        Instead of fill:#FFFFFF;stroke:#000000;, it uses fill:white;stroke:black;.

Text Elements (<text>):
    Simplified or reduced styles:
        Original: Includes dominant-baseline, transform, font-family, font-size.
        Faulty: Only includes style="dominant-baseline:hanging;fill:black;".

Summary:

File 2 omits many details and attributes, especially:
    width and height in the <svg> element.
    Precise transform attributes in <g> and <text>.
    Detailed style definitions for <rect> and <text> elements.

@benberlin7
Copy link
Author

benberlin7 commented Dec 23, 2024

Today I tried passing a XMLReader with different settings

		var settings = new XmlReaderSettings
		               {
			               DtdProcessing = DtdProcessing.Parse, 
			               XmlResolver = new XmlUrlResolver(),  
			               ValidationType = ValidationType.Auto, 
			               IgnoreWhitespace = true,           
			               IgnoreComments = true,             
			               IgnoreProcessingInstructions = true 
		};

		
		XmlReader reader = XmlReader.Create(svgFilePath, settings);
		SvgDocument svgDoc = SvgDocument.Open<SvgDocument>(reader);
		CanvasHeight = svgDoc.Height;

I also tried

			               DtdProcessing = DtdProcessing.Parse,  
			               XmlResolver = new XmlUrlResolver(),   
			               ValidationType = ValidationType.None, 
			               IgnoreWhitespace = false,         
			               IgnoreComments = false,          
			               IgnoreProcessingInstructions = false

Unfortunately it did not help. But maybe it rules out sth. for you so I wanted to share this info @H1Gdev

@benberlin7
Copy link
Author

solved it : it was the missing System.Numerics.Vectors.Dll in the installation folder.

@benberlin7
Copy link
Author

but there is still some mystery behind. It works with the System.Numerics.Vectors.Dll now. But if I paste all DLLs in an older installation (I created several with different options, some can seen above) it still doesn't work. I don't have the ambition to investigate it any longer, because it works now and I already spent way too much time for this issue, but if this happens again to someone else :
The way it works now : Open it with a distinct reader

	var settings = new XmlReaderSettings
		               {
			               DtdProcessing = DtdProcessing.Parse, 
			               XmlResolver = new XmlUrlResolver(),  
			               ValidationType = ValidationType.Auto, 
			               IgnoreWhitespace = true,           
			               IgnoreComments = true,             
			               IgnoreProcessingInstructions = true 
		};

		
		XmlReader reader = XmlReader.Create(svgFilePath, settings);
		SvgDocument svgDoc = SvgDocument.Open<SvgDocument>(reader);
		CanvasHeight = svgDoc.Height;

Then make sure that System.Vectors.Dll is in your installation folder.

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

No branches or pull requests

3 participants