Exemple #1
0
        public ButtonRecord(SwfStream stream, Type defButtonType, out bool ok)
        {
            mFlags = stream.ReadByte();
            ok = (mFlags != 0);
            if (!ok)
                return;

            bool hasBlend = (mFlags & 0x20) != 0;
            bool hasFilters = (mFlags & 0x10) != 0;
            CharacterID = stream.ReadUShort();
            CharacterDepth = stream.ReadUShort();
            CharacterMatrix = stream.ReadMatrix();

            if (defButtonType == typeof(Tags.DefineButton2Tag))
            {
                CxForm = stream.ReadCxForm(true);
                Filters = hasFilters ? Filter.ReadFilterList(stream) : new Filter[0];
                Blending = hasBlend ? (BlendMode)stream.ReadByte() : BlendMode.Normal;
            }
            else
            {
                CxForm = VGCxForm.Identity;
                Filters = new Filter[0];
                Blending = BlendMode.Normal;
            }
        }
Exemple #2
0
 public void Load(SwfStream stream, uint length, byte version)
 {
     CharacterID = stream.ReadUShort();
     Depth = stream.ReadUShort();
     Matrix = stream.ReadMatrix();
     CxForm = stream.TagPosition < length ? stream.ReadCxForm(false) : VGCxForm.Identity;
 }
Exemple #3
0
        public virtual void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();

            int count = stream.ReadUShort() / 2;
            stream.Skip((count - 1) * 2);

            Glyphs = new FontGlyph[count];
            for (int i = 0; i < count; i++)
            {
                var subShapes = new Shape(ShapeInfo.ReadShape(stream, false, false, false, false), true).SubShapes;
                if (subShapes == null || subShapes.Length < 1) continue;

                var shape = subShapes[0];
                if (shape != null && shape.Fills.Count > 0)
                {
                    Glyphs[i] = new FontGlyph
                    {
                        GlyphPath = shape.Fills.Values.First().GetPath(),
                        ReferencePoint = new Vector2(shape.Shape.ReferencePoint.X, shape.Shape.ReferencePoint.Y) * EMSquareInv
                    };
                    Glyphs[i].GlyphPath.Scale(EMSquareInv);
                }
                else
                    Glyphs[i] = new FontGlyph { GlyphPath = new VGPath(), ReferencePoint = Vector2.Zero };
            }
        }
Exemple #4
0
        public TextRecord(SwfStream stream, bool hasAlpha, int glyphBits, int advanceBits)
        {
            _flags = stream.ReadByte();
            if (EndRecord) return;

            if (HasFont) FontId = stream.ReadUShort();
            if (HasColor) Color = hasAlpha ? stream.ReadRGBA() : stream.ReadRGB();
            if (HasXOffset) XOffset = stream.ReadShort();
            if (HasYOffset) YOffset = stream.ReadShort();
            if (HasFont) FontSize = stream.ReadUShort();

            byte count = stream.ReadByte();
            Glyphs = new GlyphEntry[count];
            for (int i = 0; i < count; i++)
                Glyphs[i] = new GlyphEntry(stream, glyphBits, advanceBits);
        }
Exemple #5
0
 public ButtonCondAction(SwfStream stream)
 {
     ushort size = stream.ReadUShort();
     mFlags = stream.ReadByte();
     mKey = stream.ReadByte();
     Actions = ActionRecord.ReadActions(stream, null);
 }
Exemple #6
0
        protected void Load(SwfStream stream, uint length, bool hasDeblock)
        {
            CharacterID = stream.ReadUShort();
            uint alpha = stream.ReadUInt();
            Deblock = hasDeblock ? (ushort?)stream.ReadUShort() : null;
            byte[] data = stream.ReadByteArray(length - 6);

            ImageData = new byte[alpha];
            Array.Copy(data, 0, ImageData, 0, (int)alpha);
            Format = BitmapUtils.DetectFormat(ImageData);
            if (Format == BitmapFormat.Jpeg)
                ImageData = BitmapUtils.RepairJpegMarkers(ImageData);

            CompressedAlpha = new byte[data.Length - alpha];
            if (CompressedAlpha.Length > 0)
                Array.Copy(data, (int)alpha, CompressedAlpha, 0, CompressedAlpha.Length);
        }
