com.openpcl.pclrenderimage
Class PclRenderImage

java.lang.Object
  extended by com.openpcl.pclrenderimage.PclRenderImage
All Implemented Interfaces:
IPclRenderImage, PclCommandEvent

public class PclRenderImage
extends Object
implements IPclRenderImage, PclCommandEvent

PclRenderImage may be used with or without the openpcl.jar file. If you imbed the OpenPCLViewer JPanel in your app, then you need the openpcljar file. But if your app has all the UI code you need, and all you want is to pass in PCL bytes to render and put the BufferedImage bitmap on your screen, then you don't need the openpcl.jar file at all. The PclRenderImage class and all its rendering objects parse a byte array of PCL that was passed in through one of the Interface IPclRenderImage methods that start with "renderImage...()", and renders the visual image on a java.awt.image.BufferedImage bitmap that is returned from the renderImage...() call. PclRenderImage internally reuses the same BufferedImage that it blanks out and draws on for each different page shown or zoom change instead of eating up a lot of memory if new BufferdImages were being made only to be JVM garbage collected later at each next page to render or zoom change. Drawing speed is good and no more memory is allocated than for one image. On each of the different renderImage...() calls, if it returns null instead of the rendered page BufferedImage, then call getLastErrorString() that the calling UI code can put on the screen for the user to see the error message. The implemented interface IPclRenderImage are call into methods that can return Object values. The implemented interface PclCommandEvent is in RmsTools. There are no callback methods that the class that instantiated this class must impelement.

Author:
DocMagic, Document Systems Inc, Howard. Rendering code written May 16 2006 to July 20 2006.

Field Summary
protected  BufferedImage mBufferedImageToDrawOn
           
protected  ByteArrayOutputStream mByteArrayOutputStream
           
protected  byte[] mCurrentClickedPagePclBytes
           
protected  long mCurrentThreadId
           
protected  double mCurrentZoomFactor
           
protected  String mFileNameNoPath
           
protected  String mFullFilePathAndName
           
protected  Graphics2D mGraphics2D
           
protected  boolean mIsDrawingForPrinting
           
protected  boolean mIsExecutingAMacro
           
protected  boolean mIsRecordingAMacro
           
protected  boolean mIsSoftFontMode
           
protected  boolean mIsStateBuildingPclPages
           
protected  String mLastRenderErrorString
           
protected  int mMultipleOpenId
           
protected  int mNumberOfPagesFound
           
protected  ArrayList<PriPclPage> mPagesArrayList
           
protected  boolean mParsePclIs1stPass
           
protected  PclParser mPclParser
           
protected  PriCharWidthTables mPriCharWidthTables
           
protected  PriCursorPos mPriCursorPos
           
protected  PriDrawText mPriDrawText
           
protected  PriFonts mPriFonts
           
protected  PriPageSettings mPriPageSettings
           
protected  PriParseMacroBytes mPriParseMacroBytes
           
protected  PriParseSoftFontBytes mPriParseSoftFontBytes
           
protected  PriPclPage mPriPclPage
           
protected  PriRasterDrawing mPriRasterDrawing
           
protected  PriRectDrawing mPriRectDrawing
           
protected  String mShowHideTagBaseString
           
protected  int mStartIndexOfPclPage
           
protected  long mThreadIdCounter
           
protected  boolean mWantToCenterCharInCharCellBox
           
protected static char scCR
           
protected static char scFF
           
protected static char scLF
           
protected static double sDefaultZoomFactor
           
 
Constructor Summary
PclRenderImage()
          Constructor.
 
Method Summary
 void blankOutBufferedImage()
          Blank out the BufferedImage on the screen of the current selected view.
 void charFoundEvent(char nextChar, int pBufferPos)
           
 void commandFoundEvent(String cmdLeadin, String cmdValue, String cmdTerminator, byte[] cmdData, int pBufferPos)
           
