示例#1
0
        public List <PageItem> Process(int Flags, byte[] RecordData)
        {
            MemoryStream _ms = null;
            BinaryReader _br = null;
            MemoryStream _fs = null;
            BinaryReader _fr = null;

            try
            {
                _fs = new MemoryStream(BitConverter.GetBytes(Flags));
                _fr = new BinaryReader(_fs);
                _fr.ReadByte();
                //Byte 2 is the real flags
                byte RealFlags = _fr.ReadByte();
                // 0 1 2 3 4 5 6 7
                // X X X X X X C S
                // if C = 1 Data int16 else float!
                bool Compressed  = ((RealFlags & (int)Math.Pow(2, 6)) == (int)Math.Pow(2, 6));
                bool BrushIsARGB = ((RealFlags & (int)Math.Pow(2, 7)) == (int)Math.Pow(2, 7));
                _ms = new MemoryStream(RecordData);
                _br = new BinaryReader(_ms);
                Brush b;
                if (BrushIsARGB)
                {
                    byte A, R, G, B;
                    B = _br.ReadByte();
                    G = _br.ReadByte();
                    R = _br.ReadByte();
                    A = _br.ReadByte();
                    b = new SolidBrush(Color.FromArgb(A, R, G, B));
                }
                else
                {
                    UInt32   BrushID = _br.ReadUInt32();
                    EMFBrush EMFb    = (EMFBrush)ObjectTable[(byte)BrushID];
                    b = EMFb.myBrush;
                }
                UInt32 NumberOfPoints = _br.ReadUInt32();
                if (Compressed)
                {
                    DoCompressed(NumberOfPoints, _br, b);
                }
                else
                {
                    DoFloat(NumberOfPoints, _br, b);
                }
                return(items);
            }
            finally
            {
                if (_br != null)
                {
                    _br.Close();
                }
                if (_ms != null)
                {
                    _ms.Dispose();
                }
                if (_fr != null)
                {
                    _fr.Close();
                }
                if (_fs != null)
                {
                    _fs.Dispose();
                }
            }
        }
        internal static EMFRecordObject getObject(int flags, byte[] RecordData)
        {
            MemoryStream _ms = null;
            BinaryReader _br = null;

            try
            {
                //Put the Flags into a stream and then use a binary Reader to read the Flags
                _ms = new MemoryStream(BitConverter.GetBytes(flags));
                _br = new BinaryReader(_ms);
                //ObjectID is least significant byte (which will be the first byte in the byte array due to Little Endian)
                byte Objectid = _br.ReadByte();
                //Object Type next...
                byte ObjectTyp = _br.ReadByte();
                //Don't know what to do if this object continues on the next one!
                bool ContinuesOnNextObject = ((ObjectTyp & 128) == 128);
                if (ContinuesOnNextObject)
                {
                    ObjectTyp ^= 128;
                }

                switch ((UInt16)ObjectTyp)
                {
                case (UInt16)EmfObjectType.invalid:
                    break;

                case (UInt16)EmfObjectType.brush:
                    EMFBrush Obrush = EMFBrush.getEMFBrush(RecordData);
                    Obrush.ObjectID = Objectid;
                    return(Obrush);

                case (UInt16)EmfObjectType.pen:
                    EMFPen OPen = EMFPen.getEMFPen(RecordData);
                    OPen.ObjectID = Objectid;
                    return(OPen);

                case (UInt16)EmfObjectType.path:
                    break;

                case (UInt16)EmfObjectType.region:
                    break;

                case (UInt16)EmfObjectType.image:
                    break;

                case (UInt16)EmfObjectType.font:
                    EMFFont OFont = EMFFont.getEMFFont(RecordData);
                    OFont.ObjectID = Objectid;
                    return(OFont);

                case (UInt16)EmfObjectType.stringformat:
                    EMFStringFormat Ostringformat = EMFStringFormat.getEMFStringFormat(RecordData);
                    Ostringformat.ObjectID = Objectid;
                    return(Ostringformat);

                case (UInt16)EmfObjectType.ImageAttributes:
                    break;

                case (UInt16)EmfObjectType.CustomLineType:
                    break;
                }
                return(null);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (_br != null)
                {
                    _br.Close();
                }
                if (_ms != null)
                {
                    _ms.Dispose();
                }
            }
        }
