Ejemplo n.º 1
0
        public static XElement ToXml(LineStyleEx lineStyle)
        {
            var res = new XElement("LineStyle",
                                   new XAttribute("width", lineStyle.Width),
                                   new XAttribute("startCapStyle", (byte)lineStyle.StartCapStyle),
                                   new XAttribute("jointStyle", (byte)lineStyle.JoinStyle),
                                   new XAttribute("hasFill", lineStyle.HasFill ? "1" : "0"),
                                   new XAttribute("noHScale", lineStyle.NoHScale ? "1" : "0"),
                                   new XAttribute("noVScale", lineStyle.NoVScale ? "1" : "0"),
                                   new XAttribute("pixelHinting", lineStyle.PixelHinting ? "1" : "0"),
                                   new XAttribute("noClose", lineStyle.NoClose ? "1" : "0"),
                                   new XAttribute("endCapStyle", (byte)lineStyle.EndCapStyle)
                                   );

            if (lineStyle.Reserved != 0)
            {
                res.Add(new XAttribute("reserved", lineStyle.Reserved));
            }
            if (lineStyle.JoinStyle == JoinStyle.Miter)
            {
                res.Add(new XAttribute("miterFactor", CommonFormatter.Format(lineStyle.MilterLimitFactor)));
            }
            if (lineStyle.HasFill)
            {
                res.Add(new XElement("fillStyle", XFillStyle.ToXml(lineStyle.FillStyle)));
            }
            else
            {
                res.Add(new XElement("fillColor", XColorRGBA.ToXml(lineStyle.Color)));
            }
            return(res);
        }
Ejemplo n.º 2
0
        public static void FromXml(XElement xStyleList, IList <FillStyleRGB> fillStyles, IList <LineStyleRGB> lineStyles)
        {
            var xFillStyles = xStyleList.RequiredElement("fillStyles");

            foreach (var xFillStyle in xFillStyles.Elements())
            {
                var fillStyle = XFillStyle.FromXmlRGB(xFillStyle);
                fillStyles.Add(fillStyle);
            }

            var xLineStyles = xStyleList.RequiredElement("lineStyles");

            foreach (var xLineStyle in xLineStyles.Elements())
            {
                var lineStyle = XLineStyleRGB.FromXml(xLineStyle);
                lineStyles.Add(lineStyle);
            }
        }
Ejemplo n.º 3
0
        public static LineStyleEx FromXml(XElement xLineStyle)
        {
            var xStartCapStyle = xLineStyle.Attribute("startCapStyle");
            var xJointStyle    = xLineStyle.Attribute("jointStyle");
            var xEndCapStyle   = xLineStyle.Attribute("endCapStyle");

            var xReserved = xLineStyle.Attribute("reserved");

            var res = new LineStyleEx {
                Width         = xLineStyle.RequiredUShortAttribute("width"),
                StartCapStyle = (CapStyle)byte.Parse(xStartCapStyle.Value),
                JoinStyle     = (JoinStyle)byte.Parse(xJointStyle.Value),
                HasFill       = xLineStyle.RequiredBoolAttribute("hasFill"),
                NoHScale      = xLineStyle.RequiredBoolAttribute("noHScale"),
                NoVScale      = xLineStyle.RequiredBoolAttribute("noVScale"),
                PixelHinting  = xLineStyle.RequiredBoolAttribute("pixelHinting"),
                NoClose       = xLineStyle.RequiredBoolAttribute("noClose"),
                EndCapStyle   = (CapStyle)byte.Parse(xEndCapStyle.Value)
            };

            if (xReserved != null)
            {
                res.Reserved = byte.Parse(xReserved.Value);
            }

            if (res.JoinStyle == JoinStyle.Miter)
            {
                res.MilterLimitFactor = xLineStyle.RequiredDoubleAttribute("miterFactor");
            }

            var xFillStyle = xLineStyle.Element("fillStyle");
            var xFillColor = xLineStyle.Element("fillColor");

            if (xFillStyle != null)
            {
                res.FillStyle = XFillStyle.FromXmlRGBA(xFillStyle.Elements().First());
            }
            if (xFillColor != null)
            {
                res.Color = XColorRGBA.FromXml(xFillColor.Elements().First());
            }
            return(res);
        }
Ejemplo n.º 4
0
        public static XElement ToXml(IList <FillStyleRGB> fillStyles, IList <LineStyleRGB> lineStyles)
        {
            var xStyleList = new XElement("StyleList");

            var xFillStyles = new XElement("fillStyles");

            xStyleList.Add(xFillStyles);

            var xLineStyles = new XElement("lineStyles");

            xStyleList.Add(xLineStyles);

            foreach (var fillStyle in fillStyles)
            {
                xFillStyles.Add(XFillStyle.ToXml(fillStyle));
            }
            foreach (var lineStyle in lineStyles)
            {
                xLineStyles.Add(XLineStyleRGB.ToXml(lineStyle));
            }

            return(xStyleList);
        }