protected  BufferedImage createNewBufferedImageToDrawOn()
          Create a new BufferredImage all ready to draw on
 void freeUpMemory()
          When the user closes the view frame of one of the views on the screen, the calling UI code can call this method that frees up memory in PclRenderImage.
 BufferedImage getBufferedImageToDrawOn()
          Get the BufferedImage to draw on for purposes of an external app can call methods on the BufferedImage object which can change how it looks on the screen.
 byte[] getCurrentClickedPagePclBytes()
           
 double getCurrentZoomFactor()
           
 String getFileNameNoPath()
           
 String getFullFilePathAndName()
           
protected  Graphics2D getGraphicsWithRenderHints(BufferedImage pBufferedImage)
           
 BufferedImage getImageForPage(int pPageNumber, byte[] pPrintTimePclBytes, boolean pIsForPrinting, String pPaperSize, double pZoomFactor)
          The PCL for the passed in page number will be rendered to a BufferedImage.
 boolean getIsDrawingForPrinting()
           
 boolean getIsSoftFontMode()
           
 boolean getIsStateBuildingPclPages()
           
 String getLastRenderErrorString()
          Get the last error string.
 int getMultipleOpenId()
           
 ArrayList<PriPclPage> getPagesArrayList()
           
 String getPaperSizeForPage(int pPageNumber)
          Get the Paper Size int that was in the original Pcl bytes for the passed in page.
 boolean getParsePclIs1stPass()
           
 byte[] getPclBytesForPage(int pPageNumber)
          Get the Pcl bytes for page N
 int getPclPageCount()
          Returns the number of separate pages found by parsing the passed in Pcl bytes in splitIntoSeparatePclPages().
 PriCharWidthTables getPriCharWidthTables()
           
 PriCursorPos getPriCursorPos()
           
 PriDrawText getPriDrawText()
           
 PriFonts getPriFonts()
           
 PriPageSettings getPriPageSettings()
           
 PriParseMacroBytes getPriParseMacroBytes()
           
 PriParseSoftFontBytes getPriParseSoftFontBytes()
           
 PriPclPage getPriPclPage()
           
 PriRasterDrawing getPriRasterDrawing()
           
 PriRectDrawing getPriRectDrawing()
           
 String getShowHideTagBaseString()
           
 boolean getWantToCenterCharInCharCellBox()
           
protected  void handleFormFeedFound(int pBufferPos)
           
protected  void initializeForSplitPages()
          Initialize before splitting the Pcl bytes into separate pages.
 String loadFromFileSplitIntoSeparatePclPages(String pFullPathAndFilename)
          Read the PCL bytes the passed in String full path and filename.
 String loadFromUrlSplitIntoSeparatePclPages(String pUrl)
          Read the PCL bytes the passed in String URL.
protected  BufferedImage parseAndRender(byte[] pPclBytes, boolean pIsForPrinting, double pAtZoomFactor)
          parseAndRender() is a non public method that the 4 public renderImage...() methods call.
 void setCurrentClickedPagePclBytes(byte[] pByteArray)
           
 void setCurrentZoomFactor(double pCurrentZoomFactor)
           
 void setIsDrawingForPrinting(boolean pIsDrawingForPrinting)
           
 void setParsePclIs1stPass(boolean pParsePclIs1stPass)
           
 void setShowHideTagBaseString(String pShowHideTagBaseString)
           
 void setWantToCenterCharInCharCellBox(boolean pWantToCenterCharInCharCellBox)
           
 String splitIntoSeparatePclPages(byte[] pPclBytes)
          Split the passed in Pcl bytes into separate pages and internally store each page's Pcl bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mPclParser

protected PclParser mPclParser

mBufferedImageToDrawOn

protected BufferedImage mBufferedImageToDrawOn

mGraphics2D

protected Graphics2D mGraphics2D

mPriCharWidthTables

protected PriCharWidthTables mPriCharWidthTables

mPriCursorPos

protected PriCursorPos mPriCursorPos

mPriDrawText

protected PriDrawText mPriDrawText

mPriFonts

protected PriFonts mPriFonts

mPriPageSettings

protected PriPageSettings mPriPageSettings

mPriParseMacroBytes

protected PriParseMacroBytes mPriParseMacroBytes

mPriParseSoftFontBytes

protected PriParseSoftFontBytes mPriParseSoftFontBytes

mPriRasterDrawing