Exemple #7
0
        public LineStyle(SwfStream swf, bool hasAlpha, bool isExtended, int index)
        {
            Index = index;

            if (isExtended)
            {
                Width = swf.ReadUShort();
                StartCapStyle = ReadCap(swf);
                JoinStyle = ReadJoin(swf);
                HasFill = swf.ReadBit();
                NoHScale = swf.ReadBit();
                NoVScale = swf.ReadBit();
                PixelHinting = swf.ReadBit();

                swf.ReadBitUInt(5); // Reserved

                NoClose = swf.ReadBit();
                EndCapStyle = ReadCap(swf);

                if (JoinStyle == VGLineJoin.Miter)
                    MiterLimit = swf.ReadFixedHalf();

                if (HasFill)
                    Fill = new FillStyle(swf, hasAlpha, -1);
                else
                    Color = swf.ReadRGBA();
            }
            else
            {
                Width = swf.ReadUShort();
                Color = hasAlpha ? swf.ReadRGBA() : swf.ReadRGB();

                StartCapStyle = VGLineCap.Round;
                EndCapStyle = VGLineCap.Round;
                JoinStyle = VGLineJoin.Round;
                HasFill = false;
                NoHScale = false;
                NoVScale = false;
                PixelHinting = false;
                NoClose = false;
                MiterLimit = 1m;
                Fill = null;
            }

            if (Width < 1) Width = 1;
        }
Exemple #8
0
        public FillStyleArray(SwfStream swf, bool hasAlpha)
        {
            int count = swf.ReadByte();
            if (count == 0xFF) count = swf.ReadUShort();

            Styles = new FillStyle[count];
            for (int i = 0; i < count; i++)
                Styles[i] = new FillStyle(swf, hasAlpha, i + 1);
        }
Exemple #9
0
        public LineStyleArray(SwfStream swf, bool hasAlpha, bool isExtended)
        {
            int count = swf.ReadByte();
            if (count == 0xFF) count = swf.ReadUShort();

            Styles = new LineStyle[count];
            for (int i = 0; i < count; i++)
                Styles[i] = new LineStyle(swf, hasAlpha, isExtended, i + 1);
        }
        protected bool Load(SwfStream stream, uint length, bool hasAlpha)
        {
            CharacterID = stream.ReadUShort();

            byte format = stream.ReadByte();
            Width = stream.ReadUShort();
            Height = stream.ReadUShort();
            byte table = (format == 3) ? stream.ReadByte() : (byte)0;
            byte[] compressed = stream.ReadByteArray(length - stream.TagPosition);
            byte[] data;
            var inflater = new Inflater();
            inflater.SetInput(compressed);

            if (format == 3)
            {
                int rem = Width % 4;
                data = new byte[((rem == 0) ? Width : (Width + 4 - rem)) * Height * 4];
                if (inflater.Inflate(data) != data.Length)
                    throw new SwfCorruptedException("Bitmap data are not valid ZLIB stream!");
                Pixels = BitmapUtils.UnpackIndexed(data, Width, Height, table, hasAlpha);
            }
            else if (format == 4 && !hasAlpha)
            {
                data = new byte[(Width + Width & 0x01) * Height * 2];
                if (inflater.Inflate(data) != data.Length)
                    throw new SwfCorruptedException("Bitmap data are not valid ZLIB stream!");
                Pixels = BitmapUtils.UnpackPIX15(data, Width, Height);
            }
            else if (format == 5)
            {
                data = new byte[Width * Height * 4];
                if (inflater.Inflate(data) != data.Length)
                    return true;
                Pixels = BitmapUtils.UnpackPIX24(data, Width, Height, hasAlpha);
            }
            else
                throw new SwfCorruptedException("Invalid lossless bitmap format found!");

            return true;
        }
Exemple #11
0
        public override void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();
            ShapeBounds = stream.ReadRectangle();
            EdgeBounds = stream.ReadRectangle();

            byte res = stream.ReadByte();
            UsesFillWindingRule = version >= 10 && (res & 4) != 0;
            UsesNonScalingStrokes = (res & 2) != 0;
            UsesScalingStrokes = (res & 1) != 0;

            Shape = new Shape(ShapeInfo.ReadShape(stream, true, true, true, true), false);
        }
Exemple #12
0
        public void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();
            FrameCount = stream.ReadUShort();

            List<ISwfControlTag> tags = new List<ISwfControlTag>(256);
            ISwfTag tag;

            do
            {
                tag = stream.ReadTag();
                if (tag == null)
                    continue;

                CheckTagValidity(tag);

                if (tag is EndTag)
                    break;
                else
                    tags.Add((ISwfControlTag)tag);
            } while (true);

            Tags = tags.ToArray();
        }
