/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// playrecordcallback.BeginInvoke(recordType, flags, dataSize, recordData, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this PlayRecordCallback playrecordcallback, EmfPlusRecordType recordType, Int32 flags, Int32 dataSize, IntPtr recordData, AsyncCallback callback) { if (playrecordcallback == null) { throw new ArgumentNullException("playrecordcallback"); } return(playrecordcallback.BeginInvoke(recordType, flags, dataSize, recordData, callback, null)); }
private bool method_5(EmfPlusRecordType A_0, int A_1, int A_2, IntPtr A_3, PlayRecordCallback A_4) { byte[] destination = new byte[A_2]; if (A_3 != IntPtr.Zero) { Marshal.Copy(A_3, destination, 0, A_2); } this.metafile_0.PlayRecord(A_0, A_1, A_2, destination); return(true); }
internal bool MetafileCallback(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { if (!data.Equals(IntPtr.Zero)) { byte[] RecordData = new byte[dataSize]; Marshal.Copy(data, RecordData, 0, dataSize); ProcessRecord(flags, recordType, RecordData); } return true; }
private bool MetafileCallback(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { byte[] dataArray = null; if (data != IntPtr.Zero) { // Copy the unmanaged record to a managed byte buffer // that can be used by PlayRecord. dataArray = new byte[dataSize]; Marshal.Copy(data, dataArray, 0, dataSize); } metafile_.PlayRecord(recordType, flags, dataSize, dataArray); return(true); }
/// <summary> /// Provides a callback method for the EnumerateMetafile method. /// </summary> /// <param name="recordType">Member of the EmfPlusRecordType enumeration that specifies the type of metafile record.</param> /// <param name="flags">Set of flags that specify attributes of the record.</param> /// <param name="dataSize">Number of bytes in the record data.</param> /// <param name="data">Pointer to a buffer that contains the record data.</param> /// <param name="callbackData">Not used.</param> /// <returns></returns> private bool MetafileCallback(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { byte[] dataArray = null; if (data != IntPtr.Zero) { // 将 data 所对应的内存指针所对应的数据从内存中复制出来 // Copy the unmanaged record to a managed byte buffer // that can be used by PlayRecord. dataArray = new byte[dataSize]; // Copies data from a managed array to an unmanaged memory pointer, or from an unmanaged memory pointer to a managed array. SysMarshal.Copy(data, dataArray, 0, dataSize); } // 将 矢量图中的这一个小图元显示在 pictureBox1 的绘图面板 Graphics 中 metafile1.PlayRecord(recordType, flags, dataSize, dataArray); // Plays an individual metafile record. return(true); }
private bool MetafileCallback(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { byte[] dataArray = null; if (data != IntPtr.Zero) { // Copy the unmanaged record to a managed byte buffer // that can be used by PlayRecord. dataArray = new byte[dataSize]; Marshal.Copy(data, dataArray, 0, dataSize); } //m_mf.PlayRecord(recordType, flags, dataSize, dataArray); DecodeRecord(recordType, flags, dataArray); return true; }
bool EnumMetafileProc(EmfPlusRecordType eprt, int iFlags, int iDataSize, IntPtr ipData, PlayRecordCallback prc) { strwrite.Write("{0} ({1}, {2})", eprt, iFlags, iDataSize); if (iDataSize > 0) { byte[] abyData = new Byte[iDataSize]; Marshal.Copy(ipData, abyData, 0, iDataSize); foreach (byte by in abyData) { strwrite.Write(" {0:X2}", by); } } strwrite.WriteLine(); return(true); }
private bool EnumMetaCB(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { string str = ""; // Play only EmfPlusRecordType.FillEllipse records. if (recordType == EmfPlusRecordType.FillEllipse || recordType == EmfPlusRecordType.FillRects || recordType == EmfPlusRecordType.DrawEllipse || recordType == EmfPlusRecordType.DrawRects) { str = "Record type:" + recordType.ToString() + ", Flags:" + flags.ToString() + ", DataSize:" + dataSize.ToString() + ", Data:" + data.ToString(); MessageBox.Show(str); } return(true); }
protected bool MetafileCallback( EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { byte[] dataArray = null; if (data != IntPtr.Zero) { dataArray = new byte[dataSize]; Marshal.Copy(data, dataArray, 0, dataSize); if (recordType == EmfPlusRecordType.WmfEscape && dataSize >= Marshal.SizeOf(m_wmfHeader) && !m_succeeded) { m_wmfHeader = (wmfHeader)RawDeserialize(dataArray, 0, m_wmfHeader.GetType()); if (m_wmfHeader.strSig.Equals(m_strSig, StringComparison.CurrentCultureIgnoreCase)) { System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); string strCompanyInfo = enc.GetString(dataArray, Marshal.SizeOf(m_wmfHeader), m_wmfHeader.iDataLen); int iNull = strCompanyInfo.IndexOf('\0'); if (iNull >= 0) { int mtefStart = Marshal.SizeOf(m_wmfHeader) + iNull + 1; iMTEF_Length = m_wmfHeader.iDataLen; bMTEF = new byte[iMTEF_Length]; Array.Copy(dataArray, mtefStart, bMTEF, 0, iMTEF_Length); m_succeeded = true; } } } } m_metafile.PlayRecord(recordType, flags, dataSize, dataArray); return(true); }
internal bool MetafileCallback(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { if (!data.Equals(IntPtr.Zero)) { byte[] RecordData = new byte[dataSize]; Marshal.Copy(data, RecordData, 0, dataSize); ProcessRecord(flags, recordType, RecordData); } return(true); }
private bool MetafileCallback(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { byte[] dataArray = null; if (data != IntPtr.Zero) { dataArray = new byte[dataSize]; Marshal.Copy(data, dataArray, 0, dataSize); if (recordType == EmfPlusRecordType.DrawString) { try { int stringLength = BitConverter.ToInt32(dataArray, 8) * 2; string str = Encoding.Unicode.GetString(dataArray, 28, stringLength); ParsedDrawStrings.Add(str); if (extractTextMode) { GuessWhiteSpaces(); parsedExpectedText += str; } } catch { if (IsParseFailedLoggingEnabled) { ParseFailedRecords.Add(new KeyValuePair <EmfPlusRecordType, byte[]>(recordType, dataArray)); } } } else if (recordType == EmfPlusRecordType.EmfSmallTextOut) { var x = BitConverter.ToInt32(dataArray, 0); var y = BitConverter.ToInt32(dataArray, 4); var cChars = BitConverter.ToInt32(dataArray, 8); var fuOptions = BitConverter.ToInt32(dataArray, 12); var iGraphicsMode = BitConverter.ToInt32(dataArray, 16); var exScale = BitConverter.ToDouble(dataArray, 20); var eyScale = BitConverter.ToDouble(dataArray, 24); var maybeBound = BitConverter.ToInt32(dataArray, 28); int num_chars = BitConverter.ToInt32(dataArray, 28); try { var maybeText = BitConverter.ToChar(dataArray, 28); ParsedSmallTextOuts.Add(maybeText); if (extractTextMode) { GuessWhiteSpaces(); parsedExpectedText += maybeText; } } catch { if (IsParseFailedLoggingEnabled) { ParseFailedRecords.Add(new KeyValuePair <EmfPlusRecordType, byte[]>(recordType, dataArray)); } } } else if (recordType == EmfPlusRecordType.EmfExtTextOutW) { string txt; try { var length = BitConverter.ToUInt32(dataArray, 36); var offString = BitConverter.ToUInt32(dataArray, 40); var chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = BitConverter.ToChar(dataArray, (int)offString - 8 + i * 2); } txt = new string(chars); if (txt.Replace(" ", "").Length > 0) { ParsedExtTextOutWs.Add(txt); if (extractTextMode) { GuessWhiteSpaces(); parsedExpectedText += txt; } } } catch { if (IsParseFailedLoggingEnabled) { ParseFailedRecords.Add(new KeyValuePair <EmfPlusRecordType, byte[]>(recordType, dataArray)); } } } else { if (extractTextMode) { betweenTextCommands.Add(recordType); } } } _loadedMetafile.PlayRecord(recordType, flags, dataSize, dataArray); return(true); }
private bool FindReplaceColorCallbackProc(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { switch (recordType) { case EmfPlusRecordType.EmfCreateBrushIndirect: if (!replaceColorFound) { // Copy the unmanaged record to a managed byte buffer that can be used by PlayRecord. if (dataSize > metafileDataSize) { metafileDataSize = dataSize; metafileData = new byte[metafileDataSize]; } Marshal.Copy(data, metafileData, 0, dataSize); // Get the RGB color components of the brush replaceColor = Color.FromArgb(metafileData[8], metafileData[9], metafileData[10]); replaceColorFound = true; } break; default: // Nothing to do break; } // No need to play the record as we only search a color to replace //((Metafile)image).PlayRecord(recordType, flags, dataSize, dataArray); //note that every record gets played even if the dataArray is empty return true; }
private bool ReplaceBrushCallbackProc(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { try { if (data == IntPtr.Zero) ((Metafile) image).PlayRecord(recordType, flags, 0, null); else { if (dataSize > metafileDataSize) { metafileDataSize = dataSize; metafileData = new byte[metafileDataSize]; } // Copy the unmanaged record to a managed byte buffer that can be used by PlayRecord. Marshal.Copy(data, metafileData, 0, dataSize); // Adjust the color switch (recordType) { case EmfPlusRecordType.EmfCreateBrushIndirect: // This type of record only appears in WMF and 'classic' EMF files, not in EMF+ files. // Get color of current brush if (!replaceColorFound) { Buffers.SetByte(metafileData, 8, FillStyle.BaseColorStyle.Color.R); Buffers.SetByte(metafileData, 9, FillStyle.BaseColorStyle.Color.G); Buffers.SetByte(metafileData, 10, FillStyle.BaseColorStyle.Color.B); Buffers.SetByte(metafileData, 11, FillStyle.BaseColorStyle.Color.A); replaceColorFound = true; } break; default: /* nothing to do */ break; } ((Metafile) image).PlayRecord(recordType, flags, dataSize, metafileData); } } catch (Exception exc) { Console.WriteLine("Error while playing metafile record: {0}", exc.Message); } return true; }
// Metafile 回调 protected bool MetafileCallback(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { byte[] dataArray = null; if (data != IntPtr.Zero) { dataArray = new byte[dataSize]; Marshal.Copy(data, dataArray, 0, dataSize); } _printMetafile.PlayRecord(recordType, flags, dataSize, dataArray); return(true); }
private static bool MetafileResetCallback(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData) { byte[] dataArray = null; if (data != IntPtr.Zero) { dataArray = new byte[dataSize]; Marshal.Copy(data, dataArray, 0, dataSize); if (recordType == EmfPlusRecordType.EmfSetWindowExtEx) { bBounds = dataArray; } } return(true); }
private static bool DelFunc(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr recordData, PlayRecordCallback callbackData) { byte[] numArray = new byte[dataSize]; if (recordData != IntPtr.Zero) { Marshal.Copy(recordData, numArray, 0, dataSize); } EmfPlusRecordType emfPlusRecordType = recordType; if (emfPlusRecordType <= EmfPlusRecordType.DrawArc) { if (emfPlusRecordType == EmfPlusRecordType.EmfHeader) { MetaForm.imgWidth = MetaForm.EmfWidthToWidth((int)numArray[24], (int)numArray[25]); MetaForm.imgHeight = MetaForm.EmfWidthToWidth((int)numArray[28], (int)numArray[29]); MetaForm.cn_obj = (int)MetaForm.Format_Size2(numArray[41], numArray[42]); } else { switch (emfPlusRecordType) { case EmfPlusRecordType.Object: { if ((int)numArray.Length >= 32 || numArray[4] > 1) { if (numArray[4] != 0) { MetaForm.SplitRecObject(numArray); return(true); } if ((int)numArray.Length == 32) { MetaForm.r = numArray[30]; MetaForm.g = numArray[29]; MetaForm.b = numArray[28]; } if ((int)numArray.Length > 32) { MetaForm.r = numArray[34]; MetaForm.g = numArray[33]; MetaForm.b = numArray[32]; } if (numArray[8] == 0) { MetaForm.line_style = 0; } else { MetaForm.line_style = numArray[20]; } MetaForm.text_size = MetaForm.FormatSize((int)numArray[6], (int)numArray[7]); MetaForm.obj_width = MetaForm.FormatSize((int)numArray[18], (int)numArray[19]); MetaForm.text_style = numArray[12]; break; } else { MetaForm.r = numArray[14]; MetaForm.g = numArray[13]; MetaForm.b = numArray[12]; MetaForm.hatch_style = numArray[8]; break; } } case EmfPlusRecordType.Clear: case EmfPlusRecordType.FillPie: case EmfPlusRecordType.DrawPie: { return(true); } case EmfPlusRecordType.FillRects: { if (numArray[3] == 255) { MetaForm.r = numArray[2]; MetaForm.g = numArray[1]; MetaForm.b = numArray[0]; } MetaForm.DrawRectangle(numArray, 8, true); MetaForm.hatch_style = -1; break; } case EmfPlusRecordType.DrawRects: { MetaForm.DrawRectangle(numArray, 4, false); break; } case EmfPlusRecordType.FillPolygon: { MetaForm.DrawPolyLine(numArray, 4, true, false); MetaForm.hatch_style = -1; break; } case EmfPlusRecordType.DrawLines: { if (numArray[0] != 2) { MetaForm.DrawPolyLine(numArray, 0, false, false); break; } else { MetaForm.DrawLine(numArray, 4); break; } } case EmfPlusRecordType.FillEllipse: { if (numArray[3] != 0) { MetaForm.r = numArray[2]; MetaForm.g = numArray[1]; MetaForm.b = numArray[0]; } if (numArray[8] != numArray[10]) { MetaForm.DrawEllipse(numArray, 4, true); } else { MetaForm.DrawCircle(numArray, 4, true); } MetaForm.hatch_style = -1; break; } case EmfPlusRecordType.DrawEllipse: { if (numArray[4] != numArray[6]) { MetaForm.DrawEllipse(numArray, 0, false); break; } else { MetaForm.DrawCircle(numArray, 0, false); break; } } case EmfPlusRecordType.DrawArc: { if (numArray[12] != numArray[14]) { MetaForm.DrawEllArc(numArray); break; } else { MetaForm.DrawArc(numArray); break; } } default: { return(true); } } } } else if (emfPlusRecordType == EmfPlusRecordType.DrawBeziers) { MetaForm.DrawPolyLine(numArray, 0, false, true); } else if (emfPlusRecordType == EmfPlusRecordType.DrawString) { MetaForm.r = numArray[2]; MetaForm.g = numArray[1]; MetaForm.b = numArray[0]; MetaForm.DrawString(numArray); } else { switch (emfPlusRecordType) { case EmfPlusRecordType.ResetWorldTransform: { MetaForm.transform = false; break; } case EmfPlusRecordType.MultiplyWorldTransform: { return(true); } case EmfPlusRecordType.TranslateWorldTransform: { MetaForm.transform = true; MetaForm.transPoint.X = MetaForm.FormatSize((int)numArray[2], (int)numArray[3]); MetaForm.transPoint.Y = MetaForm.FormatSize((int)numArray[6], (int)numArray[7]); break; } default: { return(true); } } } return(true); }