From: <doc...@us...> - 2008-11-26 23:59:21
|
Revision: 223 http://openpcl.svn.sourceforge.net/openpcl/?rev=223&view=rev Author: documentsystems Date: 2008-11-26 23:59:17 +0000 (Wed, 26 Nov 2008) Log Message: ----------- 1) PCL Push/Pop cursor position implemented 2) Reset cursor position to x=0, y=0 on subsequent page parse Modified Paths: -------------- openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java openpcl/src/com/openpcl/pclrenderimage/render/PriCursorPos.java openpcl/src/com/openpcl/pclrenderimage/tools/PclParser.java openpcl/src/com/openpcl/viewer/OpenPCLViewer.java Modified: openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java =================================================================== --- openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java 2008-10-17 15:59:12 UTC (rev 222) +++ openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java 2008-11-26 23:59:17 UTC (rev 223) @@ -10,6 +10,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; +import java.util.Stack; import com.openpcl.pclrenderimage.api.IPclRenderImage; import com.openpcl.pclrenderimage.render.PriCharWidthTables; @@ -90,6 +91,7 @@ protected PriCharWidthTables mPriCharWidthTables = null; protected PriCursorPos mPriCursorPos = null; + protected Stack<PriCursorPos> mPriCursorStack = null; protected PriDrawText mPriDrawText = null; protected PriFonts mPriFonts = null; protected PriPageSettings mPriPageSettings = null; @@ -135,9 +137,10 @@ if (mBufferedImageToDrawOn != null) { mGraphics2D = getGraphicsWithRenderHints(mBufferedImageToDrawOn); - // Instantiate supporing objects that this class has a reference to + // Instantiate supporting objects that this class has a reference to mPriCharWidthTables = new PriCharWidthTables(); mPriCursorPos = new PriCursorPos(this); + mPriCursorStack = new Stack<PriCursorPos>(); mPriDrawText = new PriDrawText(this, mGraphics2D); mPriFonts = new PriFonts(this, mGraphics2D); mPriPageSettings = new PriPageSettings(); @@ -272,14 +275,15 @@ */ try { // The command value is null for some commands, a parseFloat will throw an exception under this condition - if(cmdValue != null){ + if((cmdValue != null)&&(cmdValue != "")) { // Use Float.parseFloat() then Math.round() because when cmdValue is "10.00", - // Interger.parseInt() returns 0 instead of 10 + // Integer.parseInt() returns 0 instead of 10 cmdValueFloat = Float.parseFloat(cmdValue); cmdValueInt = Math.round(cmdValueFloat); } - } catch (NumberFormatException e) { - } + } catch (NumberFormatException e) { + } + // The "if else" is nested for parse speed instead of a 1 level long string compare chain. // The most frequently used commands should be nearer the top. if(cmdLeadin.equals(PCL_POSITION)){ // Position command @@ -312,7 +316,7 @@ processPrimaryFontCommand(cmdTerminator, cmdValueInt); } else if (cmdLeadin.equals(PCL_RESET)) { processResetCommand(); - } + } } private void processResetCommand() { @@ -472,6 +476,25 @@ */ private void processExecuteCommand(char cmdTerminator, int pBufferPos, int cmdValueInt) { switch(cmdTerminator){ + case 'S': //jfg added push/pop commands 11.10.2008 + switch (cmdValueInt) { + case 0: // &f0S PUSH cursor position + if (mIsStateBuildingPclPages || mIsRecordingAMacro) { return; } + //clone the current position object and place it onto the stack + PriCursorPos tPriCursorPos = (PriCursorPos)mPriCursorPos.clone(); + //place the saved cursor position onto the stack + mPriCursorStack.push(tPriCursorPos); + break; + case 1: // &f1S POP cursor position + if (mIsStateBuildingPclPages || mIsRecordingAMacro) { return; } + if (!mPriCursorStack.empty()){ + //get the last position off the stack + mPriCursorPos = mPriCursorStack.pop(); + } + break; + } + break; + case 'Y': if (mIsStateBuildingPclPages) { return; } mPriDrawText.drawBufferedUpCharsAs1String(); @@ -634,6 +657,7 @@ private void processShadeTransparencyCommand(char cmdTerminator, int cmdValueInt) { switch(cmdTerminator){ case 'T': + if (mIsStateBuildingPclPages || mIsRecordingAMacro) { return; } mPriDrawText.drawBufferedUpCharsAs1String(); // Set current Pattern. 0=black, 1=white. White text is put on top of rectangle draws sometimes mPriPageSettings.setPrintPattern(cmdValueInt); @@ -935,7 +959,7 @@ * Also some Blockument pages start with Fill instead of non fill text don't specifiy a font or LPI or top margin */ mPriFonts.setJavaBuiltInFont(4099); mPriPageSettings.setToInitialValues(); - + mPriCursorPos.setToInitialValues();//jfg fixed 11/06/2008 - without this, multiple parses of the same byte stream have xPos and yPos would never be reset mPclParser = new PclParser(mCurrentClickedPagePclBytes, this); // Parse the PCL bytes from the RmsTools PclParser mPclParser.ParsePCL(); // does callbacks to the 2 interface methods below as necessary (making the BufferedImage) Modified: openpcl/src/com/openpcl/pclrenderimage/render/PriCursorPos.java =================================================================== --- openpcl/src/com/openpcl/pclrenderimage/render/PriCursorPos.java 2008-10-17 15:59:12 UTC (rev 222) +++ openpcl/src/com/openpcl/pclrenderimage/render/PriCursorPos.java 2008-11-26 23:59:17 UTC (rev 223) @@ -9,12 +9,22 @@ * All the Cursor positioning * @author howard 5/16/2006 */ -public class PriCursorPos { - protected PclRenderImage mPclRenderImage = null; +public class PriCursorPos implements Cloneable { + protected PclRenderImage mPclRenderImage = null; - /** The current X and Y drawing position */ - protected int mXpos = 0; - protected int mYpos = 0; + /** The current X and Y drawing position */ + protected int mXpos = 0; + protected int mYpos = 0; + + //clone implemented for PUSH and POP PCL cmds + public Object clone() { + try { + return super.clone(); + } + catch (CloneNotSupportedException e) { + throw new InternalError(e.toString()); + } + } /** * Constructor Modified: openpcl/src/com/openpcl/pclrenderimage/tools/PclParser.java =================================================================== --- openpcl/src/com/openpcl/pclrenderimage/tools/PclParser.java 2008-10-17 15:59:12 UTC (rev 222) +++ openpcl/src/com/openpcl/pclrenderimage/tools/PclParser.java 2008-11-26 23:59:17 UTC (rev 223) @@ -82,23 +82,24 @@ public void ParsePCL() { int bufInt; - char ch; + char ch; try { while (( bufInt = buffer.read() ) != -1) { bufferPos++; // = 1; - ch = (char)bufInt; + ch = (char)bufInt; if ( ch == scESC ) { // We have an escape: getPclCommands(); // Loop for all parts of the command } else { callbackObject.charFoundEvent( ch, bufferPos ); } } + System.out.println("parsed " + bufferPos + " bytes"); } catch (ParseException pe) { System.out.println("Unable to complete PCL parsing."); pe.printStackTrace(); } - catch (IOException e) { e.printStackTrace(); } + catch (IOException e) { e.printStackTrace(); } } public void getPclCommands() throws ParseException, IOException { @@ -152,7 +153,21 @@ * ex: Soft font header: ')sxxW'; Transfer Raster: '*b,W'; etc. */ if ((pclState==4 || pclState==6 || pclState==7) && cmdTerminator == 'W' ) { - int numChars = Integer.parseInt( cmdValue ); // BOA ERROR: Throwing 'NumberFormatException' ? (Blank string) + int numChars = 0; + + try + { + + numChars = Integer.parseInt( cmdValue ); + } + catch (NumberFormatException e) + { + // TODO Auto-generated catch block + System.out.println(cmdValue); + e.printStackTrace(); + } + + // BOA ERROR: Throwing 'NumberFormatException' ? (Blank string) cmdData = GetBytesFromBuffer( numChars ); pclState = Math.min(pclState + 1, 7 ); // 4 becomes 5, 6 becomes 7 ?? } else { Modified: openpcl/src/com/openpcl/viewer/OpenPCLViewer.java =================================================================== --- openpcl/src/com/openpcl/viewer/OpenPCLViewer.java 2008-10-17 15:59:12 UTC (rev 222) +++ openpcl/src/com/openpcl/viewer/OpenPCLViewer.java 2008-11-26 23:59:17 UTC (rev 223) @@ -755,6 +755,8 @@ tPosFileFilter.addExtension("pcl"); tPosFileFilter.addExtension("prn"); tPosFileFilter.addExtension("tem"); + tPosFileFilter.addExtension("txt");//jfg + tPosFileFilter.setDescription("PCL Files"); return tPosFileFilter; } @@ -1325,6 +1327,8 @@ /** Determine the file type by the file extension. * Subclass plugins override this method so do not delete or rename this method. */ public int determineFileTypeByFileExtension(String pExtensionOfFileName) { + return sFileTypePCL; //jfg : removed logic to open all files by extension +/** if (pExtensionOfFileName.equalsIgnoreCase(".PCL") || pExtensionOfFileName.equalsIgnoreCase(".PRN") || pExtensionOfFileName.equalsIgnoreCase(".TEM")) { @@ -1333,6 +1337,7 @@ } else { return sFileTypeNotSupported; } + */ } /** Show the zoom factor in the toolbar button JLabel.setText() */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |