Exemple #1
0
 /// <summary>
 /// Writes the ARGB color to writer.
 /// </summary>
 /// <param name="writer">The writer to which to write color.</param>
 /// <param name="val">Color to be written.</param>
 public static void WriteARGB(this ISwfStreamWriter writer, SwfRGBA val)
 {
     writer.WriteByte(val.Alpha);
     writer.WriteByte(val.Red);
     writer.WriteByte(val.Green);
     writer.WriteByte(val.Blue);
 }
Exemple #2
0
 public static void WriteKerningRecord(this ISwfStreamWriter writer, KerningRecord record, bool wideCodes)
 {
     if (wideCodes)
     {
         writer.WriteUInt16(record.LeftCode);
         writer.WriteUInt16(record.RightCode);
     }
     else
     {
         writer.WriteByte((byte)record.LeftCode);
         writer.WriteByte((byte)record.RightCode);
     }
     writer.WriteSInt16(record.Adjustment);
 }
Exemple #3
0
        public static void WriteClipActionRecord(this ISwfStreamWriter writer, byte swfVersion, ClipActionRecord record)
        {
            writer.WriteClipEventFlags(swfVersion, record.Flags);
            if (record.Flags.IsEmpty)
            {
                return;
            }

            var awmem = new MemoryStream();
            var aw    = new ActionWriter(new SwfStreamWriter(awmem));

            foreach (var action in record.Actions)
            {
                aw.WriteAction(action);
            }

            var size = awmem.Length + (record.Flags.ClipEventKeyPress ? 1 : 0);

            writer.WriteUInt32((uint)size);

            if (record.Flags.ClipEventKeyPress)
            {
                writer.WriteByte(record.KeyCode);
            }

            writer.WriteBytes(awmem.ToArray());
        }
Exemple #4
0
        public static void WriteClipEventFlags(this ISwfStreamWriter writer, byte swfVersion, ClipEventFlags flags)
        {
            writer.WriteBit(flags.ClipEventKeyUp);
            writer.WriteBit(flags.ClipEventKeyDown);
            writer.WriteBit(flags.ClipEventMouseUp);
            writer.WriteBit(flags.ClipEventMouseDown);
            writer.WriteBit(flags.ClipEventMouseMove);
            writer.WriteBit(flags.ClipEventUnload);
            writer.WriteBit(flags.ClipEventEnterFrame);
            writer.WriteBit(flags.ClipEventLoad);

            writer.WriteBit(flags.ClipEventDragOver);
            writer.WriteBit(flags.ClipEventRollOut);
            writer.WriteBit(flags.ClipEventRollOver);
            writer.WriteBit(flags.ClipEventReleaseOutside);
            writer.WriteBit(flags.ClipEventRelease);
            writer.WriteBit(flags.ClipEventPress);
            writer.WriteBit(flags.ClipEventInitialize);
            writer.WriteBit(flags.ClipEventData);

            if (swfVersion >= 6)
            {
                writer.WriteUnsignedBits(flags.Reserved, 5);
                writer.WriteBit(flags.ClipEventConstruct);
                writer.WriteBit(flags.ClipEventKeyPress);
                writer.WriteBit(flags.ClipEventDragOut);

                writer.WriteByte(flags.Reserved2);
            }
        }
Exemple #5
0
        public static void WriteButtonRecordEx(this ISwfStreamWriter writer, ButtonRecordEx button)
        {
            writer.WriteUnsignedBits(button.Reserved, 2);
            writer.WriteBit(button.BlendMode.HasValue);
            writer.WriteBit(button.Filters.Count > 0);
            writer.WriteBit(button.StateHitTest);
            writer.WriteBit(button.StateDown);
            writer.WriteBit(button.StateOver);
            writer.WriteBit(button.StateUp);
            if (!button.IsEndButton)
            {
                writer.WriteUInt16(button.CharacterID);
                writer.WriteUInt16(button.PlaceDepth);
                writer.WriteMatrix(ref button.PlaceMatrix);
                writer.WriteColorTransformRGBA(button.ColorTransform);
                writer.FlushBits();

                if (button.Filters.Count > 0)
                {
                    writer.WriteFilterList(button.Filters);
                }
                if (button.BlendMode.HasValue)
                {
                    writer.WriteByte((byte)button.BlendMode.Value);
                }
            }
        }
Exemple #6
0
 public static void WriteFilterList(this ISwfStreamWriter writer, IList <BaseFilter> source)
 {
     writer.WriteByte((byte)source.Count);
     foreach (var filter in source)
     {
         writer.WriteFilter(filter);
     }
 }
