Пример #1
0
        public static XElement ToXml(ConvolutionFilter filter)
        {
            var res = new XElement(TAG_NAME,
                                   new XAttribute("divisor", CommonFormatter.Format(filter.Divisor)),
                                   new XAttribute("bias", CommonFormatter.Format(filter.Bias))
                                   );

            var xMatrix = new XElement("matrix");

            for (var y = 0; y < filter.MatrixY; y++)
            {
                var xRow = new XElement("r");
                for (var x = 0; x < filter.MatrixX; x++)
                {
                    var xCol = new XElement("c")
                    {
                        Value = CommonFormatter.Format(filter.Matrix[y, x])
                    };
                    xRow.Add(xCol);
                }
                xMatrix.Add(xRow);
            }
            res.Add(xMatrix);

            res.Add(new XElement("color", XColorRGBA.ToXml(filter.DefaultColor)));
            if (filter.Reserved != 0)
            {
                res.Add(new XAttribute("reserved", filter.Reserved));
            }
            res.Add(new XAttribute("clamp", CommonFormatter.Format(filter.Clamp)));
            res.Add(new XAttribute("preserveAlpha", CommonFormatter.Format(filter.PreserveAlpha)));
            return(res);
        }
Пример #2
0
        public static ConvolutionFilter FromXml(XElement xFilter)
        {
            var xMatrix   = xFilter.RequiredElement("matrix");
            var xReserved = xFilter.Attribute("reserved");

            var filter = new ConvolutionFilter {
                Divisor = xFilter.RequiredDoubleAttribute("divisor"),
                Bias    = xFilter.RequiredDoubleAttribute("bias")
            };

            var xRows  = xMatrix.Elements().ToList();
            var height = xRows.Count;
            var width  = xMatrix.Elements().First().Elements().Count();

            filter.Matrix = new double[height, width];
            for (var y = 0; y < filter.MatrixY; y++)
            {
                var xRow  = xRows[y];
                var xCols = xRow.Elements().ToList();
                for (var x = 0; x < filter.MatrixX; x++)
                {
                    var xCol = xCols[x];
                    filter.Matrix[y, x] = CommonFormatter.ParseDouble(xCol.Value);
                }
            }

            filter.DefaultColor = XColorRGBA.FromXml(xFilter.RequiredElement("color").Element("Color"));
            if (xReserved != null)
            {
                filter.Reserved = byte.Parse(xReserved.Value);
            }
            filter.Clamp         = xFilter.RequiredBoolAttribute("clamp");
            filter.PreserveAlpha = xFilter.RequiredBoolAttribute("preserveAlpha");
            return(filter);
        }
Пример #3
0
        public static XElement ToXml(SolidFillStyleRGBA fillStyle)
        {
            var res = new XElement(SOLID);

            res.Add(new XElement("color", XColorRGBA.ToXml(fillStyle.Color)));
            return(res);
        }
Пример #4
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);
        }
Пример #5
0
 public static XElement ToXml(GradientRecordRGBA record)
 {
     return(new XElement("GradientItem",
                         new XAttribute("position", record.Ratio),
                         new XElement("color", XColorRGBA.ToXml(record.Color))
                         ));
 }
Пример #6
0
        public static SolidFillStyleRGBA FromXmlRGBA(XElement xFillStyle)
        {
            var xColor = xFillStyle.RequiredElement("color").Element("Color");

            return(new SolidFillStyleRGBA {
                Color = XColorRGBA.FromXml(xColor)
            });
        }
