Exemplo n.º 1
0
        public static void WriteColorTransformRGB(this ISwfStreamWriter writer, ref ColorTransformRGB tranform)
        {
            var bitsCounter = new SignedBitsCount(0);

            if (tranform.HasAddTerms)
            {
                bitsCounter.AddValue(tranform.RedAddTerm);
                bitsCounter.AddValue(tranform.GreenAddTerm);
                bitsCounter.AddValue(tranform.BlueAddTerm);
            }
            if (tranform.HasMultTerms)
            {
                bitsCounter.AddValue(tranform.RedMultTerm);
                bitsCounter.AddValue(tranform.GreenMultTerm);
                bitsCounter.AddValue(tranform.BlueMultTerm);
            }
            writer.WriteBit(tranform.HasAddTerms);
            writer.WriteBit(tranform.HasMultTerms);
            var bits = bitsCounter.GetBits();

            writer.WriteUnsignedBits(bits, 4);
            if (tranform.HasMultTerms)
            {
                writer.WriteSignedBits(tranform.RedMultTerm, bits);
                writer.WriteSignedBits(tranform.GreenMultTerm, bits);
                writer.WriteSignedBits(tranform.BlueMultTerm, bits);
            }
            if (tranform.HasAddTerms)
            {
                writer.WriteSignedBits(tranform.RedAddTerm, bits);
                writer.WriteSignedBits(tranform.GreenAddTerm, bits);
                writer.WriteSignedBits(tranform.BlueAddTerm, bits);
            }
            writer.FlushBits();
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
 public static void WriteShapeRecordsRGB(this ISwfStreamWriter writer, IList <IShapeRecordRGB> shapeRecords, uint fillStyleBits, uint lineStyleBits)
 {
     writer.WriteUnsignedBits(fillStyleBits, 4);
     writer.WriteUnsignedBits(lineStyleBits, 4);
     writer.FlushBits();
     foreach (var shapeRecord in shapeRecords)
     {
         _shapeRecordWriter.WriteRGB(writer, shapeRecord, true, ref fillStyleBits, ref lineStyleBits);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Writes rectangle to the writer.
        /// </summary>
        /// <param name="writer">Writer to which to write rectangle.</param>
        /// <param name="rect">Rectangle to be written.</param>
        public static void WriteRect(this ISwfStreamWriter writer, ref SwfRect rect)
        {
            var btCount = new SignedBitsCount(rect.XMin, rect.XMax, rect.YMin, rect.YMax);
            var bits    = btCount.GetBits();

            if (bits < 1)
            {
                bits = 1;
            }
            writer.WriteUnsignedBits(bits, 5);
            writer.WriteSignedBits(rect.XMin, bits);
            writer.WriteSignedBits(rect.XMax, bits);
            writer.WriteSignedBits(rect.YMin, bits);
            writer.WriteSignedBits(rect.YMax, bits);
            writer.FlushBits();
        }
Exemplo n.º 6
0
        public static void WriteMatrix(this ISwfStreamWriter writer, ref SwfMatrix matrix)
        {
            var hasScale = matrix.HasScale;

            writer.WriteBit(hasScale);
            if (hasScale)
            {
                var sx        = (int)(matrix.ScaleX * 65536.0);
                var sy        = (int)(matrix.ScaleY * 65536.0);
                var scaleBits = new SignedBitsCount(sx, sy).GetBits();
                if (scaleBits < 1)
                {
                    scaleBits = 1;
                }
                writer.WriteUnsignedBits(scaleBits, 5);
                writer.WriteFixedPoint16(matrix.ScaleX, scaleBits);
                writer.WriteFixedPoint16(matrix.ScaleY, scaleBits);
            }
            var hasRotate = matrix.HasRotate;

            writer.WriteBit(hasRotate);
            if (hasRotate)
            {
                var rx         = (int)(matrix.RotateSkew0 * 65536.0);
                var ry         = (int)(matrix.RotateSkew1 * 65536.0);
                var rotateBits = new SignedBitsCount(rx, ry).GetBits();
                if (rotateBits < 1)
                {
                    rotateBits = 1;
                }
                writer.WriteUnsignedBits(rotateBits, 5);
                writer.WriteFixedPoint16(matrix.RotateSkew0, rotateBits);
                writer.WriteFixedPoint16(matrix.RotateSkew1, rotateBits);
            }
            var translateBits = new SignedBitsCount(matrix.TranslateX, matrix.TranslateY).GetBits();

            writer.WriteUnsignedBits(translateBits, 5);
            writer.WriteSignedBits(matrix.TranslateX, translateBits);
            writer.WriteSignedBits(matrix.TranslateY, translateBits);
            writer.FlushBits();
        }