protected PriRasterDrawing mPriRasterDrawing

mPriRectDrawing

protected PriRectDrawing mPriRectDrawing

mCurrentClickedPagePclBytes

protected byte[] mCurrentClickedPagePclBytes

mMultipleOpenId

protected int mMultipleOpenId

mStartIndexOfPclPage

protected int mStartIndexOfPclPage

mNumberOfPagesFound

protected int mNumberOfPagesFound

sDefaultZoomFactor

protected static final double sDefaultZoomFactor
See Also:
Constant Field Values

mCurrentZoomFactor

protected double mCurrentZoomFactor

mPriPclPage

protected PriPclPage mPriPclPage

mPagesArrayList

protected ArrayList<PriPclPage> mPagesArrayList

mByteArrayOutputStream

protected ByteArrayOutputStream mByteArrayOutputStream

mFullFilePathAndName

protected String mFullFilePathAndName

mFileNameNoPath

protected String mFileNameNoPath

mLastRenderErrorString

protected String mLastRenderErrorString

scLF

protected static char scLF

scFF

protected static char scFF

scCR

protected static char scCR

mThreadIdCounter

protected long mThreadIdCounter

mCurrentThreadId

protected long mCurrentThreadId

mIsSoftFontMode

protected boolean mIsSoftFontMode

mParsePclIs1stPass

protected boolean mParsePclIs1stPass

mIsRecordingAMacro

protected boolean mIsRecordingAMacro

mIsExecutingAMacro

protected boolean mIsExecutingAMacro

mIsDrawingForPrinting

protected boolean mIsDrawingForPrinting

mIsStateBuildingPclPages

protected boolean mIsStateBuildingPclPages

mWantToCenterCharInCharCellBox

protected boolean mWantToCenterCharInCharCellBox

mShowHideTagBaseString

protected String mShowHideTagBaseString
Constructor Detail

PclRenderImage

public PclRenderImage()
Constructor. There are no callback methods, only call into methods that can return an object value

Method Detail

getPriCharWidthTables

public PriCharWidthTables getPriCharWidthTables()

getPriCursorPos

public PriCursorPos getPriCursorPos()

getPriDrawText

public PriDrawText getPriDrawText()

getPriFonts

public PriFonts getPriFonts()

getPriPageSettings

public PriPageSettings getPriPageSettings()

getPriParseMacroBytes

public PriParseMacroBytes getPriParseMacroBytes()

getPriParseSoftFontBytes

public PriParseSoftFontBytes getPriParseSoftFontBytes()

getPriPclPage

public PriPclPage getPriPclPage()

getPriRasterDrawing

public PriRasterDrawing getPriRasterDrawing()

getPriRectDrawing

public PriRectDrawing getPriRectDrawing()

getPagesArrayList

public ArrayList<PriPclPage> getPagesArrayList()

getCurrentClickedPagePclBytes

public byte[] getCurrentClickedPagePclBytes()

getMultipleOpenId

public int getMultipleOpenId()

getCurrentZoomFactor

public double getCurrentZoomFactor()

getIsSoftFontMode

public boolean getIsSoftFontMode()

getParsePclIs1stPass

public boolean getParsePclIs1stPass()

getIsDrawingForPrinting

public boolean getIsDrawingForPrinting()

getIsStateBuildingPclPages

public boolean getIsStateBuildingPclPages()

getWantToCenterCharInCharCellBox

public boolean getWantToCenterCharInCharCellBox()

getShowHideTagBaseString

public String getShowHideTagBaseString()

getFileNameNoPath

public String getFileNameNoPath()

getFullFilePathAndName

public String getFullFilePathAndName()

setCurrentClickedPagePclBytes

public void setCurrentClickedPagePclBytes(byte[] pByteArray)

setParsePclIs1stPass

public void setParsePclIs1stPass(boolean pParsePclIs1stPass)

setIsDrawingForPrinting

public void setIsDrawingForPrinting(boolean pIsDrawingForPrinting)

setWantToCenterCharInCharCellBox

public void setWantToCenterCharInCharCellBox(boolean pWantToCenterCharInCharCellBox)

setShowHideTagBaseString

