/// <summary> /// Start parsing the loaded data. Cannot be executed when EMF is not loaded. Every Parsed Datas will be stored in "Parsed(EMFRecordTypeName)". /// </summary> /// <returns></returns> public bool ParseStart() { if (IsLoaded == false) { throw new Exception("EMF File has not Loaded yet."); } ParsedExtTextOutWs.Clear(); ParsedSmallTextOuts.Clear(); ParsedDrawStrings.Clear(); ParseFailedRecords.Clear(); parsedExpectedText = ""; try { dummy.EnumerateMetafile(_loadedMetafile, new Point(0, 0), metafileDelegate); return(true); } catch { throw; } }
/// <summary> /// Experimental : Start parsing and returns string. Every linebreak and space will be determined by Linebreak and Space array properties. /// </summary> /// <returns></returns> public string GetCombinedStringFromLoadedMetaFile() { if (IsLoaded == false) { throw new Exception("EMF File has not Loaded yet."); } ParsedExtTextOutWs.Clear(); ParsedSmallTextOuts.Clear(); ParsedDrawStrings.Clear(); ParseFailedRecords.Clear(); parsedExpectedText = ""; extractTextMode = true; try { dummy.EnumerateMetafile(_loadedMetafile, new Point(0, 0), metafileDelegate); return(parsedExpectedText); } catch { throw; } }
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); }