示例#1
0
        private SvgVoLayer ToSvg(Layer layer)
        {
            var svgLayer = new SvgVoLayer();

            svgLayer.ID      = layer.UniqueId;
            svgLayer.Display = layer.Visible ? Display.Inline : Display.None;

            var customAttrs = svgLayer.CustomAttributes;

            if (layer.Locked)
            {
                customAttrs.Add(new SvgVoAttribute("locked", layer.Locked));
            }

            if (!string.IsNullOrEmpty(layer.Name))
            {
                customAttrs.Add(new SvgVoAttribute("name", layer.Name));
            }

            if (layer.Region != null)
            {
                customAttrs.Add(new SvgVoAttribute("region", _serializer.Serialize(layer.Region)));
            }

            foreach (var vObject in layer.VObjects)
            {
                var svg = ToSvg(vObject);
                if (svg != null)
                {
                    svgLayer.ChildNodes.Add(svg);
                }
            }

            return(svgLayer);
        }
示例#2
0
        private Layer FromSvg(SvgVoLayer svgLayer)
        {
            var layer = new Layer();

            layer.UniqueId = svgLayer.ID;
            layer.Visible  = svgLayer.Display != Display.None;

            foreach (var attr in svgLayer.CustomAttributes)
            {
                if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "locked")
                {
                    layer.Locked = attr.GetValue() == "true";
                }

                if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "name")
                {
                    layer.Name = attr.GetValue();
                }

                if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "region")
                {
                    layer.Region = _serializer.Deserialize <RectangleF?>(attr.GetValue());
                }
            }

            foreach (var childSvgNode in svgLayer.ChildNodes)
            {
                var vObject = FromSvg(childSvgNode as SvgElement);
                if (vObject != null)
                {
                    layer.VObjects.Add(vObject);
                }
            }

            return(layer);
        }