Browse Source

Moved namespace declarations to root

flabbet 7 months ago
parent
commit
9458cedea0

+ 1 - 1
src/PixiEditor.SVG/Elements/SvgImage.cs

@@ -12,7 +12,7 @@ public class SvgImage : SvgElement
     public SvgProperty<SvgNumericUnit> Width { get; } = new("width");
     public SvgProperty<SvgNumericUnit> Height { get; } = new("height");
         
-    public SvgProperty<SvgStringUnit> Href { get; } = new("href", "xlink", "http://www.w3.org/1999/xlink");
+    public SvgProperty<SvgStringUnit> Href { get; } = new("href", "xlink");
     public SvgProperty<SvgLinkUnit> Mask { get; } = new("mask");
     public SvgProperty<SvgEnumUnit<SvgImageRenderingType>> ImageRendering { get; } = new("image-rendering");
 

+ 3 - 3
src/PixiEditor.SVG/SvgDocument.cs

@@ -61,12 +61,12 @@ public class SvgDocument : SvgElement, IElementContainer, ITransformable, IFilla
 
         Dictionary<string, string> usedNamespaces = new();
 
-        /*GatherRequiredNamespaces(usedNamespaces, Children);
+        GatherRequiredNamespaces(usedNamespaces, Children);
 
         foreach (var usedNamespace in usedNamespaces)
         {
-            document.Root.Add(XNamespace.Xmlns + usedNamespace.Key, usedNamespace.Value);
-        }*/
+            document.Root.Add(new XAttribute(XNamespace.Xmlns + usedNamespace.Key, usedNamespace.Value));
+        }
 
         AppendProperties(document.Root);
 

+ 4 - 7
src/PixiEditor.SVG/SvgElement.cs

@@ -25,12 +25,9 @@ public class SvgElement(string tagName)
                 SvgProperty prop = (SvgProperty)property.GetValue(this);
                 if (prop?.Unit != null)
                 {
-                    if (!string.IsNullOrEmpty(prop.NamespaceName) && !string.IsNullOrEmpty(prop.NamespaceUri))
+                    if (!string.IsNullOrEmpty(prop.NamespaceName))
                     {
-                        XAttribute nsAttribute = new XAttribute(XNamespace.Xmlns + prop.NamespaceName, prop.NamespaceUri);
-                        element.Add(nsAttribute);
-                        
-                        XName name = XNamespace.Get(prop.NamespaceUri) + prop.SvgName;
+                        XName name = XNamespace.Get(RequiredNamespaces[prop.NamespaceName]) + prop.SvgName;
                         element.Add(new XAttribute(name, prop.Unit.ToXml()));
                     }
                     else
@@ -48,7 +45,7 @@ public class SvgElement(string tagName)
                 element.Add(child.ToXml(nameSpace));
             }
         }
-        
+
         return element;
     }
 
@@ -83,7 +80,7 @@ public class SvgElement(string tagName)
             property.Unit.ValuesFromXml(reader.Value);
         }
     }
-    
+
     private void ParseListProperty(SvgList list, XmlReader reader)
     {
         list.Unit ??= CreateDefaultUnit(list);

+ 2 - 4
src/PixiEditor.SVG/SvgProperty.cs

@@ -10,14 +10,12 @@ public abstract class SvgProperty
         SvgName = svgName;
     }
     
-    protected SvgProperty(string svgName, string? namespaceName, string? namespaceUri) : this(svgName)
+    protected SvgProperty(string svgName, string? namespaceName) : this(svgName)
     {
         NamespaceName = namespaceName;
-        NamespaceUri = namespaceUri;
     }
 
     public string? NamespaceName { get; set; }
-    public string? NamespaceUri { get; set; }
     public string SvgName { get; set; }
     public ISvgUnit? Unit { get; set; }
 }
@@ -34,7 +32,7 @@ public class SvgProperty<T> : SvgProperty where T : struct, ISvgUnit
     {
     }
     
-    public SvgProperty(string svgName, string? namespaceName, string? namespaceUri) : base(svgName, namespaceName, namespaceUri)
+    public SvgProperty(string svgName, string? namespaceName) : base(svgName, namespaceName)
     {
     }
 }