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(); } } }
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; }