//--------------------------------------------------------------------// // M e t h o d // // p a r s e B u f f e r // //--------------------------------------------------------------------// // // // Parse provided buffer, assuming that the current print language is // // PJL. // // // //--------------------------------------------------------------------// public Boolean parseBuffer( Byte [] buf, ref Int32 fileOffset, ref Int32 bufRem, ref Int32 bufOffset, ref ToolCommonData.ePrintLang crntPDL, ref Boolean endReached, PrnParseLinkData linkData, PrnParseOptions options, DataTable table) { Boolean seqInvalid; //----------------------------------------------------------------// // // // Initialise. // // // //----------------------------------------------------------------// _buf = buf; _linkData = linkData; _options = options; _table = table; _fileOffset = fileOffset; _analysisLevel = _linkData.AnalysisLevel; seqInvalid = false; //----------------------------------------------------------------// _indxOffsetFormat = _options.IndxGenOffsetFormat; _options.getOptCharSet(ref _indxCharSetName, ref _indxCharSetSubAct, ref _valCharSetSubCode); _endOffset = _options.ValCurFOffsetEnd; _showPML = _options.FlagPMLWithinPJL; //----------------------------------------------------------------// if (linkData.isContinuation()) { seqInvalid = parseContinuation(ref bufRem, ref bufOffset, ref crntPDL, ref endReached); } else { seqInvalid = parseSequences(ref bufRem, ref bufOffset, ref crntPDL, ref endReached); } return(seqInvalid); }
//--------------------------------------------------------------------// // M e t h o d // // g e t R o w C o l o u r S t y l e D a t a // //--------------------------------------------------------------------// // // // Get references to colour style data for colour coded analysis. // // // //--------------------------------------------------------------------// private static void getRowColourStyleData( PrnParseOptions options, ref String[] classes, ref String[] clrBack, ref String[] clrFore) { Int32 indxClrBack; Int32 indxClrFore; PropertyInfo[] stdClrsPropertyInfo = null; Boolean flagClrMapUseClr = false; PropertyInfo pInfoBack, pInfoFore; Int32 ctClrMapRowTypes = PrnParseRowTypes.getCount(); Int32 ctClrMapStdClrs = 0; Int32[] indxClrMapBack = new Int32[ctClrMapRowTypes]; Int32[] indxClrMapFore = new Int32[ctClrMapRowTypes]; options.getOptClrMap(ref flagClrMapUseClr, ref indxClrMapBack, ref indxClrMapFore); options.getOptClrMapStdClrs(ref ctClrMapStdClrs, ref stdClrsPropertyInfo); //----------------------------------------------------------------// for (Int32 i = 0; i < ctClrMapRowTypes; i++) { String rowType = Enum.GetName(typeof(PrnParseRowTypes.eType), i); indxClrBack = indxClrMapBack[i]; indxClrFore = indxClrMapFore[i]; pInfoBack = stdClrsPropertyInfo[indxClrBack] as PropertyInfo; pInfoFore = stdClrsPropertyInfo[indxClrFore] as PropertyInfo; classes[i] = rowType; clrBack[i] = pInfoBack.Name; clrFore[i] = pInfoFore.Name; } }
//--------------------------------------------------------------------// // M e t h o d // // v i e w F i l e // //--------------------------------------------------------------------// // // // Open print file and show content. // // // //--------------------------------------------------------------------// public Boolean viewFile(String prnFilename, PrnParseOptions options, DataTable table) { Boolean OK = true; Boolean ipOpen = false; ipOpen = openInputPrn(prnFilename, ref _fileSize); if (!ipOpen) { OK = false; } else { viewFileAction(options, table); closeInputPrn(); } return(OK); }
//--------------------------------------------------------------------// // M e t h o d // // i n i t i a l i s e // //--------------------------------------------------------------------// // // // Initialise 'target' data. // // // //--------------------------------------------------------------------// private void initialise() { //----------------------------------------------------------------// // // // Populate form. // // // //----------------------------------------------------------------// btnGenerate.Content = "Generate overlay"; _options = new PrnParseOptions(); // need a dummy one // grpOverlay.Visibility = Visibility.Hidden; grpProgress.Visibility = Visibility.Hidden; btnGenerate.Visibility = Visibility.Hidden; btnSaveReport.Visibility = Visibility.Hidden; //----------------------------------------------------------------// // // // Reinstate settings from persistent storage. // // // //----------------------------------------------------------------// metricsLoad(); txtPrnFilename.Text = _prnFilename; txtPCLMacroId.Text = _macroIdPCL.ToString(); txtPCLXLStreamName.Text = _streamNamePCLXL; rbPCLOvlEnc.IsChecked = _flagOvlEncPCL; rbPCLXLOvlEnc.IsChecked = _flagOvlEncPCLXL; chkPCLRestoreCursor.IsChecked = _flagRestoreCursorPCL; chkPCLXLRestoreGS.IsChecked = _flagRestoreGSPCLXL; if (_flagOvlEncPCL) { lbPCLMacroId.Visibility = Visibility.Visible; txtPCLMacroId.Visibility = Visibility.Visible; } else { lbPCLMacroId.Visibility = Visibility.Hidden; txtPCLMacroId.Visibility = Visibility.Hidden; } if (_flagOvlEncPCLXL) { lbPCLXLStreamName.Visibility = Visibility.Visible; txtPCLXLStreamName.Visibility = Visibility.Visible; } else { lbPCLXLStreamName.Visibility = Visibility.Hidden; txtPCLXLStreamName.Visibility = Visibility.Hidden; } //----------------------------------------------------------------// txtPCLOvlFilename.Text = _ovlFilenamePCL; txtPCLXLOvlFilename.Text = _ovlFilenamePCLXL; //----------------------------------------------------------------// Int32 ctRowTypes = PrnParseRowTypes.getCount(); _indxClrMapBack = new Int32[ctRowTypes]; _indxClrMapFore = new Int32[ctRowTypes]; _options.getOptClrMap(ref _flagClrMapUseClr, ref _indxClrMapBack, ref _indxClrMapFore); _options.getOptClrMapStdClrs(ref _ctClrMapStdClrs, ref _stdClrsPropertyInfo); //----------------------------------------------------------------// initialiseGridProgress(); }
//--------------------------------------------------------------------// // F i e l d s // // Class variables. // // // //--------------------------------------------------------------------// //--------------------------------------------------------------------// // M e t h o d // // g e n e r a t e // //--------------------------------------------------------------------// // // // Generate the report. // // // //--------------------------------------------------------------------// public static void generate( ToolPrnAnalyse.eInfoType indxInfoType, ReportCore.eRptFileFmt rptFileFmt, DataTable table, String prnFilename, Int64 fileSize, Boolean flagOffsetHex, PrnParseOptions options) { Object stream = null; Object writer = null; Boolean OK = false; Int32 reportSize; String fileExt; String saveFilename = null; if (rptFileFmt == ReportCore.eRptFileFmt.html) { fileExt = "html"; } else if (rptFileFmt == ReportCore.eRptFileFmt.xml) { fileExt = "xml"; } else { fileExt = "txt"; } if (indxInfoType == ToolPrnAnalyse.eInfoType.Analysis) { saveFilename = prnFilename + "_analysis." + fileExt; OK = ReportCore.docOpen(rptFileFmt, ref saveFilename, ref stream, ref writer); if (OK) { Int32 ctClrMapRowTypes = PrnParseRowTypes.getCount(); Boolean useClr = options.FlagClrMapUseClr; reportSize = table.Rows.Count; if (useClr) { String[] rowClasses = new String[ctClrMapRowTypes]; String[] rowClrBack = new String[ctClrMapRowTypes]; String[] rowClrFore = new String[ctClrMapRowTypes]; getRowColourStyleData(options, ref rowClasses, ref rowClrBack, ref rowClrFore); ReportCore.docInitialise(rptFileFmt, writer, true, false, ctClrMapRowTypes, rowClasses, rowClrBack, rowClrFore); } else { ReportCore.docInitialise(rptFileFmt, writer, true, false, 0, null, null, null); } reportHeader(indxInfoType, rptFileFmt, writer, prnFilename, fileSize, reportSize); reportBodyAnalysis(rptFileFmt, writer, table, flagOffsetHex); ReportCore.docFinalise(rptFileFmt, writer); ReportCore.docClose(rptFileFmt, stream, writer); } } else if (indxInfoType == ToolPrnAnalyse.eInfoType.Content) { saveFilename = prnFilename + "_content." + fileExt; OK = ReportCore.docOpen(rptFileFmt, ref saveFilename, ref stream, ref writer); if (OK) { reportSize = table.Rows.Count; ReportCore.docInitialise(rptFileFmt, writer, true, false, 0, null, null, null); reportHeader(indxInfoType, rptFileFmt, writer, prnFilename, fileSize, reportSize); reportBodyContent(rptFileFmt, writer, table, flagOffsetHex); ReportCore.docFinalise(rptFileFmt, writer); ReportCore.docClose(rptFileFmt, stream, writer); } } else if (indxInfoType == ToolPrnAnalyse.eInfoType.Statistics) { saveFilename = prnFilename + "_statistics." + fileExt; OK = ReportCore.docOpen(rptFileFmt, ref saveFilename, ref stream, ref writer); if (OK) { reportSize = table.Rows.Count; ReportCore.docInitialise(rptFileFmt, writer, true, false, 0, null, null, null); reportHeader(indxInfoType, rptFileFmt, writer, prnFilename, fileSize, reportSize); reportBodyStatistics(rptFileFmt, writer, table); ReportCore.docFinalise(rptFileFmt, writer); ReportCore.docClose(rptFileFmt, stream, writer); } } }
//--------------------------------------------------------------------// // M e t h o d // // a n a l y s e F o n t H d d r // //--------------------------------------------------------------------// // // // Provide an interpretation of the contents of a PCL XL soft font // // header. // // // //--------------------------------------------------------------------// public Boolean analyseFontHddr(Int32 hddrLen, Byte [] buf, Int32 fileOffset, ref Int32 bufRem, ref Int32 bufOffset, PrnParseLinkData linkData, PrnParseOptions options, DataTable table) { Int32 binDataLen; Boolean validSegs = false; PrnParseConstants.eContType contType; Boolean continuation = false; //----------------------------------------------------------------// // // // Initialise. // // // //----------------------------------------------------------------// _table = table; _buf = buf; _fileOffset = fileOffset; _analysisLevel = linkData.AnalysisLevel; _options = options; contType = linkData.getContType(); _indxOffsetFormat = _options.IndxGenOffsetFormat; _showBinData = _options.FlagPCLXLMiscBinData; //----------------------------------------------------------------// if (contType == PrnParseConstants.eContType.None) { _nextStage = eStage.Start; _validHddr = true; _firstSeg = true; _hddrLen = hddrLen; _hddrRem = hddrLen; _hddrPos = fileOffset + bufOffset; } else { contType = PrnParseConstants.eContType.None; linkData.resetContData(); } //----------------------------------------------------------------// if (_nextStage == eStage.Start) { if (bufRem < _cHddrDescLen) { //--------------------------------------------------------// // // // Font header descriptor is not all in buffer. // // Initiate continuation. // // // //--------------------------------------------------------// contType = PrnParseConstants.eContType.PCLXLFontHddr; linkData.setBacktrack(contType, -bufRem); } else { _nextStage = eStage.ShowHddr; } } if (_nextStage == eStage.ShowHddr) { //------------------------------------------------------------// // // // Process font header. // // // //------------------------------------------------------------// processFontHeader(ref bufRem, ref bufOffset); bufRem = bufRem - _cHddrDescLen; _hddrRem = _hddrRem - _cHddrDescLen; bufOffset = bufOffset + _cHddrDescLen; if (_validHddr) { _nextStage = eStage.ShowData; } else { _nextStage = eStage.BadSeqA; } } if (_nextStage == eStage.ShowData) { //------------------------------------------------------------// // // // Output details of segmented data: // // // //------------------------------------------------------------// Int32 dummy = 0; continuation = _parseSegs.processSegData(_buf, _fileOffset, false, _firstSeg, true, ref bufRem, ref bufOffset, ref _hddrDataRem, ref _hddrRem, ref dummy, ref validSegs, linkData, _options, _table); _firstSeg = false; } if (_nextStage == eStage.EndOK) { //------------------------------------------------------------// // // // End of processing of valid header. // // // //------------------------------------------------------------// return(_validHddr); } if (_nextStage == eStage.BadSeqA) { //------------------------------------------------------------// // // // Inconsistency found. // // // //------------------------------------------------------------// _nextStage = eStage.BadSeqB; PrnParseCommon.addTextRow( PrnParseRowTypes.eType.MsgError, _table, PrnParseConstants.eOvlShow.None, "", "", "", "Processing of header abandoned!"); } if ((_nextStage == eStage.BadSeqB) && (_hddrRem != 0)) { //------------------------------------------------------------// // // // Header does not appear to be valid. // // Treat remainder of header as a binary sequence without // // interpretation. // // Check if remainder of download sequence is within the // // buffer. // // // //------------------------------------------------------------// if (_hddrRem > bufRem) { //--------------------------------------------------------// // // // Remainder of sequence is not in buffer. // // Initiate continuation. // // // //--------------------------------------------------------// contType = PrnParseConstants.eContType.PCLXLFontHddr; binDataLen = bufRem; _hddrRem = _hddrRem - bufRem; linkData.setContinuation(contType); } else { contType = PrnParseConstants.eContType.None; linkData.resetContData(); binDataLen = _hddrRem; _hddrRem = 0; } if ((binDataLen) != 0) { //--------------------------------------------------------// // // // Some, or all, of the download data is contained within // // the current 'block'. // // // //--------------------------------------------------------// PrnParseData.processBinary( _table, PrnParseConstants.eOvlShow.None, buf, fileOffset, bufOffset, binDataLen, "PCLXL Binary", _showBinData, false, true, _indxOffsetFormat, _analysisLevel); bufRem = bufRem - binDataLen; bufOffset = bufOffset + binDataLen; } } return(_validHddr); }
//--------------------------------------------------------------------// // M e t h o d // // v i e w F i l e A c t i o n // //--------------------------------------------------------------------// // // // View file contents. // // // //--------------------------------------------------------------------// private void viewFileAction(PrnParseOptions options, DataTable table) { Int32 blockLen, sliceLen, blockStart = 0; Int32 offsetStart = 0, offsetEnd = -1, offsetCrnt; String offsetFormat; String offsetStr; Boolean rowLimitReached = false; Boolean endReached = false; Byte[] buf = new Byte[PrnParseConstants.bufSize]; //----------------------------------------------------------------// if (options.IndxGenOffsetFormat == PrnParseConstants.eOptOffsetFormats.Hexadecimal) { offsetFormat = "{0:x8}"; } else { offsetFormat = "{0:d10}"; } options.getOptCharSet(ref _indxCharSetName, ref _indxCharSetSubAct, ref _valCharSetSubCode); //----------------------------------------------------------------// // // // Check for start conditions specific to current file. // // // //----------------------------------------------------------------// options.getOptCurFOffsets(ref offsetStart, ref offsetEnd); blockStart = offsetStart; _ipStream.Seek(offsetStart, SeekOrigin.Begin); if (offsetStart != 0) { addRow(table, "Comment", "Start Offset = " + offsetStart + " (0x" + offsetStart.ToString("X8") + ") requested", ""); } if (offsetEnd != -1) { addRow(table, "Comment", "End Offset = " + offsetEnd + " (0x" + offsetEnd.ToString("X8") + ") requested", ""); } //----------------------------------------------------------------// while (!endReached && !rowLimitReached) { //------------------------------------------------------------// // // // Read next 'block' of file. // // If end-of-file detected, block will be less than full. // // // //------------------------------------------------------------// blockLen = _binReader.Read(buf, 0, PrnParseConstants.bufSize); if (blockLen == 0) { endReached = true; } else { //--------------------------------------------------------// // // // Split the current 'block' into 'slices'. // // Each 'slice' will provide one line of the output // // display; the last 'slice' may be less than a full line.// // Other slices may also be less than a full line if the // // option to split slices when LineFeed or FormFeed // // characters are encountered is in force. // // // //--------------------------------------------------------// sliceLen = PrnParseConstants.viewBytesPerLine; for (int i = 0; ((i < blockLen) && (!endReached)); i += sliceLen) { if ((i + PrnParseConstants.viewBytesPerLine) > blockLen) { //------------------------------------------------// // // // Last slice of data is less than full. // // // //------------------------------------------------// sliceLen = blockLen - i; } else { sliceLen = PrnParseConstants.viewBytesPerLine; } //----------------------------------------------------// // // // Extract required details from current slice. // // // //----------------------------------------------------// offsetCrnt = blockStart + i; offsetStr = String.Format(offsetFormat, offsetCrnt); sliceLen = viewFileSlice(buf, offsetStr, i, sliceLen, table); if ((offsetEnd != -1) && (offsetCrnt > offsetEnd)) { endReached = true; } } //--------------------------------------------------------// // // // Increment 'block' offset value. // // // //--------------------------------------------------------// blockStart = blockStart + blockLen; if ((offsetEnd != -1) && (blockStart > offsetEnd)) { endReached = true; } } } }
//--------------------------------------------------------------------// // M e t h o d // // i n i t i a l i s e // //--------------------------------------------------------------------// // // // Initialise . . . // // // //--------------------------------------------------------------------// private void initialise() { // _initialised = false; _redoAnalysis = true; _redoContent = true; _redoStatistics = true; //----------------------------------------------------------------// // // // Populate form. // // // //----------------------------------------------------------------// btnAnalysis.IsEnabled = false; btnContent.IsEnabled = false; btnStatistics.IsEnabled = false; btnSaveReport.IsEnabled = false; //----------------------------------------------------------------// // btnAnalyse.Content = "Analyse print file"; //----------------------------------------------------------------// // // // // // // //----------------------------------------------------------------// _options = new PrnParseOptions(); /* * //----------------------------------------------------------------// * // // * // If we ever support the 'doWork' mechanism: // * // // * //----------------------------------------------------------------// * * _bkWk = new BackgroundWorker (); * * _bkWk.WorkerReportsProgress = true; * * _bkWk.DoWork += new DoWorkEventHandler (this.bkWk_DoWork); * * _bkWk.RunWorkerCompleted += * new RunWorkerCompletedEventHandler (this.bkWk_Completed); * * _bkWk.ProgressChanged += * new ProgressChangedEventHandler (this.bkWk_Progress); */ //----------------------------------------------------------------// // // // Reinstate settings from persistent storage. // // // //----------------------------------------------------------------// metricsLoad(); _fileSize = -1; Int32 ctRowTypes = PrnParseRowTypes.getCount(); _indxClrMapBack = new Int32[ctRowTypes]; _indxClrMapFore = new Int32[ctRowTypes]; _options.getOptClrMap(ref _flagClrMapUseClr, ref _indxClrMapBack, ref _indxClrMapFore); _options.getOptClrMapStdClrs(ref _ctClrMapStdClrs, ref _stdClrsPropertyInfo); /* * //----------------------------------------------------------------// * // // * // If we ever support the 'doWork' mechanism: // * // statusBar updates // * // // * //----------------------------------------------------------------// * * statusBar.Items[0] = ""; * statusBar.Items[1] = ""; */ txtFileName.Text = ""; txtFileSize.Text = ""; //----------------------------------------------------------------// initialiseGridAnalysis(); initialiseGridContent(); initialiseGridStatistics(); //----------------------------------------------------------------// // _initialised = true; }
//--------------------------------------------------------------------// // F i e l d s // // Class variables. // // // //--------------------------------------------------------------------// //--------------------------------------------------------------------// // M e t h o d // // g e n e r a t e // //--------------------------------------------------------------------// // // // Generate the report. // // // //--------------------------------------------------------------------// public static void generate( ReportCore.eRptFileFmt rptFileFmt, DataTable table, String prnFilename, String ovlFilename, Boolean flagOffsetHex, PrnParseOptions options) { Object stream = null; Object writer = null; Boolean OK = false; String fileExt; String saveFilename = null; if (rptFileFmt == ReportCore.eRptFileFmt.html) { fileExt = "html"; } else if (rptFileFmt == ReportCore.eRptFileFmt.xml) { fileExt = "xml"; } else { fileExt = "txt"; } saveFilename = ovlFilename + "_report." + fileExt; OK = ReportCore.docOpen(rptFileFmt, ref saveFilename, ref stream, ref writer); if (OK) { Int32 ctClrMapRowTypes = PrnParseRowTypes.getCount(); Boolean useClr = options.FlagClrMapUseClr; if (useClr) { String[] rowClasses = new String[ctClrMapRowTypes]; String[] rowClrBack = new String[ctClrMapRowTypes]; String[] rowClrFore = new String[ctClrMapRowTypes]; getRowColourStyleData(options, ref rowClasses, ref rowClrBack, ref rowClrFore); ReportCore.docInitialise(rptFileFmt, writer, true, false, ctClrMapRowTypes, rowClasses, rowClrBack, rowClrFore); } else { ReportCore.docInitialise(rptFileFmt, writer, true, false, 0, null, null, null); } reportHeader(rptFileFmt, writer, prnFilename, ovlFilename); reportBody(rptFileFmt, writer, table, flagOffsetHex); ReportCore.docFinalise(rptFileFmt, writer); ReportCore.docClose(rptFileFmt, stream, writer); } }