Exemple #13
0
        public void Load(SwfStream stream, uint length, byte version)
        {
            long end = length + stream.TagPosition;

            CharacterID = stream.ReadUShort();
            TrackAsMenu = (stream.ReadByte() & 0x01) != 0;
            ushort actionOffset = stream.ReadUShort();

            var type = GetType();
            var parts = new List<ButtonRecord>();
            bool ok;
            while (true)
            {
                var part = new ButtonRecord(stream, type, out ok);
                if (!ok) break;
                parts.Add(part);
            }
            Parts = parts.ToArray();

            var actions = new List<ButtonCondAction>();
            while (stream.TagPosition < end)
                actions.Add(new ButtonCondAction(stream));
            Actions = actions.ToArray();
        }
Exemple #14
0
        public ClipActions(SwfStream stream)
        {
            stream.ReadUShort();
            AllEvents = stream.ReadClipEventFlags();

            var records = new List<ClipActionRecord>();
            ClipActionRecord current;

            while(true)
            {
                current = new ClipActionRecord(stream);
                if (current.EventFlags == ClipEventFlags.None)
                    break;
                records.Add(current);
            }

            Records = records.ToArray();
        }
Exemple #15
0
        public virtual void Load(SwfStream stream, uint length, byte version)
        {
            FontID = stream.ReadUShort();
            Name = stream.ReadString(stream.ReadByte());
            Flags = (FontFlags)stream.ReadByte();
            ReadLangCode(stream);

            uint count = (uint)(length - stream.TagPosition);
            if ((Flags & FontFlags.WideCodes) != 0)
            {
                count /= 2;
                Characters = stream.ReadCharArray((int)count);
            }
            else
            {
                Characters = new char[count];
                for (int i = 0; i < count; i++)
                    Characters[i] = (char)stream.ReadByte();
            }
        }
Exemple #16
0
        public virtual void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();
            Bounds = stream.ReadRectangle();
            Matrix = stream.ReadMatrix();

            if (CharacterID == 347)
            { }

            byte gBits = stream.ReadByte();
            byte aBits = stream.ReadByte();

            List<TextRecord> recs = new List<TextRecord>();
            while (true)
            {
                var rec = new TextRecord(stream, HasAlpha, gBits, aBits);
                if (rec.EndRecord) break;
                recs.Add(rec);
            }
            TextRecords = recs.ToArray();
        }
Exemple #17
0
 public void Load(SwfStream stream, uint length, byte version)
 {
     CharacterID = stream.ReadUShort();
     CxForm = stream.ReadCxForm(false);
 }
Exemple #18
0
 public virtual void Load(SwfStream stream, uint length, byte version)
 {
     CharacterID = stream.ReadUShort();
     ImageData = BitmapUtils.ComposeJpeg(stream.JpegTables.JpegData, BitmapUtils.RepairJpegMarkers(stream.ReadByteArray(length - 2)));
 }
Exemple #19
0
 public override void Load(SwfStream stream, uint length, byte version)
 {
     CharacterID = stream.ReadUShort();
     ImageData = BitmapUtils.RepairJpegMarkers(stream.ReadByteArray(length - 2));
     Format = BitmapUtils.DetectFormat(ImageData);
 }
Exemple #20
0
        public virtual void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();
            Flags = (FontFlags)stream.ReadByte();
            Language = stream.ReadLanguage();
            Name = stream.ReadString(stream.ReadByte());
            ushort count = stream.ReadUShort();
            stream.Skip((count + 1) * (((Flags & FontFlags.WideOffsets) != 0) ? 4 : 2)); // Offsets

            Glyphs = new FontGlyph[count];
            for (int i = 0; i < count; i++)
            {
                var subShapes = new Shape(ShapeInfo.ReadShape(stream, false, false, false, false), true).SubShapes;
                if (subShapes == null || subShapes.Length < 1) continue;

                var shape = subShapes[0];
                if (shape != null && shape.Fills.Count > 0)
                {
                    Glyphs[i] = new FontGlyph
                    {
                        GlyphPath = shape.Fills.Values.First().GetPath(),
                        ReferencePoint = new Vector2(shape.Shape.ReferencePoint.X, shape.Shape.ReferencePoint.Y) * DefineFontTag.EMSquareInv
                    };
                    Glyphs[i].GlyphPath.Scale(DefineFontTag.EMSquareInv);
                }
                else
                    Glyphs[i] = new FontGlyph { GlyphPath = new VGPath(), ReferencePoint = Vector2.Zero };
            }

            if ((Flags & FontFlags.WideCodes) != 0)
                Characters = stream.ReadCharArray((int)count);
            else
            {
                Characters = new char[count];
                for (int i = 0; i < count; i++)
                    Characters[i] = (char)stream.ReadByte();
            }

            if ((Flags & FontFlags.HasLayout) != 0)
            {
                Ascent = stream.ReadShort();
                Descent = stream.ReadShort();
                Leading = stream.ReadShort();
                Advances = stream.ReadShortArray(count);
                Bounds = stream.ReadRectangleArray(count);

                char l, r;
                int adj;
                ushort kerns = stream.ReadUShort();
                Kerning = new VGKerningTable(kerns);
                if ((Flags & FontFlags.WideCodes) != 0)
                {
                    for (int i = 0; i < kerns; i++)
                    {
                        l = (char)stream.ReadUShort();
                        r = (char)stream.ReadUShort();
                        adj = stream.ReadShort();
                        Kerning.Add(l, r, adj);
                    }
                }
                else
                {
                    for (int i = 0; i < kerns; i++)
                    {
                        l = (char)stream.ReadByte();
                        r = (char)stream.ReadByte();
                        adj = stream.ReadShort();
                        Kerning.Add(l, r, adj);
                    }
                }
            }
        }