Пример #7
0
        public static TextRecordRGBA FromXmlRGBA(XElement element)
        {
            var result = new TextRecordRGBA();

            foreach (var attribute in element.Attributes())
            {
                switch (attribute.Name.LocalName)
                {
                case "objectID":
                    result.FontID = ushort.Parse(attribute.Value);
                    break;

                case "isSetup":
                    result.Type = CommonFormatter.ParseBool(attribute.Value);
                    break;

                case "reserved":
                    result.Reserved = byte.Parse(attribute.Value);
                    break;

                case "x":
                    result.XOffset = short.Parse(attribute.Value);
                    break;

                case "y":
                    result.YOffset = short.Parse(attribute.Value);
                    break;

                case "fontHeight":
                    result.TextHeight = ushort.Parse(attribute.Value);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            foreach (var elem in element.Elements())
            {
                switch (elem.Name.LocalName)
                {
                case "color":
                    var color = XColorRGBA.FromXml(elem.Element("Color"));
                    result.TextColor = color;
                    break;

                case "glyphs":
                    foreach (var glyphElem in elem.Elements())
                    {
                        result.Glyphs.Add(ParseGlyphEntry(glyphElem));
                    }
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            return(result);
        }
Пример #8
0
        public static LineStyleRGBA FromXml(XElement xLineStyle)
        {
            var xColor = xLineStyle.RequiredElement("color").Element("Color");

            return(new LineStyleRGBA {
                Width = xLineStyle.RequiredUShortAttribute("width"),
                Color = XColorRGBA.FromXml(xColor)
            });
        }
Пример #9
0
        public static GradientRecordRGBA FromXml(XElement xRecord)
        {
            var record = new GradientRecordRGBA {
                Ratio = xRecord.RequiredByteAttribute("position"),
                Color = XColorRGBA.FromXml(xRecord.RequiredElement("color").Element("Color"))
            };

            return(record);
        }
Пример #10
0
        protected override void FormatTagElement(DefineEditTextTag tag, XElement xTag)
        {
            xTag.Add(new XElement(SIZE_ELEM, XRect.ToXml(tag.Bounds)));

            xTag.Add(new XAttribute(WORD_WRAP_ATTRIB, SwfMillPrimitives.GetStringValue(tag.WordWrap)));
            xTag.Add(new XAttribute(MULTILINE_ATTRIB, SwfMillPrimitives.GetStringValue(tag.Multiline)));
            xTag.Add(new XAttribute(PASSWORD_ATTRIB, SwfMillPrimitives.GetStringValue(tag.Password)));
            xTag.Add(new XAttribute(READONLY_ATTRIB, SwfMillPrimitives.GetStringValue(tag.ReadOnly)));

            xTag.Add(new XAttribute(AUTOSIZE_ATTRIB, SwfMillPrimitives.GetStringValue(tag.AutoSize)));
            xTag.Add(new XAttribute(HAS_LAYOUT_ATTRIB, CommonFormatter.Format(tag.HasLayout)));
            xTag.Add(new XAttribute(NOT_SELECTABLE_ATTRIB, CommonFormatter.Format(tag.NoSelect)));
            xTag.Add(new XAttribute(BORDER_ATTRIB, CommonFormatter.Format(tag.Border)));
            xTag.Add(new XAttribute("static", CommonFormatter.Format(tag.WasStatic)));
            xTag.Add(new XAttribute(IS_HTML_ATTRIB, CommonFormatter.Format(tag.HTML)));
            xTag.Add(new XAttribute(USE_OUTLINES_ATTRIB, CommonFormatter.Format(tag.UseOutlines)));

            if (tag.HasFont)
            {
                xTag.Add(new XAttribute(FONT_REF_ATTRIB, tag.FontID));
            }
            if (tag.FontClass != null)
            {
                xTag.Add(new XAttribute("fontClass", tag.FontClass));
            }
            if (tag.HasFont)
            {
                xTag.Add(new XAttribute(FONT_HEIGHT_ATTRIB, tag.FontHeight));
            }
            if (tag.TextColor.HasValue)
            {
                xTag.Add(new XElement("color", XColorRGBA.ToXml(tag.TextColor.Value)));
            }
            if (tag.MaxLength.HasValue)
            {
                xTag.Add(new XAttribute(MAX_LENGTH_ATTRIB, tag.MaxLength.Value));
            }
            if (tag.HasLayout)
            {
                xTag.Add(new XAttribute(ALIGN_ATTRIB, tag.Align));
                xTag.Add(new XAttribute(LEFT_MARGIN_ATTRIB, tag.LeftMargin));
                xTag.Add(new XAttribute(RIGHT_MARGIN_ATTRIB, tag.RightMargin));
                xTag.Add(new XAttribute(INDENT_ATTRIB, tag.Indent));
                xTag.Add(new XAttribute(LEADING_ATTRIB, tag.Leading));
            }
            xTag.Add(new XAttribute(VARIABLE_NAME_ATTRIB, tag.VariableName));
            if (tag.InitialText != null)
            {
                xTag.Add(new XAttribute(INITIAL_TEXT_ATTRIB, tag.InitialText));
            }
        }
Пример #11
0
        public static XElement ToXml(GlowFilter filter)
        {
            var res = new XElement(TAG_NAME,
                                   new XAttribute("blurX", CommonFormatter.Format(filter.BlurX)),
                                   new XAttribute("blurY", CommonFormatter.Format(filter.BlurY)),
                                   new XAttribute("innerGlow", CommonFormatter.Format(filter.InnerGlow)),
                                   new XAttribute("knockout", CommonFormatter.Format(filter.Knockout)),
                                   new XAttribute("passes", filter.Passes),
                                   new XAttribute("strength", CommonFormatter.Format(filter.Strength)),
                                   new XElement("color", XColorRGBA.ToXml(filter.Color)),
                                   new XAttribute("compositeSource", CommonFormatter.Format(filter.CompositeSource))
                                   );

            return(res);
        }
Пример #12
0
 public static XElement ToXml(DropShadowFilter filter)
 {
     return(new XElement(TAG_NAME,
                         new XAttribute("angle", CommonFormatter.Format(filter.Angle)),
                         new XAttribute("blurX", CommonFormatter.Format(filter.BlurX)),
                         new XAttribute("blurY", CommonFormatter.Format(filter.BlurY)),
                         new XAttribute("distance", CommonFormatter.Format(filter.Distance)),
                         new XAttribute("innerShadow", CommonFormatter.Format(filter.InnerShadow)),
                         new XAttribute("knockout", CommonFormatter.Format(filter.Knockout)),
                         new XAttribute("compositeSource", CommonFormatter.Format(filter.CompositeSource)),
                         new XAttribute("passes", filter.Passes),
                         new XAttribute("strength", CommonFormatter.Format(filter.Strength)),
                         new XElement("color", XColorRGBA.ToXml(filter.Color))
                         ));
 }
Пример #13
0
        public static GlowFilter FromXml(XElement xFilter)
        {
            var xCompositeSource = xFilter.Attribute("compositeSource");

            var xColor = xFilter.RequiredElement("color").Element("Color");

            return(new GlowFilter {
                BlurX = xFilter.RequiredDoubleAttribute("blurX"),
                BlurY = xFilter.RequiredDoubleAttribute("blurY"),
                InnerGlow = xFilter.RequiredBoolAttribute("innerGlow"),
                Knockout = xFilter.RequiredBoolAttribute("knockout"),
                Passes = xFilter.RequiredUIntAttribute("passes"),
                Strength = xFilter.RequiredDoubleAttribute("strength"),
                CompositeSource = xCompositeSource == null || CommonFormatter.ParseBool(xCompositeSource.Value),
                Color = XColorRGBA.FromXml(xColor)
            });
        }
Пример #14
0
        protected override bool AcceptTagElement(DefineEditTextTag tag, XElement element)
        {
            switch (element.Name.LocalName)
            {
            case SIZE_ELEM:
                tag.Bounds = XRect.FromXml(element.Element("Rectangle"));
                break;

            case COLOR_ELEM:
                tag.TextColor = XColorRGBA.FromXml(element.Element("Color"));
                break;

            default:
                return(false);
            }
            return(true);
        }
Пример #15
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);
        }
Пример #16
0
        public static BevelFilter FromXml(XElement xFilter)
        {
            var xCompositeSource = xFilter.Attribute("compositeSource");

            var xShadowColor    = xFilter.RequiredElement("shadowColor").Element("Color");
            var xHighlightColor = xFilter.RequiredElement("highlightColor").Element("Color");

            return(new BevelFilter {
                Angle = xFilter.RequiredDoubleAttribute("angle"),
                BlurX = xFilter.RequiredDoubleAttribute("blurX"),
                BlurY = xFilter.RequiredDoubleAttribute("blurY"),
                Distance = xFilter.RequiredDoubleAttribute("distance"),
                InnerShadow = xFilter.RequiredBoolAttribute("innerShadow"),
                Knockout = xFilter.RequiredBoolAttribute("knockout"),
                Passes = xFilter.RequiredUIntAttribute("passes"),
                Strength = xFilter.RequiredDoubleAttribute("strength"),
                CompositeSource = xCompositeSource == null || CommonFormatter.ParseBool(xCompositeSource.Value),
                OnTop = xFilter.RequiredBoolAttribute("onTop"),
                ShadowColor = XColorRGBA.FromXml(xShadowColor),
                HighlightColor = XColorRGBA.FromXml(xHighlightColor)
            });
        }
Пример #17
0
        public static XElement ToXmlRGBA(TextRecordRGBA entry)
        {
            var res = new XElement(XName.Get("TextRecord6"));

            res.Add(new XAttribute("isSetup", CommonFormatter.Format(entry.Type)));
            if (entry.FontID.HasValue)
            {
                res.Add(new XAttribute("objectID", entry.FontID.Value));
            }
            if (entry.Reserved != 0)
            {
                res.Add(new XAttribute("reserved", entry.Reserved));
            }
            if (entry.XOffset.HasValue)
            {
                res.Add(new XAttribute("x", entry.XOffset.Value));
            }
            if (entry.YOffset.HasValue)
            {
                res.Add(new XAttribute("y", entry.YOffset.Value));
            }
            if (entry.FontID.HasValue)
            {
                if (!entry.TextHeight.HasValue)
                {
                    throw new InvalidOperationException("Text Height must be specified");
                }
                res.Add(new XAttribute("fontHeight", entry.TextHeight.Value));
            }
            if (entry.TextColor.HasValue)
            {
                var color = entry.TextColor.Value;
                res.Add(new XElement("color", XColorRGBA.ToXml(color)));
            }
            res.Add(new XElement(XName.Get("glyphs"), entry.Glyphs.Select(FormatGlyphEntry)));
            return(res);
        }
Пример #18
0
 public static XElement ToXml(LineStyleRGBA lineStyle)
 {
     return(new XElement("LineStyle",
                         new XAttribute("width", lineStyle.Width),
                         new XElement("color", XColorRGBA.ToXml(lineStyle.Color))));
 }