コード例 #1
0
        // PackByte
        //      Packs an op-code, and up to 4 booleans into a single byte.
        //
        // Binary format is :
        //      First 4 bits map directly to the op-code.
        //      Next 4 bits map to booleans 1 - 4.
        //
        //          Like this:
        //
        //              7| 6  | 5  | 4  | 3 | 2 | 1 | 0 |
        //           <B4>|<B3>|<B2>|<B1><-  Op Code    ->
        //
        private static byte PackByte(ParserGeometryContextOpCodes opCode, bool bool1, bool bool2, bool bool3, bool bool4)
        {
            byte packedByte = (byte)opCode;

            if (packedByte >= 16)
            {
                throw new ArgumentException(SR.Get(SRID.UnknownPathOperationType));
            }

            if (bool1)
            {
                packedByte |= SetBool1;
            }

            if (bool2)
            {
                packedByte |= SetBool2;
            }

            if (bool3)
            {
                packedByte |= SetBool3;
            }

            if (bool4)
            {
                packedByte |= SetBool4;
            }

            return(packedByte);
        }
コード例 #2
0
        internal static void Deserialize(BinaryReader br, StreamGeometryContext sc, StreamGeometry geometry)
        {
            bool closed = false;
            Byte currentByte;

            while (!closed)
            {
                currentByte = br.ReadByte();

                ParserGeometryContextOpCodes opCode = UnPackOpCode(currentByte);

                switch (opCode)
                {
                case ParserGeometryContextOpCodes.FillRule:
                    DeserializeFillRule(br, currentByte, geometry);
                    break;

                case ParserGeometryContextOpCodes.BeginFigure:
                    DeserializeBeginFigure(br, currentByte, sc);
                    break;

                case ParserGeometryContextOpCodes.LineTo:
                    DeserializeLineTo(br, currentByte, sc);
                    break;

                case ParserGeometryContextOpCodes.QuadraticBezierTo:
                    DeserializeQuadraticBezierTo(br, currentByte, sc);
                    break;

                case ParserGeometryContextOpCodes.BezierTo:
                    DeserializeBezierTo(br, currentByte, sc);
                    break;

                case ParserGeometryContextOpCodes.PolyLineTo:
                    DeserializePolyLineTo(br, currentByte, sc);
                    break;

                case ParserGeometryContextOpCodes.PolyQuadraticBezierTo:
                    DeserializePolyQuadraticBezierTo(br, currentByte, sc);
                    break;

                case ParserGeometryContextOpCodes.PolyBezierTo:
                    DeserializePolyBezierTo(br, currentByte, sc);
                    break;

                case ParserGeometryContextOpCodes.ArcTo:
                    DeserializeArcTo(br, currentByte, sc);
                    break;

                case ParserGeometryContextOpCodes.Closed:
                    closed = true;
                    break;
                }
            }
        }
コード例 #3
0
        // SerializeListOfPointsAndTwoBools
        //
        // Binary format is :
        //
        //  <Byte+OpCode> <Count> <Number1> ... <NumberN>
        //
        //      <Byte+OpCode> := OpCode + bool1 + bool2
        //      <Count> := int32
        //      <NumberN> := <SerializationFloatType.ScaledInteger+Integer> | <SerializationFloatTypeForSpecialNumbers> | <SerializationFloatType.Double+Double>
        private void SerializeListOfPointsAndTwoBools(ParserGeometryContextOpCodes opCode, IList <Point> points, bool bool1, bool bool2)
        {
            // Pack the two bools into one byte
            Byte packedByte = PackByte(opCode, bool1, bool2);

            _bw.Write(packedByte);

            // Write the count.
            _bw.Write(points.Count);

            // Write out all the Points
            for (int i = 0; i < points.Count; i++)
            {
                XamlSerializationHelper.WriteDouble(_bw, points[i].X);
                XamlSerializationHelper.WriteDouble(_bw, points[i].Y);
            }
        }
コード例 #4
0
        //
        // SerializePointAndTwoBools
        //
        // Binary format is :
        //
        //  <Byte+OpCode> <Number1> <Number2>
        //
        //      Where :
        //          <Byte+OpCode> := OpCode + bool1 + bool2 + isScaledIntegerX + isScaledIntegerY
        //          <NumberN> := <ScaledInteger> | <SerializationFloatTypeForSpecialNumbers> | <SerializationFloatType.Double+Double>
        //          <SerializationFloatTypeForSpecialNumbers> := <SerializationFloatType.Zero> | <SerializationFloatType.One> | <SerializationFloatType.MinusOne>
        //          <SerializationFloatType.Double+Double> := <SerializationFloatType.Double> <Double>
        //
        // By packing the flags for isScaledInteger into the first byte - we save 2 extra bytes per number for the common case.
        //
        // As a result - most LineTo's (and other operations) will be stored in 9 bytes.
        //               Some LineTo's will be 6 (or even sometimes 3)
        //               Max LineTo will be 19 (two doubles).
        private void SerializePointAndTwoBools(ParserGeometryContextOpCodes opCode,
                                               Point point,
                                               bool bool1,
                                               bool bool2)
        {
            int  intValueX = 0;
            int  intValueY = 0;
            bool isScaledIntegerX, isScaledIntegerY;

            isScaledIntegerX = XamlSerializationHelper.CanConvertToInteger(point.X, ref intValueX);
            isScaledIntegerY = XamlSerializationHelper.CanConvertToInteger(point.Y, ref intValueY);

            _bw.Write(PackByte(opCode, bool1, bool2, isScaledIntegerX, isScaledIntegerY));

            SerializeDouble(point.X, isScaledIntegerX, intValueX);
            SerializeDouble(point.Y, isScaledIntegerY, intValueY);
        }
