示例#1
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();
        }