示例#3
0
        private EMFPen(byte[] RecordData)
        {
            ObjectType = EmfObjectType.pen;

            //put the Data into a stream and use a binary reader to read the data
            MemoryStream _ms = new MemoryStream(RecordData);
            BinaryReader _br = new BinaryReader(_ms);

            myPen = new Pen(Color.Black); //default just for now..
            UInt32 Version = _br.ReadUInt32();
            UInt32 Unknown = _br.ReadUInt32();
            UInt32 Flags   = _br.ReadUInt32();

            _br.ReadUInt32();  //PenUnit NOT SURE...
            myPen.Width = _br.ReadSingle();
            //Rest of data depends on Flags!
            byte[]   Transform;
            Single[] DashLengths;
            Single[] CompoundLineData;

            //For now this will be nowhere near fully implemented... Just getting what I need to get it to work!
            if ((Flags & (UInt32)PenDataFlags.PenDataTransform) == (UInt32)PenDataFlags.PenDataTransform)
            {
                //Read the next 24 bytes... A PenDataTransformObject
                Transform = _br.ReadBytes(24);
            }
            if ((Flags & (UInt32)PenDataFlags.PenDataStartCap) == (UInt32)PenDataFlags.PenDataStartCap)
            {
                myPen.StartCap = (System.Drawing.Drawing2D.LineCap)_br.ReadInt32();
            }
            if ((Flags & (UInt32)PenDataFlags.PenDataEndCap) == (UInt32)PenDataFlags.PenDataEndCap)
            {
                myPen.EndCap = (System.Drawing.Drawing2D.LineCap)_br.ReadInt32();
            }
            if ((Flags & (UInt32)PenDataFlags.PenDataJoin) == (UInt32)PenDataFlags.PenDataJoin)
            {
                myPen.LineJoin = (System.Drawing.Drawing2D.LineJoin)_br.ReadUInt32();
            }
            if ((Flags & (UInt32)PenDataFlags.PenDataMiterLimit) == (UInt32)PenDataFlags.PenDataMiterLimit)
            {
                myPen.MiterLimit = _br.ReadSingle();
            }
            if ((Flags & (UInt32)PenDataFlags.PenDataLineStyle) == (UInt32)PenDataFlags.PenDataLineStyle)
            {
                myPen.DashStyle = (System.Drawing.Drawing2D.DashStyle)_br.ReadInt32();
            }
            if ((Flags & (UInt32)PenDataFlags.PenDataDashedLineCap) == (UInt32)PenDataFlags.PenDataDashedLineCap)
            {
                myPen.DashCap = (System.Drawing.Drawing2D.DashCap)_br.ReadUInt32();
            }
            if ((Flags & (UInt32)PenDataFlags.PenDataDashedLineOffset) == (UInt32)PenDataFlags.PenDataDashedLineOffset)
            {
                myPen.DashOffset = _br.ReadSingle();
            }
            if ((Flags & (UInt32)PenDataFlags.PenDataDashedLine) == (UInt32)PenDataFlags.PenDataDashedLine)
            {
                //Woo-hoo... A Variable length field!...
                UInt32 DashedLineDataSize = _br.ReadUInt32();//Number of floats to read...
                DashLengths = new Single[DashedLineDataSize];
                for (int i = 0; i < DashedLineDataSize; i++)
                {
                    DashLengths[i] = _br.ReadSingle();
                }
                myPen.DashPattern = DashLengths;
            }

            if ((Flags & (UInt32)PenDataFlags.PenDataNonCenter) == (UInt32)PenDataFlags.PenDataNonCenter)
            {
                myPen.Alignment = (System.Drawing.Drawing2D.PenAlignment)_br.ReadInt32();
            }
            if ((Flags & (UInt32)PenDataFlags.PenDataCompoundLine) == (UInt32)PenDataFlags.PenDataCompoundLine)
            {
                //Joy...more variable length...
                UInt32 CompoundLineDataSize = _br.ReadUInt32();//Number of floats to read...
                CompoundLineData = new Single[CompoundLineDataSize];
                for (int i = 0; i < CompoundLineDataSize; i++)
                {
                    CompoundLineData[i] = _br.ReadSingle();
                }
                myPen.CompoundArray = CompoundLineData;
            }

            if ((Flags & (UInt32)PenDataFlags.PenDataCustomStartCap) == (UInt32)PenDataFlags.PenDataCustomStartCap)
            {
                //Again...variable length...Hope we don't get this one any time soon... I'm not implementing it!
                UInt32 CustomStartCapSize = _br.ReadUInt32();
                _br.ReadBytes((int)CustomStartCapSize);
            }
            if ((Flags & (UInt32)PenDataFlags.PenDataCustomEndCap) == (UInt32)PenDataFlags.PenDataCustomEndCap)
            {
                //Again...variable length...Hope we don't get this one any time soon... I'm not implementing it either!
                UInt32 CustomEndCapSize = _br.ReadUInt32();
                _br.ReadBytes((int)CustomEndCapSize);
            }
            //Ok - the rest of the bytes are going to be a brush object
            EMFBrush myBrush = EMFBrush.getEMFBrush(_br.ReadBytes((int)(_br.BaseStream.Length - _br.BaseStream.Position)));

            //Now we can make a pen for storage...
            myPen.Brush = myBrush.myBrush;
        }