コード例 #5
0
 private static byte PackByte(ParserGeometryContextOpCodes opCode, bool bool1, bool bool2)
 {
     return(PackByte(opCode, bool1, bool2, false, false));
 }
コード例 #6
0
        // PackByte
        //      Packs an op-code, and up to 4 booleans into a single byte.
        //
        // Binary format is :
        //      First 4 bits map directly to the op-code.
        //      Next 4 bits map to booleans 1 - 4.
        //
        //          Like this:
        //
        //              7| 6  | 5  | 4  | 3 | 2 | 1 | 0 |
        //           <B4>|<B3>|<B2>|<B1><-  Op Code    ->
        //
        private static byte PackByte(ParserGeometryContextOpCodes opCode, bool bool1, bool bool2, bool bool3, bool bool4)
        {
            byte packedByte = (byte) opCode;

            if (packedByte >= 16)
            {
                throw new ArgumentException(SR.Get(SRID.UnknownPathOperationType));
            }

            if (bool1)
            {
                packedByte |= SetBool1;
            }

            if (bool2)
            {
                packedByte |= SetBool2;
            }

            if (bool3)
            {
                packedByte |= SetBool3;
            }

            if (bool4)
            {
                packedByte |= SetBool4;
            }

            return packedByte;
        }
コード例 #7
0
 private static byte PackByte(ParserGeometryContextOpCodes opCode, bool bool1, bool bool2)
 {
     return PackByte(opCode, bool1, bool2, false, false);
 }
コード例 #8
0
        // SerializeListOfPointsAndTwoBools
        //
        // Binary format is :
        //
        //  <Byte+OpCode> <Count> <Number1> ... <NumberN>
        //
        //      <Byte+OpCode> := OpCode + bool1 + bool2
        //      <Count> := int32
        //      <NumberN> := <SerializationFloatType.ScaledInteger+Integer> | <SerializationFloatTypeForSpecialNumbers> | <SerializationFloatType.Double+Double>
        private void SerializeListOfPointsAndTwoBools(ParserGeometryContextOpCodes opCode, IList<Point> points, bool bool1, bool bool2)
        {
            // Pack the two bools into one byte
            Byte packedByte = PackByte(opCode, bool1, bool2);
            _bw.Write(packedByte);

            // Write the count.
            _bw.Write(points.Count);

            // Write out all the Points
            for(int i = 0; i < points.Count; i++)
            {
                XamlSerializationHelper.WriteDouble(_bw, points[i].X);
                XamlSerializationHelper.WriteDouble(_bw, points[i].Y);
            }
        }
コード例 #9
0
        //
        // SerializePointAndTwoBools
        //
        // Binary format is :
        //
        //  <Byte+OpCode> <Number1> <Number2>
        //
        //      Where :
        //          <Byte+OpCode> := OpCode + bool1 + bool2 + isScaledIntegerX + isScaledIntegerY
        //          <NumberN> := <ScaledInteger> | <SerializationFloatTypeForSpecialNumbers> | <SerializationFloatType.Double+Double>
        //          <SerializationFloatTypeForSpecialNumbers> := <SerializationFloatType.Zero> | <SerializationFloatType.One> | <SerializationFloatType.MinusOne>
        //          <SerializationFloatType.Double+Double> := <SerializationFloatType.Double> <Double>
        //
        // By packing the flags for isScaledInteger into the first byte - we save 2 extra bytes per number for the common case.
        //
        // As a result - most LineTo's (and other operations) will be stored in 9 bytes.
        //               Some LineTo's will be 6 (or even sometimes 3)
        //               Max LineTo will be 19 (two doubles).
        private void SerializePointAndTwoBools(ParserGeometryContextOpCodes opCode,
                                                       Point point,
                                                       bool bool1,
                                                       bool bool2)
        {
            int intValueX = 0;
            int intValueY = 0;
            bool isScaledIntegerX, isScaledIntegerY;

            isScaledIntegerX = XamlSerializationHelper.CanConvertToInteger(point.X, ref intValueX);
            isScaledIntegerY = XamlSerializationHelper.CanConvertToInteger(point.Y, ref intValueY);

            _bw.Write(PackByte(opCode, bool1, bool2, isScaledIntegerX, isScaledIntegerY));

            SerializeDouble(point.X, isScaledIntegerX, intValueX);
            SerializeDouble(point.Y, isScaledIntegerY, intValueY);
        }