Exemple #21
0
 public void Load(SwfStream stream, uint length, byte version)
 {
     SpriteID = stream.ReadUShort();
     Actions = ActionRecord.ReadActions(stream, null);
 }
Exemple #22
0
 public virtual void Load(SwfStream stream, uint length, byte version)
 {
     CharacterID = stream.ReadUShort();
     ShapeBounds = stream.ReadRectangle();
     Shape = new Shape(ShapeInfo.ReadShape(stream, false, false, true, false), false);
 }
 public void Load(SwfStream stream, uint length, byte version)
 {
     CharacterID = stream.ReadUShort();
     stream.ReadUInt();
     Data = stream.ReadByteArray(length - 6);
 }
Exemple #24
0
 public void Load(SwfStream stream, uint length, byte version)
 {
     mFlags = stream.ReadByte();
     Depth = stream.ReadUShort();
     if (HasCharacter) CharacterID = stream.ReadUShort();
     if (HasMatrix) Matrix = stream.ReadMatrix();
     if (HasCxForm) CxForm = stream.ReadCxForm(true);
     if (HasRatio) Ratio = stream.ReadUShort();
     if (HasName) Name = stream.ReadString();
     if (HasClipDepth) ClipDepth = stream.ReadUShort();
     if (HasActions) Actions = new ClipActions(stream);
 }
Exemple #25
0
 public void Load(SwfStream stream, uint length, byte version)
 {
     Depth = stream.ReadUShort();
     TabIndex = stream.ReadUShort();
 }
 public void Load(SwfStream stream, uint length, byte version)
 {
     CharacterID = stream.ReadUShort();
     Splitter = stream.ReadRectangle();
 }
Exemple #27
0
 public void Load(SwfStream stream, uint length, byte version)
 {
     CharacterID = stream.ReadUShort();
     Depth = stream.ReadUShort();
 }
Exemple #28
0
 public virtual void Load(SwfStream stream, uint length, byte version)
 {
     CharacterID = stream.ReadUShort();
     Bounds = stream.ReadRectangle();
     Flags = (EditTextFlags)stream.ReadUShort();
     if ((Flags & EditTextFlags.HasFont) != 0) FontID = stream.ReadUShort();
     if ((Flags & EditTextFlags.HasFontClass) != 0) FontClass = stream.ReadString();
     if ((Flags & EditTextFlags.HasFont) != 0) FontHeight = stream.ReadUShort();
     TextColor = ((Flags & EditTextFlags.HasTextColor) != 0) ? stream.ReadRGBA() : (VGColor)Color.Black;
     MaxLength = ((Flags & EditTextFlags.HasMaxLength) != 0) ? stream.ReadUShort() : ushort.MaxValue;
     if ((Flags & EditTextFlags.HasLayout) != 0)
     {
         TextAlign = (Align)stream.ReadByte();
         LeftMargin = stream.ReadUShort();
         RightMargin = stream.ReadUShort();
         Indent = stream.ReadUShort();
         Leading = stream.ReadShort();
     }
     Variable = stream.ReadString();
     InitialText = ((Flags & EditTextFlags.HasText) != 0) ? stream.ReadString() : string.Empty;
 }
Exemple #29
0
        public void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();

            var type = GetType();
            var parts = new List<ButtonRecord>();
            bool ok;
            while (true)
            {
                var part = new ButtonRecord(stream, type, out ok);
                if (!ok) break;
                parts.Add(part);
            }
            Parts = parts.ToArray();
            Actions = ActionRecord.ReadActions(stream, null);
        }
Exemple #30
0
 public virtual void Load(SwfStream stream, uint length, byte version)
 {
     FontID = stream.ReadUShort();
     Name = stream.ReadString();
     Copyright = stream.ReadString();
 }