public void setShowHideTagBaseString(String pShowHideTagBaseString)

setCurrentZoomFactor

public void setCurrentZoomFactor(double pCurrentZoomFactor)

handleFormFeedFound

protected void handleFormFeedFound(int pBufferPos)

charFoundEvent

public void charFoundEvent(char nextChar,
                           int pBufferPos)
Specified by:
charFoundEvent in interface PclCommandEvent

commandFoundEvent

public void commandFoundEvent(String cmdLeadin,
                              String cmdValue,
                              String cmdTerminator,
                              byte[] cmdData,
                              int pBufferPos)
Specified by:
commandFoundEvent in interface PclCommandEvent

createNewBufferedImageToDrawOn

protected BufferedImage createNewBufferedImageToDrawOn()
Create a new BufferredImage all ready to draw on

Returns:
BufferedImage

getGraphicsWithRenderHints

protected Graphics2D getGraphicsWithRenderHints(BufferedImage pBufferedImage)

initializeForSplitPages

protected void initializeForSplitPages()
Initialize before splitting the Pcl bytes into separate pages. Any previous split pages are deleted and new pages are made now.


parseAndRender

protected BufferedImage parseAndRender(byte[] pPclBytes,
                                       boolean pIsForPrinting,
                                       double pAtZoomFactor)
parseAndRender() is a non public method that the 4 public renderImage...() methods call. Highlights of what parseAndRender() does is: 1. Parse the passed in PCL bytes that the UI code got from an opened local file or from a URL or from XML, and build PriPclPage objects that are added to the mPagesArrayList. 2. The UI code can then call getPclPagesArrayList() to get the ArrayList of PriPclPage objects which are the separate pages. 3. If the UI code calls breakPclIntoPages(byte[]) b 2. The UI code pass 2. Wait til the user clicks on a tree page node on the OpenPCLViewer side, which will call and render the PCL for that one page only by pulling the PCL bytes from the PriPclPage returned from mPagesArrayList.getAt(int), where int is the page number the user clicked on to see. PriPclPage.getPclBytes() the user clicked on. This happens in the PclRenderImage side and not on the OpenPCLViewer side or other external app sice, because PclRenderImage's PriTree adds a tree selection listener that gets called if the UI code added the JTree to the screen and the user clicks on a tree page node. 3. Using the mBufferedImageToDrawOnArray[] and the mPagesJTreeArray[] array, and the method switchToImageNumber(int) that is called from the UI code as the user adds views by opening files, or opening URLs, or clicks to the different currenly open views, render the passed in PCL bytes from the below methods shown below in #4. 4. These PCL bytes were passed in using the public API Interface methods: a. renderImageFromPcl(byte[]) b. renderImageFromPclAtZoomFactor(byte[], double); d. renderImageFromFile(String)

Parameters:
pPclBytes -
pAtZoomFactor -
Returns:
If error returns error String. If no error then returns null

freeUpMemory

public void freeUpMemory()
When the user closes the view frame of one of the views on the screen, the calling UI code can call this method that frees up memory in PclRenderImage. This is important because on a 512mb memory PC, only 9 views can be open before it goes into the swap file. If the user is opening and closing views, and memory is not freed up upon closing views, then it's a big problem. Ok so then one might say that it's better to not free up memory of closed views and to reuse the BufferedImage in views that were closed is a possibility assuming that the user will open and close views, then open later as many views that were closed. But, what if the user opens 9 views, then closes 8 views, then checks the memory used by the app, and sees that it didn't let go of the memory of the 8 closed views. Might as well implement let go of the memory upon close of a view now before it is a reported bug later, right?

Parameters:
pImageNumber -

splitIntoSeparatePclPages

public String splitIntoSeparatePclPages(byte[] pPclBytes)
Split the passed in Pcl bytes into separate pages and internally store each page's Pcl bytes. In DocMaster, this is "ParseEntirePCL".

Specified by:
splitIntoSeparatePclPages in interface IPclRenderImage
Parameters:
pPclBytes -
Returns:
If error returns error String. If no error then returns null

getPclPageCount

