Ejemplo n.º 1
0
 static StrokeCollectionSerializer()
 {
     TransformDescriptor transformDescriptor = new TransformDescriptor();
     transformDescriptor.Transform[0] = 1.0f;
     transformDescriptor.Tag = KnownTagCache.KnownTagIndex.TransformIsotropicScale;
     transformDescriptor.Size = 1;
     StrokeCollectionSerializer.IdentityTransformDescriptor = transformDescriptor;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a Matrix Information structure based on the transform descriptor
        /// </summary>
        /// <param name="tdrd"></param>
        /// <returns></returns>
        private Matrix LoadTransform(TransformDescriptor tdrd)
        {
            double M00 = 0.0f, M01 = 0.0f, M10 = 0.0f, M11 = 0.0f, M20 = 0.0f, M21 = 0.0f;

            if (KnownTagCache.KnownTagIndex.TransformIsotropicScale == tdrd.Tag)
            {
                M00 = M11 = tdrd.Transform[0];
            }
            else if (KnownTagCache.KnownTagIndex.TransformRotate == tdrd.Tag)
            {
                double dAngle = (tdrd.Transform[0] / 100) * (Math.PI / 180);

                M00 = M11 = Math.Cos(dAngle);
                M01 = Math.Sin(dAngle);
                if (M01 == 0.0f && M11 == 1.0f)
                {
                    //special case for 0 degree rotate transforms
                    //this is identity
                    M10 = 0.0f;
                }
                else
                {
                    M10 = -M11;
                }
            }
            else if (KnownTagCache.KnownTagIndex.TransformAnisotropicScale == tdrd.Tag)
            {
                M00 = tdrd.Transform[0];
                M11 = tdrd.Transform[1];
            }
            else if (KnownTagCache.KnownTagIndex.TransformTranslate == tdrd.Tag)
            {
                M20 = tdrd.Transform[0];
                M21 = tdrd.Transform[1];
            }
            else if (KnownTagCache.KnownTagIndex.TransformScaleAndTranslate == tdrd.Tag)
            {
                M00 = tdrd.Transform[0];
                M11 = tdrd.Transform[1];
                M20 = tdrd.Transform[2];
                M21 = tdrd.Transform[3];
            }
            else    // TAG_TRANSFORM
            {
                M00 = tdrd.Transform[0];
                M01 = tdrd.Transform[1];
                M10 = tdrd.Transform[2];
                M11 = tdrd.Transform[3];
                M20 = tdrd.Transform[4];
                M21 = tdrd.Transform[5];
            }

            return new Matrix(M00, M01, M10, M11, M20, M21);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Multibyte Encode if necessary a Transform Descriptor into the stream
        /// </summary>
        /// <param name="strm"></param>
        /// <param name="xform"></param>
        /// <param name="useDoubles"></param>
        /// <returns></returns>
        private uint EncodeTransformDescriptor(Stream strm, TransformDescriptor xform, bool useDoubles)
        {
            uint cbData = 0;

            // First encode the tag
            cbData = SerializationHelper.Encode(strm, (uint)xform.Tag);

            // Encode specially if transform denotes rotation
            if (KnownTagCache.KnownTagIndex.TransformRotate == xform.Tag)
            {
                uint angle = (uint)(xform.Transform[0] + 0.5f);

                cbData += SerializationHelper.Encode(strm, angle);
            }
            else
            {
                // samgeo - Presharp issue
                // Presharp gives a warning when local IDisposable variables are not closed
                // in this case, we can't call Dispose since it will also close the underlying stream
                // which still needs to be written to
#pragma warning disable 1634, 1691
#pragma warning disable 6518
                BinaryWriter bw = new BinaryWriter(strm);

                for (int i = 0; i < xform.Size; i++)
                {
                    // note that the binary writer changes serialization
                    //      lengths depending on the Write parameter cast
                    if (useDoubles)
                    {
                        bw.Write(xform.Transform[i]);
                        cbData += Native.SizeOfDouble;
                    }
                    else
                    {
                        bw.Write((float)xform.Transform[i]);
                        cbData += Native.SizeOfFloat;
                    }
                }
#pragma warning restore 6518
#pragma warning restore 1634, 1691
            }

            return cbData;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads and Decodes a Transfrom Descriptor Block from the stream. For information on how it is stored in the stream,
        /// please refer to the spec.
        /// </summary>
        /// <param name="strm"></param>
        /// <param name="tag"></param>
        /// <param name="cbSize"></param>
        /// <param name="useDoubles"></param>
        /// <param name="xform"></param>
        /// <returns></returns>
        private uint DecodeTransformBlock(Stream strm, KnownTagCache.KnownTagIndex tag, uint cbSize, bool useDoubles, out TransformDescriptor xform)
        {
            xform = new TransformDescriptor();
            xform.Tag = tag;

            uint cbRead = 0;
            uint cbTotal = cbSize;

            if (0 == cbSize)
                return 0;

            // samgeo - Presharp issue
            // Presharp gives a warning when local IDisposable variables are not closed
            // in this case, we can't call Dispose since it will also close the underlying stream
            // which still needs to be read from
#pragma warning disable 1634, 1691
#pragma warning disable 6518
            BinaryReader bw = new BinaryReader(strm);

            if (KnownTagCache.KnownTagIndex.TransformRotate == tag)
            {
                uint angle;

                cbRead = SerializationHelper.Decode(strm, out angle);
                if (cbRead > cbSize)
                    throw new ArgumentException(ISFDebugMessage("Invalid ISF data"),"strm");


                xform.Transform[0] = (double)angle;
                xform.Size = 1;
            }
            else
            {
                if (tag == KnownTagCache.KnownTagIndex.TransformIsotropicScale)
                {
                    xform.Size = 1;
                }
                else if (tag == KnownTagCache.KnownTagIndex.TransformAnisotropicScale || tag == KnownTagCache.KnownTagIndex.TransformTranslate)
                {
                    xform.Size = 2;
                }
                else if (tag == KnownTagCache.KnownTagIndex.TransformScaleAndTranslate)
                {
                    xform.Size = 4;
                }
                else
                {
                    xform.Size = 6;
                }

                if (useDoubles)
                {
                    cbRead = xform.Size * Native.SizeOfDouble;
                }
                else
                {
                    cbRead = xform.Size * Native.SizeOfFloat;
                }

                if (cbRead > cbSize)
                    throw new ArgumentException(ISFDebugMessage("Invalid ISF data"),"strm");


                for (int i = 0; i < xform.Size; i++)
                {
                    if (useDoubles)
                    {
                        xform.Transform[i] = bw.ReadDouble();
                    }
                    else
                    {
                        xform.Transform[i] = (double)bw.ReadSingle();
                    }
                }
            }

            return cbRead;
#pragma warning restore 6518
#pragma warning restore 1634, 1691
        }