managed-commons / SvgNet

Fork of the SVG library for .NET that makes a GdiGraphics that "draws" on a SVG model
BSD 3-Clause "New" or "Revised" License
84 stars 37 forks source link

SvgNet produces invalid decimal seperator in German culture #1

Closed housemysedar closed 12 years ago

housemysedar commented 12 years ago

SvgNet generates the comma "," instead of the dot "." if used in German culture. E.g. Inkscape won't understand this and show misplaced elements.

The fix is quite simple: In Types.cs, line 232

replace string s = _num.ToString();

with string s = _num.ToString(System.Globalization.CultureInfo.InvariantCulture);

This should work for any country.

housemysedar commented 12 years ago

I found some more compatibility issues: Single.ToString() sometimes produces a scientific representation which not all tools seems to understand. So the following conversion is even better:

.ToString("F", System.Globalization.CultureInfo.InvariantCulture);

There are probably some more places where the ToString() conversion should be adapted, e.g. SvgTransformList.cs, line 167.

It seems that InkScape does not process compressed attributes correctly. So I'd suggest to replace SvgGraphics.cs, line 184: return _root.WriteSVGString(true); with return _root.WriteSVGString(false);

monoman commented 12 years ago

Fixed most ToString() applied to floats, but some places apply to object in hashtables and thus may fail if the object contained is a float.

oli-arborum commented 7 years ago
  1. A missing culture parameter was found in SvgTypes.SvgPath.ToString() where d.ForString() for a float variable is called.

  2. Regarding the hashtables that may contain floats I propose the following code for the first foreach loop in SvgElement.WriteXmlElements():

            if (_atts[s] is float)
            {
                me.SetAttribute(s, doc.NamespaceURI, ((float)_atts[s]).ToString(System.Globalization.CultureInfo.InvariantCulture));
            }
            else if (_atts[s] is double)
            {
                me.SetAttribute(s, doc.NamespaceURI, ((double)_atts[s]).ToString(System.Globalization.CultureInfo.InvariantCulture));
            }
            else
            {
                me.SetAttribute(s, doc.NamespaceURI, _atts[s].ToString());
            }
monoman commented 7 years ago

Published new nuget with last fixes: https://www.nuget.org/packages/SvgNet/1.0.1