示例#4
0
        public List <PageItem> Process(int Flags, byte[] RecordData)
        {
            MemoryStream _ms = null;
            BinaryReader _br = null;
            MemoryStream _fs = null;
            BinaryReader _fr = null;

            try
            {
                _fs = new MemoryStream(BitConverter.GetBytes(Flags));
                _fr = new BinaryReader(_fs);
                _fr.ReadByte();
                //Byte 1 will be ignored
                byte RealFlags = _fr.ReadByte();
                //Byte 2 will be brushtype
                // 0 1 2 3 4 5 6 7
                // X X X X X X C S
                // if S = 1 brushID is an ARGBobject, else its an Index to object table
                // if C = 1 int16, 0 = Points are Float (ignore P)
                bool Compressed  = ((RealFlags & (int)Math.Pow(2, 6)) == (int)Math.Pow(2, 6));
                bool BrushIsARGB = ((RealFlags & (int)Math.Pow(2, 7)) == (int)Math.Pow(2, 7));
                _ms = new MemoryStream(RecordData);
                _br = new BinaryReader(_ms);
                Brush b;
                if (BrushIsARGB)
                {
                    byte A, R, G, B;
                    B = _br.ReadByte();
                    G = _br.ReadByte();
                    R = _br.ReadByte();
                    A = _br.ReadByte();
                    b = new SolidBrush(Color.FromArgb(A, R, G, B));
                }
                else
                {
                    UInt32   BrushID = _br.ReadUInt32();
                    EMFBrush EMFb    = (EMFBrush)ObjectTable[(byte)BrushID];
                    b = EMFb.myBrush;
                }
                if (Compressed)
                {
                    Int16 Xp  = _br.ReadInt16();
                    Int16 Yp  = _br.ReadInt16();
                    Int16 Wid = _br.ReadInt16();
                    Int16 Hgt = _br.ReadInt16();
                    DoInstructions(Xp, Yp, Wid, Hgt, b);
                }
                else
                {
                    Single Xp  = _br.ReadSingle();
                    Single Yp  = _br.ReadSingle();
                    Single Wid = _br.ReadSingle();
                    Single Hgt = _br.ReadSingle();
                    DoInstructions(Xp, Yp, Wid, Hgt, b);
                }
                return(items);
            }
            finally
            {
                if (_br != null)
                {
                    _br.Close();
                }
                if (_ms != null)
                {
                    _ms.Dispose();
                }
                if (_fr != null)
                {
                    _fr.Close();
                }
                if (_fs != null)
                {
                    _fs.Dispose();
                }
            }
        }
示例#5
0
        public List <PageItem> Process(int Flags, byte[] RecordData)
        {
            MemoryStream _ms = null;
            BinaryReader _br = null;
            MemoryStream _fs = null;
            BinaryReader _fr = null;

            try
            {
                _fs = new MemoryStream(BitConverter.GetBytes(Flags));
                _fr = new BinaryReader(_fs);
                //Byte 1 will be ObjectID - a font in the object table
                byte ObjectID = _fr.ReadByte();
                //Byte 2 is the real flags
                byte RealFlags = _fr.ReadByte();
                // 0 1 2 3 4 5 6 7
                // X X X X X X X S
                // if S = type of brush - if S then ARGB, else a brush object in object table

                _ms = new MemoryStream(RecordData);
                _br = new BinaryReader(_ms);
                bool  BrushIsARGB = ((RealFlags & (int)Math.Pow(2, 7)) == (int)Math.Pow(2, 7));
                Brush b;
                if (BrushIsARGB)
                {
                    byte A, R, G, B;
                    B = _br.ReadByte();
                    G = _br.ReadByte();
                    R = _br.ReadByte();
                    A = _br.ReadByte();
                    b = new SolidBrush(Color.FromArgb(A, R, G, B));
                }
                else
                {
                    UInt32   BrushID = _br.ReadUInt32();
                    EMFBrush EMFb    = (EMFBrush)ObjectTable[(byte)BrushID];
                    b = EMFb.myBrush;
                }

                UInt32 FormatID     = _br.ReadUInt32(); // Index of Optional stringFormatobject in Object Table...
                UInt32 StringLength = _br.ReadUInt32();
                //bounding of string...
                Single recX      = _br.ReadSingle();
                Single recY      = _br.ReadSingle();
                Single recWidth  = _br.ReadSingle();
                Single recHeight = _br.ReadSingle();
                //Array of Chars...
                char[] StringData             = new char[StringLength];
                System.Text.UnicodeEncoding d = new System.Text.UnicodeEncoding();
                d.GetChars(_br.ReadBytes((int)StringLength * 2), 0, (int)StringLength * 2, StringData, 0);
                EMFFont      EF = (EMFFont)ObjectTable[(byte)ObjectID];
                Font         f  = EF.myFont;
                StringFormat sf;
                if (ObjectTable.Contains((byte)FormatID))
                {
                    EMFStringFormat ESF = (EMFStringFormat)ObjectTable[(byte)FormatID];
                    sf = ESF.myStringFormat;
                }
                else
                {
                    sf = new StringFormat();
                }

                DoInstructions(f, sf, b, recX, recY, recWidth, recHeight, new String(StringData));
                return(items);
            }
            finally
            {
                if (_br != null)
                {
                    _br.Close();
                }
                if (_ms != null)
                {
                    _ms.Dispose();
                }
                if (_fr != null)
                {
                    _fr.Close();
                }
                if (_fs != null)
                {
                    _fs.Dispose();
                }
            }
        }