Exemple #7
0
 public static void WriteLineStylesEx(this ISwfStreamWriter writer, IList <LineStyleEx> styles)
 {
     if (styles.Count < 255)
     {
         writer.WriteByte((byte)styles.Count);
     }
     else
     {
         writer.WriteByte(255);
         writer.WriteUInt16((ushort)styles.Count);
     }
     foreach (var lineStyle in styles)
     {
         var style = lineStyle;
         writer.WriteLineStyleEx(style);
     }
 }
Exemple #8
0
 public static void WriteFillStylesRGBA(this ISwfStreamWriter writer, IList <FillStyleRGBA> styles)
 {
     if (styles.Count < 255)
     {
         writer.WriteByte((byte)styles.Count);
     }
     else
     {
         writer.WriteByte(255);
         writer.WriteUInt16((ushort)styles.Count);
     }
     foreach (var fillStyle in styles)
     {
         var style = fillStyle;
         writer.WriteFillStyleRGBA(style);
     }
 }
Exemple #9
0
        public static void WriteTextRecordRGBA(this ISwfStreamWriter writer, TextRecordRGBA record, uint glyphBits, uint advanceBits)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }
            writer.WriteBit(record.Type);
            writer.WriteUnsignedBits(record.Reserved, 3);

            writer.WriteBit(record.FontID.HasValue);
            writer.WriteBit(record.TextColor.HasValue);
            writer.WriteBit(record.YOffset.HasValue);
            writer.WriteBit(record.XOffset.HasValue);

            var isEnd = !record.Type && record.Reserved == 0 && !record.FontID.HasValue && !record.TextColor.HasValue && !record.YOffset.HasValue && !record.XOffset.HasValue;

            if (!isEnd)
            {
                if (record.FontID.HasValue)
                {
                    writer.WriteUInt16(record.FontID.Value);
                }
                if (record.TextColor.HasValue)
                {
                    var color = record.TextColor.Value;
                    writer.WriteRGBA(ref color);
                }
                if (record.XOffset.HasValue)
                {
                    writer.WriteSInt16(record.XOffset.Value);
                }
                if (record.YOffset.HasValue)
                {
                    writer.WriteSInt16(record.YOffset.Value);
                }
                if (record.FontID.HasValue)
                {
                    if (!record.TextHeight.HasValue)
                    {
                        throw new InvalidOperationException("Font height must be specified when font is specified");
                    }
                    writer.WriteUInt16(record.TextHeight.Value);
                }
                if (record.Glyphs.Count > 255)
                {
                    throw new InvalidOperationException("Text record has too much glyphs specified");
                }

                writer.WriteByte((byte)record.Glyphs.Count);
                foreach (var glyph in record.Glyphs)
                {
                    writer.WriteGlyphEntry(glyph, glyphBits, advanceBits);
                }
            }
            writer.FlushBits();
        }
Exemple #10
0
 public static void WriteLineStylesRGB(this ISwfStreamWriter writer, IList <LineStyleRGB> styles, bool allowBigArray)
 {
     if (styles.Count < 255)
     {
         writer.WriteByte((byte)styles.Count);
     }
     else
     {
         if (!allowBigArray)
         {
             throw new InvalidOperationException("DefineShape supports up to 255 fill style records");
         }
         writer.WriteByte(255);
         writer.WriteUInt16((ushort)styles.Count);
     }
     foreach (var lineStyle in styles)
     {
         var style = lineStyle;
         writer.WriteLineStyleRGB(style);
     }
 }
Exemple #11
0
        public static void WriteSwfFileInfo(this ISwfStreamWriter writer, SwfFileInfo fileInfo)
        {
            string format = fileInfo.Format.ToString();

            if (string.IsNullOrEmpty(format) || format.Length != 3)
            {
                throw new InvalidOperationException("Format should be of length 3");
            }
            writer.WriteByte((byte)format[0]);
            writer.WriteByte((byte)format[1]);
            writer.WriteByte((byte)format[2]);

            writer.WriteByte(fileInfo.Version);

            var len = fileInfo.FileLength;

            writer.WriteByte((byte)((len >> 0) & 0xff));
            writer.WriteByte((byte)((len >> 8) & 0xff));
            writer.WriteByte((byte)((len >> 16) & 0xff));
            writer.WriteByte((byte)((len >> 24) & 0xff));
        }
Exemple #12
0
 public static void WriteGradientRecordRGBA(this ISwfStreamWriter writer, ref GradientRecordRGBA record)
 {
     writer.WriteByte(record.Ratio);
     writer.WriteRGBA(ref record.Color);
 }
Exemple #13
0
 /// <summary>
 /// Writes the RGB color to writer.
 /// </summary>
 /// <param name="writer">The writer to which to write color.</param>
 /// <param name="val">Color to be written.</param>
 public static void WriteRGB(this ISwfStreamWriter writer, ref SwfRGB val)
 {
     writer.WriteByte(val.Red);
     writer.WriteByte(val.Green);
     writer.WriteByte(val.Blue);
 }