public int getPclPageCount()
Returns the number of separate pages found by parsing the passed in Pcl bytes in splitIntoSeparatePclPages().

Specified by:
getPclPageCount in interface IPclRenderImage
Returns:
int

getImageForPage

public BufferedImage getImageForPage(int pPageNumber,
                                     byte[] pPrintTimePclBytes,
                                     boolean pIsForPrinting,
                                     String pPaperSize,
                                     double pZoomFactor)
The PCL for the passed in page number will be rendered to a BufferedImage. Passing in the zoom factor is mandatory because the rendering code draws everything (text, rectanges, raster dot areas, etc) pre-scaled to exactly how small or big is needed and clips the overall image width and height to make the whole image look zoomed smaller or bigger. The UI code can then put this image on the screen without scaling the image on the UI side. Doing it this way is needed so the image looks sharp because scaling using the AffineTransform scale leaves the image too blurry for both zoom in or out. In DocMaster, this is getImage().

Specified by:
getImageForPage in interface IPclRenderImage
Parameters:
pPageNumber. - The Pcl page number to render to the image.
pPrintTimePclBytes. - Draw these additional PCL bytes on the print image.
pIsForPrinting. - If true non printing items like signature blocks won't be rendered.
pPaperSize. - If a paper size is not specified in the PCL, this paper size will be used. "LTR" or "LGL".
pZoomFactor. - This is mandatory (see note for why).
Returns:
BufferedImage. If null is returned, then call getLastErrorString()

getLastRenderErrorString

public String getLastRenderErrorString()
Get the last error string. Call this if getImageForPage() returned null instead of returning the BufferedImage.

Specified by:
getLastRenderErrorString in interface IPclRenderImage
Returns:
String of the last error

loadFromFileSplitIntoSeparatePclPages

public String loadFromFileSplitIntoSeparatePclPages(String pFullPathAndFilename)
Read the PCL bytes the passed in String full path and filename. Then this calls splitIntoSeparatePclPages to split the Pcl into its separate pages. No image is rendered yet. To get the image for a page number, call getImageForPage().

Specified by:
loadFromFileSplitIntoSeparatePclPages in interface IPclRenderImage
Parameters:
pFullPathAndFilename -
Returns:
If error returns error String. If no error then returns null

loadFromUrlSplitIntoSeparatePclPages

public String loadFromUrlSplitIntoSeparatePclPages(String pUrl)
Read the PCL bytes the passed in String URL. Then this calls splitIntoSeparatePclPages to split the Pcl into its separate pages. No image is rendered yet. To get the image for a page number, call getImageForPage().

Specified by:
loadFromUrlSplitIntoSeparatePclPages in interface IPclRenderImage
Parameters:
pUrl -
Returns:
If error returns error String. If no error then returns null

getBufferedImageToDrawOn

public BufferedImage getBufferedImageToDrawOn()
Get the BufferedImage to draw on for purposes of an external app can call methods on the BufferedImage object which can change how it looks on the screen.

Specified by:
getBufferedImageToDrawOn in interface IPclRenderImage
Returns:
BufferedImage

blankOutBufferedImage

public void blankOutBufferedImage()
Blank out the BufferedImage on the screen of the current selected view.

Specified by:
blankOutBufferedImage in interface IPclRenderImage

getPclBytesForPage

public byte[] getPclBytesForPage(int pPageNumber)
Get the Pcl bytes for page N

Specified by:
getPclBytesForPage in interface IPclRenderImage

getPaperSizeForPage

public String getPaperSizeForPage(int pPageNumber)
Get the Paper Size int that was in the original Pcl bytes for the passed in page. Each page has its own paper size setting, which was set in the PclRenderImage.commandFoundEvent() for the Pcl command "ESC & L # A". When a Paper Size Pcl command is found, it is set on the current page and also on the following pages until another Paper Size command is found. For those Pcl files that have been dieted/scrubbed, and the Paper Size is not there, then the default Paper Size is used from PriPageSettings.sDefaultPaperSize.

Specified by:
getPaperSizeForPage in interface IPclRenderImage
Parameters:
pPageNumber -
Returns:
String


OpenPCL http://www.openpcl.com