├── .classpath ├── .project ├── LICENSE.txt ├── README.txt ├── doc ├── CoverTest.txt ├── PCL5_Commands_structure.txt ├── Plan.txt └── kwadraty.doc └── src ├── gui ├── BitmapPanel.java ├── GUIRasterizer.java ├── JARClassLoader.java ├── JFileFilter.java ├── TextOutputText.java ├── TextRasterizer.java └── VectorButton.java └── java └── org └── getopt └── pcl5 ├── CommonPrinterState.java ├── FontDefinition.java ├── HPGLInterpreter └── cmd │ ├── CmdAbsoluteArcThreePoint.java │ ├── CmdAdvanceFullPage.java │ ├── CmdArcAbsolute.java │ ├── CmdArcRelative.java │ ├── CmdComment.java │ ├── CmdDefaultValues.java │ ├── CmdEscCommand.java │ ├── CmdInputAbsolute.java │ ├── CmdInputRelative.java │ ├── CmdInputWindow.java │ ├── CmdReplot.java │ ├── CmdRotateCoordinateSystem.java │ ├── CmdScale.java │ ├── CmdUniversalExitLanguage.java │ ├── CmdUnknownHPGL.java │ ├── CommandHPGL.java │ └── EscCommandHPGL.java ├── IPrint.java ├── IPrinterState.java ├── Interpreter.java ├── PCL5Interpreter ├── BaseCommand.java ├── Command.java ├── ControlCodes.java ├── FontDescriptorPCLBitmappedFonts.java ├── FontHeaderCommon.java ├── FontHeaderIntellifontBound.java ├── FontHeaderIntellifontUnbound.java ├── FontHeaderPCLBitmappedFonts.java ├── FontHeaderResolutionSpecifiedBitmapped.java ├── FontHeaderTrueType.java ├── FontsetPCLBitmappedFonts.java ├── IInitialSetup.java ├── IParse.java ├── IPrint.java ├── PatternGraphics.java ├── PrinterImage.java ├── PrinterScore.java ├── PrinterTIFF.java ├── PrinterType.java ├── PrinterTypeface.java ├── RasterGraphics.java ├── Resolution.java ├── ScaleBW2Gray.java ├── TypefaceInfo.java ├── UserDefinedPattern.java └── cmd │ ├── BaseCommandPCL5.java │ ├── CmdCarriageReturn.java │ ├── CmdCharacterCode.java │ ├── CmdCharacterDefinition.java │ ├── CmdEndRasterGraphics.java │ ├── CmdEndRasterGraphicsEx.java │ ├── CmdEscUnknownPCL5.java │ ├── CmdExtendedEscUnknownPCL5.java │ ├── CmdFillRectangularArea.java │ ├── CmdFontHeader.java │ ├── CmdFontID.java │ ├── CmdFontSelectionbyID.java │ ├── CmdFormFeed.java │ ├── CmdHeight.java │ ├── CmdHorizontalCursorPositioning.java │ ├── CmdHorizontalRectangleSize.java │ ├── CmdLeftMargin.java │ ├── CmdLogicalPageOrientation.java │ ├── CmdNumberOfCopies.java │ ├── CmdPageSize.java │ ├── CmdPaperSource.java │ ├── CmdPatternID.java │ ├── CmdPatternTransparencyMode.java │ ├── CmdPictureFrameHorizontalSize.java │ ├── CmdPictureFrameVerticalSize.java │ ├── CmdPitch.java │ ├── CmdPrinterReset.java │ ├── CmdRasterGraphicsPresentationMode.java │ ├── CmdRasterGraphicsResolution.java │ ├── CmdRightMargin.java │ ├── CmdSelectCurrentPattern.java │ ├── CmdSetCompressionMethod.java │ ├── CmdSetCompressionMode.java │ ├── CmdSetPictureFrameAnchorPoint.java │ ├── CmdSimplexDuplexPrintCommand.java │ ├── CmdSpacing.java │ ├── CmdStartRasterGraphics.java │ ├── CmdStrokeWeight.java │ ├── CmdStyle.java │ ├── CmdSymbolSet.java │ ├── CmdTopMargin.java │ ├── CmdTransferRasterData.java │ ├── CmdTypefaceFamily.java │ ├── CmdUnderline.java │ ├── CmdUnitOfMeasure.java │ ├── CmdUniversalExitLanguage.java │ ├── CmdUnknownPCL5.java │ ├── CmdUserDefinedPattern.java │ ├── CmdVerticalCursorPositioning.java │ ├── CmdVerticalMotionIndex.java │ ├── CmdVerticalRectangleSize.java │ ├── CommandPCL5.java │ ├── EscCommandPCL5.java │ └── EscExtendedCommandPCL5.java ├── PJLInterpreter └── cmd │ ├── BaseCommandPJL.java │ ├── CmdComment.java │ ├── CmdEnter.java │ ├── CmdEscUnknownPJL.java │ ├── CmdSet.java │ ├── CmdUniversalExitLanguage.java │ ├── CmdUnknownPJL.java │ ├── CommandPJL.java │ └── EscCommandPJL.java ├── PackageLoader.java ├── PageSize.java ├── PrinterState.java └── res ├── commands.properties ├── hpglcommands.properties └── pjlcommands.properties /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | PCL5 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | A parser for the Printer Command Language version 5. 2 | 3 | 4 | PCL5 has been created by Hewlett-Packard for the use in their line of 5 | raster and vector printers. Since then many other printer vendors started 6 | using it in their products. 7 | 8 | PCL is a documented format, but implementations often differ in 9 | many subtle (and not so subtle) details of how the format is to be 10 | interpreted, so that parsing PCL correctly is a challenge. For example, 11 | even among printers coming from a single vendor there are substantial 12 | differences in interpretation of the same commands between dot-matrix, 13 | laser and ink-jet printers, and between specific models in each category. 14 | 15 | The following reference materials were used to implement this parser: 16 | 17 | http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13210/bpl13210.pdf 18 | http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13211/bpl13211.pdf 19 | http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13208/bpl13208.pdf 20 | http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13207/bpl13207.pdf 21 | 22 | This package provides a basic interpreter that can be easily extended or 23 | modified to cover any particular variant of the language. The original 24 | purpose of this parser was text extraction, so the handling of details of 25 | formatting and graphics is less reliable. 26 | 27 | PCL format allows for adding extensions, e.g. sections in other printer 28 | languages. Some of the commonly used ones are PJL (Print Job Language) 29 | and HPGL (HP Graphics Language). This package offers a limited support 30 | for parsing these languages. 31 | -------------------------------------------------------------------------------- /doc/CoverTest.txt: -------------------------------------------------------------------------------- 1 | CmdAdvancePrintPositionVertically 2 | CmdAssignCharacterTable 3 | +CmdBackspace 4 | CmdBarCodeSetupAndPrint 5 | CmdBEL 6 | CmdCancelBottomMargin 7 | CmdCancelLine 8 | CmdCancelMSBControl 9 | +CmdCarriageReturn 10 | CmdControlPaperLoading 11 | CmdDefineUserDefinedCharacters 12 | CmdDeleteLastCharacterInBuffer 13 | CmdCopyROMToRAM 14 | CmdDeselectPrinter 15 | CmdDisablePaperOutDetector 16 | CmdEnablePaperOutDetector 17 | CmdEnablePrintingOfControlCodes 18 | +CmdEnablePrintingOfUpperControlCodes 19 | CmdEscUnknown 20 | CmdExtendedEscUnknown 21 | +CmdFormFeed 22 | CmdHorizontalVerticalSkip 23 | +CmdInitializePrinter 24 | +CmdLineFeed 25 | +?CmdMasterSelect 26 | CmdPrintDataAsCharacters 27 | CmdPrintRasterGraphics 28 | CmdReassignBitImageMode 29 | CmdReversePaperFeed 30 | CmdSelect10CPI 31 | +CmdSelect60DPIGraphics 32 | CmdSelect9PinGraphics 33 | +CmdSelectAnInternationalCharacterSet 34 | +CmdSelectBitImage 35 | CmdSelectBoldFont 36 | CmdSelectCharacterStyle 37 | +CmdSelectCharacterTable 38 | CmdSelectCondensedPrinting 39 | CmdSelectCondensedPrinting2 40 | CmdSelectDoubleStrike 41 | CmdSelectDoubleWidthPrintingOneLine 42 | CmdSelectDoubleWidthPrintingOneLine2 43 | CmdSelectFontByPitchAndPoint 44 | CmdSelectGraphicsMode 45 | CmdSelectImmediatePrintMode 46 | CmdSelectItalicFont 47 | CmdSelectJustification 48 | CmdSelectLineScore 49 | +CmdSelectLineSpacing 50 | CmdSelectLowspeedMode 51 | +CmdSelectLQOrDraft 52 | CmdSelectMicroWeavePrintMode 53 | CmdSelectPrinter 54 | CmdSelectPrintingColor 55 | CmdSelectPrintingOfUpperControlCodes 56 | CmdSelectSuperscriptSubscriptPrinting 57 | +CmdSelectTypeface 58 | CmdSelectUserDefinedSet 59 | CmdSelectVerticalTabChannel 60 | CmdSetAbsoluteHorizontalPrintPosition 61 | CmdSetAbsoluteVerticalPrintPosition 62 | CmdSetBottomMargin 63 | CmdSetFixedTabIncrement 64 | CmdSetHorizontalMotionIndex 65 | CmdSetHorizontalTabs 66 | CmdSetIntercharacterSpace 67 | CmdSetLeftMargin 68 | CmdSetMSBTo0 69 | CmdSetMSBTo1 70 | CmdSetPageFormat 71 | +CmdSetPageLength 72 | CmdSetPageLengthUnits 73 | +CmdSetRelativeHorizontalPrintPosition 74 | CmdSetRelativeVerticalPrintPosition 75 | CmdSetRightMargin 76 | CmdSetUnit 77 | CmdSetVerticalTabs 78 | CmdSetVerticalTabsInVFUChannels 79 | CmdTabHorizontally 80 | CmdTabVertically 81 | CmdTurnDoubleHeightPrinting 82 | CmdTurnDoubleWidthPrinting 83 | CmdTurnProportionalMode 84 | +CmdTurnUnderline 85 | CmdTurnUnidirectionalMode 86 | CmdUnidirectionalMode 87 | CmdUnknown 88 | -------------------------------------------------------------------------------- /doc/PCL5_Commands_structure.txt: -------------------------------------------------------------------------------- 1 | PCL5 commands structure for parser 2 | 3 | Normal commands 4 | char - CR, LF 5 | Esc commands 6 | [Esc]char - E, 9, = 7 | Extended Esc 8 | [Esc][family][subfamily]#[command][data] 9 | family - %, &, (, ), * 10 | subfamily - any small char 11 | # - 0 or more digits +/- 12 | cmd - any big letter or @ (look exceptions) 13 | data - optional data stream 14 | Exceptions 15 | [Esc](#X - Font Selection by ID 16 | [Esc])#X 17 | [Esc]%#B - Enter HP-GL/2 Mode 18 | -[Esc](3@..... 19 | -[Esc])3@..... 20 | -[Esc]&d@ 21 | 22 | [Esc](#M - Symbol Set 23 | [Esc]%-#X 24 | [Esc]&b#W...... 25 | [Esc]E 26 | [Esc]&l#X 27 | [Esc]&a#G 28 | [Esc]&u#D 29 | [Esc]&a#P 30 | [Esc]&c#T 31 | [Esc]&t#P 32 | [Esc]9 33 | [Esc]&k#H 34 | [Esc]*p#X 35 | [Esc]= 36 | [Esc]&f#S 37 | [Esc](#X 38 | [Esc])#X 39 | [Esc](3@..... 40 | [Esc])3@..... 41 | [Esc]&d@ 42 | [Esc](s#P 43 | [Esc])s#P 44 | [Esc]&p#X 45 | [Esc]&d#D 46 | [Esc]*c#D 47 | [Esc]&n#W........ 48 | [Esc](f#W..... 49 | [Esc]&f#X 50 | [Esc]*v#N 51 | [Esc]*l#O 52 | [Esc]*c#W......... 53 | [Esc]*t#R 54 | [Esc]*r#F 55 | [Esc]*b#Y 56 | [Esc]*rB 57 | [Esc]*rC 58 | [Esc]*v#W..... 59 | [Esc]*v#A 60 | [Esc]&p#S 61 | [Esc]*m#W 62 | [Esc]*l#W..... 63 | [Esc]*i#W...... 64 | [Esc]&b#M 65 | [Esc]*s#T 66 | [Esc]&r#F 67 | 68 | -------------------------------------------------------------------------------- /doc/Plan.txt: -------------------------------------------------------------------------------- 1 | Main class external interfaces 2 | 3 | Internal printer calculates with 3600 DPI resolution 4 | Highest possible print resolution is 720 DPI 5 | All external interfaces uses 72 DPI (float) resolution 6 | 7 | IInitialSetup 8 | void set/getPrinterType(printerType) // 24/9 pins 9 | void set/getDefaultPageLength(pageLength) // in inches 10 | void set/getAutoLF(bool) 11 | void set/getInternationalCharacterSet(int) 12 | 13 | IPrinterState 14 | Font getCurrentFont() 15 | Color getCurrentColor() 16 | 17 | IPrint (callback interface) 18 | void PageSize((float w, float h) 19 | void PrintText(float x, float y, string, IPrinterState) 20 | void PrintBitmap(float x, float y, BufferedImage, IPrinterState) 21 | 22 | IParse 23 | void Parse(InputStream, IPrint) 24 | 25 | For test there will be 2 IPrint implementation 26 | - text file output 27 | - AWT Image output 28 | -------------------------------------------------------------------------------- /doc/kwadraty.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigram/pcl-parser/a977bd61a3e80db928c1f970e94265923769e834/doc/kwadraty.doc -------------------------------------------------------------------------------- /src/gui/BitmapPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-26 3 | * 4 | */ 5 | 6 | import java.awt.Graphics; 7 | import java.awt.Image; 8 | 9 | import javax.swing.JPanel; 10 | 11 | /** 12 | * @author Piotrm 13 | */ 14 | public class BitmapPanel extends JPanel 15 | { 16 | private Image _img; 17 | 18 | /** Called when the window needs painting. 19 | * Computes X and Y range, scales. 20 | */ 21 | public void paintComponent(Graphics g) 22 | { 23 | super.paintComponent(g); 24 | 25 | if (_img != null) 26 | g.drawImage(_img, 0, 0, null); 27 | } 28 | 29 | /** 30 | * @return Returns the img. 31 | */ 32 | public Image getImg() 33 | { 34 | return _img; 35 | } 36 | /** 37 | * @param img The img to set. 38 | */ 39 | public void setImg(Image img) 40 | { 41 | this._img = img; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/gui/JARClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Aug 11, 2004 3 | */ 4 | import java.io.*; 5 | import java.net.*; 6 | import java.util.*; 7 | import java.util.jar.*; 8 | 9 | /** 10 | * @author Matthew D. Hicks 11 | */ 12 | public class JARClassLoader extends URLClassLoader { 13 | protected File _file; 14 | protected JarFile jar; 15 | 16 | public JARClassLoader(File file) throws MalformedURLException, IOException { 17 | super(new URL[] {file.toURL()}); 18 | this._file = file; 19 | this.jar = new JarFile(file); 20 | } 21 | 22 | public Class[] getClasses() throws ClassNotFoundException { 23 | ArrayList list = new ArrayList(500); 24 | Enumeration e = jar.entries(); 25 | JarEntry entry; 26 | while (e.hasMoreElements()) { 27 | entry = (JarEntry)e.nextElement(); 28 | if ((!entry.isDirectory()) && (entry.getName().endsWith(".class"))) { 29 | list.add(entry.getName().replaceAll("/", ".").substring(0, entry.getName().length() - 6)); 30 | } 31 | } 32 | Class[] classes = new Class[list.size()]; 33 | for (int i = 0; i < list.size(); i++) { 34 | classes[i] = this.loadClass((String)list.get(i)); 35 | } 36 | 37 | return classes; 38 | } 39 | 40 | public static void main(String[] args) throws Exception { 41 | File file = new File("myclasses.jar"); 42 | JARClassLoader loader = new JARClassLoader(file); 43 | Class[] classes = loader.getClasses(); 44 | for (int i = 0; i < classes.length; i++) { 45 | System.out.println("Class: " + classes[i].getName()); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/gui/JFileFilter.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.util.*; 3 | 4 | /** A simple FileFilter class that works by filename extension, 5 | * like the one in the JDK demo called ExtentionFilter, which 6 | * has been announced to be supported in a future Swing release. 7 | */ 8 | class JFileFilter extends javax.swing.filechooser.FileFilter { 9 | protected String description; 10 | protected ArrayList exts = new ArrayList(); 11 | 12 | public void addType(String s) 13 | { 14 | exts.add(s); 15 | } 16 | 17 | /** Return true if the given file is accepted by this filter. */ 18 | public boolean accept(File f) { 19 | // Little trick: if you don't do this, only directory names 20 | // ending in one of the extensions appear in the window. 21 | if (f.isDirectory( )) { 22 | return true; 23 | } else if (f.isFile( )) { 24 | Iterator it = exts.iterator( ); 25 | while (it.hasNext( )) { 26 | if (f.getName().endsWith((String)it.next( ))) 27 | return true; 28 | } 29 | } 30 | // A file that didn't match, or a weirdo (e.g. UNIX device file?). 31 | return false; 32 | } 33 | 34 | /** Set the printable description of this filter. */ 35 | public void setDescription(String s) 36 | { 37 | description = s; 38 | } 39 | 40 | /** Return the printable description of this filter. */ 41 | public String getDescription( ) 42 | { 43 | return description; 44 | } 45 | } -------------------------------------------------------------------------------- /src/gui/TextOutputText.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-12 3 | * 4 | */ 5 | 6 | import java.util.ArrayList; 7 | 8 | /** 9 | * Sample rasterizer 10 | * 11 | * @author Piotrm 12 | */ 13 | public class TextOutputText 14 | { 15 | /** 16 | * run text-output rasterizer 17 | * 18 | * @param filename file to interpret 19 | */ 20 | // static private void runText(String filename) 21 | // { 22 | // if (filename == null) 23 | // { 24 | // System.out.println("Usage: TextOutputText file"); 25 | // return; 26 | // } 27 | // 28 | // InputStream is; 29 | // try 30 | // { 31 | // is = new FileInputStream(filename); 32 | // 33 | // TextRasterizer txtRasterizer = new TextRasterizer(new PrintWriter(System.out, true)); 34 | // 35 | // Interpreter interpreter = new Interpreter(); 36 | // 37 | // interpreter.parse(is, txtRasterizer); 38 | // } 39 | // catch (FileNotFoundException e) 40 | // { 41 | // e.printStackTrace(); 42 | // } 43 | // catch (IOException e) 44 | // { 45 | // e.printStackTrace(); 46 | // } 47 | // } 48 | 49 | /** 50 | * run graphics-output rasterizer 51 | * 52 | * @param filename file to interpret 53 | */ 54 | static private void runGUI(String filename) 55 | { 56 | GUIRasterizer guiRasterizer = new GUIRasterizer(); 57 | guiRasterizer.setInputFile(filename); 58 | guiRasterizer.setSize(500, 400); 59 | guiRasterizer.setVisible(true); 60 | } 61 | 62 | public static void main(String[] args) 63 | { 64 | ArrayList a = new ArrayList(100); 65 | for(int i = 0; i < 20; i++) 66 | a.add("abc"); 67 | 68 | a.add(5, "cde"); 69 | a.set(10, "fgh"); 70 | a.set(8, null); 71 | a.set(8, "xxx"); 72 | 73 | if (args.length == 1) 74 | runGUI(args[0]); 75 | else 76 | runGUI(null); 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/gui/TextRasterizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-12 3 | * 4 | */ 5 | 6 | import java.awt.*; 7 | import java.awt.image.BufferedImage; 8 | import java.io.*; 9 | 10 | import org.getopt.pcl5.IPrint; 11 | import org.getopt.pcl5.IPrinterState; 12 | 13 | 14 | /** 15 | * @author Piotrm 16 | * 17 | * TODO To change the template for this generated type comment go to 18 | * Window - Preferences - Java - Code Style - Code Templates 19 | */ 20 | public class TextRasterizer implements IPrint 21 | { 22 | private PrintWriter writer; 23 | 24 | public TextRasterizer(PrintWriter wr) 25 | { 26 | writer = wr; 27 | } 28 | 29 | public void pageSize(float w, float h) 30 | { 31 | writer.println("New page size: [" + w + ", " + h + "]"); 32 | } 33 | 34 | public void printText(float x, float y, float w, float h, String text, int[] kerning, IPrinterState state) 35 | { 36 | Font fnt = state.getFont(); 37 | Color clr = state.getCurrentColor(); 38 | 39 | writer.print("[" + x + ", " + y + "] "); 40 | writer.print("[" + w + ", " + h + "] "); 41 | writer.print("[F:" + fnt.getFontName() + ", " + fnt.getSize() + "]"); 42 | writer.print("[C:" + clr + "]"); 43 | writer.println("|" + text + "|"); 44 | } 45 | 46 | /* (non-Javadoc) 47 | * @see pl.biz.coda.ESCP2Interpreter.IPrint#PrintBitmap(float, float, java.awt.Image, pl.biz.coda.ESCP2Interpreter.IPrinterState) 48 | */ 49 | public void printBitmap(float x, float y, float w, float h, BufferedImage image, IPrinterState state) 50 | { 51 | writer.print("[" + x + ", " + y + "] "); 52 | writer.print("[" + w + ", " + h + "] "); 53 | writer.print("[" + image.getWidth() + ", " + image.getHeight() + "]"); 54 | writer.println(" bitmap"); 55 | } 56 | 57 | /* (non-Javadoc) 58 | * @see com.ccginc.escp.ESCP2Interpreter.IPrint#trace(java.lang.String, java.lang.String) 59 | */ 60 | public void trace(Object command, String message) 61 | { 62 | writer.println("**TRACE** " + command.toString() + " " + message); 63 | } 64 | 65 | /* (non-Javadoc) 66 | * @see com.ccginc.escp.ESCP2Interpreter.IPrint#assertCondition(java.lang.String, java.lang.String) 67 | */ 68 | public void assertCondition(Object command, String message) 69 | { 70 | writer.println("**ASSERT** " + command.toString() + " " + message); 71 | } 72 | 73 | /* (non-Javadoc) 74 | * @see com.ccginc.escp.ESCP2Interpreter.IPrint#notImplemented(java.lang.String, java.lang.String) 75 | */ 76 | public void notImplemented(Object command, String message) 77 | { 78 | writer.println("**NOT IMPLEMENTED** " + command.toString() + " " + message); 79 | } 80 | 81 | /* (non-Javadoc) 82 | * @see com.ccginc.escp.ESCP2Interpreter.IPrint#newPage() 83 | */ 84 | public void newPage() 85 | { 86 | writer.println("########## NEW PAGE ##########"); 87 | } 88 | 89 | /* (non-Javadoc) 90 | * @see com.ccginc.escp.ESCP2Interpreter.IPrint#newMargins(float, float, float, float) 91 | */ 92 | public void newMargins(float top, float bottom, float left, float right) 93 | { 94 | writer.println("New margins set: [" + top + " " + bottom + " " + left + " " + right + "]"); 95 | } 96 | 97 | /* (non-Javadoc) 98 | * @see com.ccginc.escp.ESCP2Interpreter.IPrint#processingStart() 99 | */ 100 | public void processingStart() 101 | { 102 | writer.println("*** Process start ***"); 103 | } 104 | 105 | /* (non-Javadoc) 106 | * @see com.ccginc.escp.ESCP2Interpreter.IPrint#processingEnd() 107 | */ 108 | public void processingEnd() 109 | { 110 | writer.println("*** Process end ***"); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/gui/VectorButton.java: -------------------------------------------------------------------------------- 1 | // from Swing Hacks 2 | 3 | import java.awt.*; 4 | import java.awt.geom.*; 5 | import java.awt.event.*; 6 | import javax.swing.*; 7 | 8 | public class VectorButton extends JButton implements MouseListener { 9 | public VectorButton() { 10 | this.addMouseListener(this); 11 | } 12 | 13 | public Dimension getPreferredSize() { 14 | String text = getText(); 15 | FontMetrics fm = this.getFontMetrics(getFont()); 16 | float scale = (50f / 30f) * this.getFont().getSize2D(); 17 | int w = fm.stringWidth(text); 18 | w += (int) (scale * 1.4f); 19 | int h = fm.getHeight(); 20 | h += (int) (scale * .3f); 21 | return new Dimension(w, h); 22 | } 23 | 24 | public void paintComponent(Graphics g) { 25 | Graphics2D g2 = (Graphics2D) g; 26 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 27 | RenderingHints.VALUE_ANTIALIAS_ON); 28 | g2.setColor(this.getBackground()); 29 | g2.fillRect(0, 0, this.getWidth(), this.getHeight()); 30 | 31 | float scale = (50f / 30f) * this.getFont().getSize2D(); 32 | 33 | drawLiquidButton(this.getForeground(), this.getWidth(), this 34 | .getHeight(), getText(), scale, g2); 35 | } 36 | 37 | protected void drawLiquidButton(Color base, int width, int height, 38 | String text, float scale, Graphics2D g2) { 39 | 40 | // calculate inset 41 | int inset = (int) (scale * 0.04f); 42 | int w = width - inset * 2 - 1; 43 | int h = height - (int) (scale * 0.1f) - 1; 44 | 45 | g2.translate(inset, 0); 46 | drawDropShadow(w, h, scale, g2); 47 | 48 | if (pressed) { 49 | g2.translate(0, 0.04f * scale); 50 | } 51 | 52 | drawButtonBody(w, h, scale, base, g2); 53 | drawText(w, h, scale, text, g2); 54 | drawHighlight(w, h, scale, base, g2); 55 | drawBorder(w, h, scale, g2); 56 | 57 | if (pressed) { 58 | g2.translate(0, 0.04f * scale); 59 | } 60 | g2.translate(-inset, 0); 61 | } 62 | 63 | protected void drawDropShadow(int w, int h, float scale, Graphics2D g2) { 64 | // draw the outer drop shadow 65 | g2.setColor(new Color(0, 0, 0, 50)); 66 | VectorButton.fillRoundRect(g2, (-.04f) * scale, (.02f) * scale, w + .08f 67 | * scale, h + 0.08f * scale, scale * 1.04f, scale * 1.04f); 68 | g2.setColor(new Color(0, 0, 0, 100)); 69 | VectorButton.fillRoundRect(g2, 0, 0.06f * scale, w, h, scale, scale); 70 | } 71 | 72 | protected void drawButtonBody(int w, int h, float scale, Color base, 73 | Graphics2D g2) { 74 | // draw the button body 75 | Color grad_top = base.brighter(); 76 | Color grad_bot = base.darker(); 77 | GradientPaint bg = new GradientPaint(new Point(0, 0), grad_top, 78 | new Point(0, h), grad_bot); 79 | g2.setPaint(bg); 80 | VectorButton.fillRoundRect(g2, (0) * scale, (0) * scale, w, h, 1 * scale, 81 | 1 * scale); 82 | 83 | // draw the inner color 84 | Color inner = base.brighter(); 85 | inner = alphaColor(inner, 75); 86 | g2.setColor(inner); 87 | VectorButton.fillRoundRect(g2, scale * (.4f), scale * (.4f), w - scale * .8f, h 88 | - scale * .5f, scale * .6f, scale * .4f); 89 | } 90 | 91 | protected void drawText(int w, int h, float scale, String text, 92 | Graphics2D g2) { 93 | // calculate the width and height 94 | int fw = g2.getFontMetrics().stringWidth(text); 95 | int fh = g2.getFontMetrics().getAscent() 96 | - g2.getFontMetrics().getDescent(); 97 | int textx = (w - fw) / 2; 98 | int texty = h / 2 + fh / 2; 99 | 100 | // draw the text 101 | g2.setColor(new Color(0, 0, 0, 70)); 102 | g2.drawString(text, (int) ((float) textx + scale * (0.04f)), 103 | (int) ((float) texty + scale * (0.04f))); 104 | g2.setColor(Color.black); 105 | g2.drawString(text, textx, texty); 106 | } 107 | 108 | protected void drawHighlight(int w, int h, float scale, Color base, Graphics2D g2) { 109 | // create the highlight 110 | GradientPaint highlight = new GradientPaint(new Point2D.Float( 111 | scale * 0.2f, scale * 0.2f), new Color(255, 255, 255, 175), 112 | new Point2D.Float(scale * 0.2f, scale * 0.55f), new Color(255, 113 | 255, 255, 0)); 114 | g2.setPaint(highlight); 115 | VectorButton.fillRoundRect(g2, scale * 0.2f, scale * 0.1f, w - scale * 0.4f, 116 | scale * 0.4f, scale * 0.8f, scale * 0.4f); 117 | VectorButton.drawRoundRect(g2, scale * 0.2f, scale * 0.1f, w - scale * 0.4f, 118 | scale * 0.4f, scale * 0.8f, scale * 0.4f); 119 | } 120 | 121 | protected void drawBorder(int w, int h, float scale, Graphics2D g2) { 122 | // draw the border 123 | g2.setColor(new Color(0, 0, 0, 150)); 124 | VectorButton.drawRoundRect(g2, scale * (0f), scale * (0f), w, h, scale, scale); 125 | } 126 | 127 | // float version of fill round rect 128 | protected static void fillRoundRect(Graphics2D g2, float x, float y, 129 | float w, float h, float ax, float ay) { 130 | g2 131 | .fillRoundRect((int) x, (int) y, (int) w, (int) h, (int) ax, 132 | (int) ay); 133 | } 134 | 135 | // float version of draw round rect 136 | protected static void drawRoundRect(Graphics2D g2, float x, float y, 137 | float w, float h, float ax, float ay) { 138 | g2 139 | .drawRoundRect((int) x, (int) y, (int) w, (int) h, (int) ax, 140 | (int) ay); 141 | } 142 | 143 | // generate the alpha version of this color 144 | protected static Color alphaColor(Color color, int alpha) { 145 | return new Color(color.getRed(), color.getGreen(), color.getBlue(), 146 | alpha); 147 | } 148 | 149 | /* mouse listener implementation */ 150 | protected boolean pressed = false; 151 | 152 | public void mouseExited(MouseEvent evt) { 153 | } 154 | 155 | public void mouseEntered(MouseEvent evt) { 156 | } 157 | 158 | public void mouseClicked(MouseEvent evt) { 159 | } 160 | 161 | public void mouseReleased(MouseEvent evt) { 162 | pressed = false; 163 | } 164 | 165 | public void mousePressed(MouseEvent evt) { 166 | pressed = true; 167 | } 168 | 169 | public static void p(String s) { 170 | System.out.println(s); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/CommonPrinterState.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5; 2 | 3 | public class CommonPrinterState { 4 | 5 | public class SymbolSet { 6 | final public static int Roman_8 = 0; 7 | } 8 | 9 | public class RasterMode { 10 | final public static int LogicalPage = 0; 11 | final public static int PhysicalPage = 3; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/FontDefinition.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5; 2 | 3 | import org.getopt.pcl5.PCL5Interpreter.TypefaceInfo; 4 | import org.getopt.pcl5.PrinterState.Spacing; 5 | import org.getopt.pcl5.PrinterState.StrokeWeight; 6 | import org.getopt.pcl5.PrinterState.Style; 7 | 8 | class FontDefinition { 9 | private int _spacing; 10 | private int _pitch; 11 | private float _height; 12 | private int _style; 13 | private int _strokeWeight; 14 | private int _typeface; 15 | private String _fontName; 16 | private String _vendorName; 17 | 18 | FontDefinition() { 19 | resetPCL(); 20 | } 21 | 22 | void resetPCL() { 23 | _spacing = Spacing.Fixed; 24 | _pitch = 10; // cpi 25 | _height = 12; // point 26 | _style = Style.Upright; 27 | _strokeWeight = StrokeWeight.Medium; 28 | setTypeface(0); 29 | } 30 | 31 | void resetHPGL() { 32 | _spacing = Spacing.Fixed; 33 | _pitch = 9; // cpi 34 | _height = 11.5f; // point 35 | _style = Style.Upright; 36 | _strokeWeight = StrokeWeight.Medium; 37 | setTypeface(0); 38 | } 39 | 40 | public float getHeight() { 41 | return _height; 42 | } 43 | 44 | public void setHeight(float height) { 45 | _height = height; 46 | } 47 | 48 | public int getPitch() { 49 | return _pitch; 50 | } 51 | 52 | public void setPitch(int pitch) { 53 | _pitch = pitch; 54 | } 55 | 56 | public int getSpacing() { 57 | return _spacing; 58 | } 59 | 60 | public void setSpacing(int spacing) { 61 | _spacing = spacing; 62 | } 63 | 64 | public int getStrokeWeight() { 65 | return _strokeWeight; 66 | } 67 | 68 | public void setStrokeWeight(int strokeWeight) { 69 | _strokeWeight = strokeWeight; 70 | } 71 | 72 | public int getStyle() { 73 | return _style; 74 | } 75 | 76 | public void setStyle(int style) { 77 | _style = style; 78 | } 79 | 80 | public int getTypeface() { 81 | return _typeface; 82 | } 83 | 84 | public void setTypeface(int typeface) { 85 | _typeface = typeface; 86 | _fontName = TypefaceInfo.getFontName(typeface); 87 | _vendorName = TypefaceInfo.getVendorName(typeface); 88 | } 89 | 90 | public String getFontName() { 91 | return _fontName; 92 | } 93 | 94 | public String getVendorName() { 95 | return _vendorName; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdAbsoluteArcThreePoint.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdAbsoluteArcThreePoint extends CommandHPGL { 9 | 10 | public CmdAbsoluteArcThreePoint(PrinterState printerState) { 11 | super(printerState); 12 | 13 | _command = "AT"; 14 | } 15 | 16 | protected void execute(InputStream in) throws IOException { 17 | String s = readInput(in); 18 | String[] params = s.split(","); 19 | 20 | // begining of arc is in current point 21 | // int x = _hpgl.getX() + Integer.parseInt(params[0]); 22 | // int y = _hpgl.getY() + Integer.parseInt(params[1]); 23 | // double angle = Double.parseDouble(params[2]); 24 | // 25 | // _hpgl.drawArc(x, y, angle); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdAdvanceFullPage.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdAdvanceFullPage extends CommandHPGL { 9 | 10 | public CmdAdvanceFullPage(PrinterState printerState) { 11 | super(printerState); 12 | _command = "PG"; 13 | } 14 | 15 | protected void execute(InputStream in) throws IOException { 16 | _printerState.trace(this, "Not implemented"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdArcAbsolute.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdArcAbsolute extends CommandHPGL { 9 | 10 | public CmdArcAbsolute(PrinterState printerState) { 11 | super(printerState); 12 | 13 | _command = "AA"; 14 | } 15 | 16 | protected void execute(InputStream in) throws IOException { 17 | String s = readInput(in); 18 | String[] params = s.split(","); 19 | 20 | // begining of arc is in current point 21 | int x = Integer.parseInt(params[0]); 22 | int y = Integer.parseInt(params[1]); 23 | double angle = Double.parseDouble(params[2]); 24 | 25 | _hpgl.drawArc(x, y, angle); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdArcRelative.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdArcRelative extends CommandHPGL { 9 | 10 | public CmdArcRelative(PrinterState printerState) { 11 | super(printerState); 12 | 13 | _command = "AC"; 14 | } 15 | 16 | protected void execute(InputStream in) throws IOException { 17 | String s = readInput(in); 18 | String[] params = s.split(","); 19 | 20 | // begining of arc is in current point 21 | int x = _hpgl.getX() + Integer.parseInt(params[0]); 22 | int y = _hpgl.getY() + Integer.parseInt(params[1]); 23 | double angle = Double.parseDouble(params[2]); 24 | 25 | _hpgl.drawArc(x, y, angle); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdComment.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.getopt.pcl5.HPGLInterpreter.cmd; 5 | 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | 9 | import org.getopt.pcl5.PrinterState; 10 | 11 | /** 12 | * @author pmarkiew 13 | * 14 | */ 15 | public class CmdComment extends CommandHPGL { 16 | 17 | /** 18 | * @param printerState 19 | */ 20 | public CmdComment(PrinterState printerState) { 21 | super(printerState); 22 | 23 | _command = "CO"; 24 | } 25 | 26 | /* 27 | * (non-Javadoc) 28 | * 29 | * @see 30 | * com.ccginc.pcl5.HPGLInterpreter.cmd.CommandHPGL#execute(java.io.InputStream 31 | * ) 32 | */ 33 | protected void execute(InputStream in) throws IOException { 34 | char c = (char) in.read(); 35 | 36 | while (c != '"') 37 | // first quote 38 | c = (char) in.read(); 39 | 40 | StringBuilder sb = new StringBuilder(); 41 | c = (char) in.read(); 42 | while (c != '"') // end quote 43 | { 44 | sb.append(c); 45 | c = (char) in.read(); 46 | } 47 | 48 | _printerState.trace(this, sb.toString()); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdDefaultValues.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdDefaultValues extends CommandHPGL { 9 | 10 | public CmdDefaultValues(PrinterState printerState) { 11 | super(printerState); 12 | } 13 | 14 | protected void execute(InputStream in) throws IOException { 15 | _printerState.resetHPGLDefaultValues(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdEscCommand.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdEscCommand extends EscCommandHPGL { 9 | 10 | public CmdEscCommand(PrinterState printerState) { 11 | super(printerState); 12 | } 13 | 14 | char _cmd; 15 | 16 | protected int readNum(InputStream in) throws IOException { 17 | char c = (char) in.read(); 18 | String number = ""; 19 | 20 | while (c == '+' || c == '-' || Character.isDefined(c)) 21 | number += c; 22 | 23 | // TODO: state class variable, but I can't return 2 values 24 | _cmd = c; 25 | 26 | return Integer.parseInt(number); 27 | } 28 | 29 | public boolean execute(char cmd, InputStream in) throws IOException { 30 | if (cmd == '%') { 31 | int param = readNum(in); 32 | 33 | if ((param == -12345) && (_cmd == 'X')) { 34 | // _printerState.reset(); 35 | _printerState.setActiveLanguage(PrinterState.Language.PJL); 36 | 37 | return true; 38 | } else if (_cmd == 'A') { 39 | _printerState.setActiveLanguage(PrinterState.Language.PCL5); 40 | 41 | return true; 42 | } 43 | } 44 | 45 | return false; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdInputAbsolute.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.awt.Point; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | 7 | import org.getopt.pcl5.PrinterState; 8 | 9 | public class CmdInputAbsolute extends CommandHPGL { 10 | 11 | public CmdInputAbsolute(PrinterState printerState) { 12 | super(printerState); 13 | 14 | _command = "IP"; 15 | } 16 | 17 | protected void execute(InputStream in) throws IOException { 18 | String s = readInput(in); 19 | String[] params = s.split(","); 20 | 21 | Point p1 = _printerState.getHPGLState().getP1(); 22 | Point p2 = _printerState.getHPGLState().getP2(); 23 | 24 | if (params.length == 0) // no params 25 | { 26 | p1 = new Point(0, 0); 27 | p2 = new Point(_printerState.getHorizontaPictureFrameSize(), 28 | _printerState.getVerticalPictureFrameSize()); 29 | } else if (params.length == 2) // P1 only 30 | { 31 | int x = Integer.parseInt(params[0]); 32 | int y = Integer.parseInt(params[1]); 33 | 34 | p2.setLocation(p2.getX() + x - p1.getX(), p2.getY() + y - p1.getY()); 35 | p1.setLocation(x, y); 36 | } else if (params.length == 4) // P1 and P2 37 | { 38 | int x = Integer.parseInt(params[0]); 39 | int y = Integer.parseInt(params[1]); 40 | p1.setLocation(x, y); 41 | 42 | x = Integer.parseInt(params[2]); 43 | y = Integer.parseInt(params[3]); 44 | p2.setLocation(x, y); 45 | } else { 46 | _printerState.assertCondition(this, "Incorrect numer of parameters"); 47 | } 48 | 49 | _printerState.getHPGLState().setP1(p1); 50 | _printerState.getHPGLState().setP2(p2); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdInputRelative.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.awt.Point; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | 7 | import org.getopt.pcl5.PrinterState; 8 | 9 | public class CmdInputRelative extends CommandHPGL { 10 | 11 | public CmdInputRelative(PrinterState printerState) { 12 | super(printerState); 13 | 14 | _command = "IR"; 15 | } 16 | 17 | protected void execute(InputStream in) throws IOException { 18 | String s = readInput(in); 19 | String[] params = s.split(","); 20 | 21 | Point p1 = _printerState.getHPGLState().getP1(); 22 | Point p2 = _printerState.getHPGLState().getP2(); 23 | 24 | if (params.length == 0) // no params 25 | { 26 | p1 = new Point(0, 0); 27 | p2 = new Point(_printerState.getHorizontaPictureFrameSize(), 28 | _printerState.getVerticalPictureFrameSize()); 29 | } else if (params.length == 2) // P1 only 30 | { 31 | int x = (int) ((p1.getX() * 100) / Integer.parseInt(params[0])); 32 | int y = (int) ((p1.getY() * 100) / Integer.parseInt(params[1])); 33 | 34 | p2.setLocation(p2.getX() + x - p1.getX(), p2.getY() + y - p1.getY()); 35 | p1.setLocation(x, y); 36 | } else if (params.length == 4) // P1 and P2 37 | { 38 | int x = (int) ((p1.getX() * 100) / Integer.parseInt(params[0])); 39 | int y = (int) ((p1.getY() * 100) / Integer.parseInt(params[1])); 40 | p1.setLocation(x, y); 41 | 42 | x = (int) ((p2.getX() * 100) / Integer.parseInt(params[2])); 43 | y = (int) ((p2.getY() * 100) / Integer.parseInt(params[3])); 44 | p2.setLocation(x, y); 45 | } else { 46 | _printerState.assertCondition(this, "Incorrect numer of parameters"); 47 | } 48 | 49 | _printerState.getHPGLState().setP1(p1); 50 | _printerState.getHPGLState().setP2(p2); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdInputWindow.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.awt.Rectangle; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | 7 | import org.getopt.pcl5.PrinterState; 8 | 9 | public class CmdInputWindow extends CommandHPGL { 10 | 11 | public CmdInputWindow(PrinterState printerState) { 12 | super(printerState); 13 | 14 | _command = "IW"; 15 | } 16 | 17 | protected void execute(InputStream in) throws IOException { 18 | String s = readInput(in); 19 | String[] params = s.split(","); 20 | 21 | if (params.length == 0) // no params 22 | _hpgl.setInputWindow(new Rectangle(0, 0, _printerState 23 | .getHorizontaPictureFrameSize(), _printerState 24 | .getVerticalPictureFrameSize())); 25 | else if (params.length == 4) 26 | _hpgl.setInputWindow(new Rectangle(Integer.parseInt(params[0]), Integer 27 | .parseInt(params[1]), Integer.parseInt(params[2]), Integer 28 | .parseInt(params[3]))); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdReplot.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdReplot extends CommandHPGL { 9 | 10 | public CmdReplot(PrinterState printerState) { 11 | super(printerState); 12 | _command = "RP"; 13 | } 14 | 15 | protected void execute(InputStream in) throws IOException { 16 | _printerState.trace(this, "Not implemented"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdRotateCoordinateSystem.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdRotateCoordinateSystem extends CommandHPGL { 9 | 10 | public CmdRotateCoordinateSystem(PrinterState printerState) { 11 | super(printerState); 12 | _command = "RO"; 13 | } 14 | 15 | protected void execute(InputStream in) throws IOException { 16 | String s = readInput(in); 17 | 18 | int rotation = 0; 19 | 20 | if (s.length() > 0) 21 | rotation = Integer.parseInt(s); 22 | 23 | _hpgl.setDrawingRotation(rotation); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdScale.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdScale extends CommandHPGL { 9 | 10 | public CmdScale(PrinterState printerState) { 11 | super(printerState); 12 | 13 | _command = "SC"; 14 | } 15 | 16 | protected void execute(InputStream in) throws IOException { 17 | String s = readInput(in); 18 | String[] params = s.split(","); 19 | 20 | if (params.length == 0) { 21 | // _hpgl.setScale(1.0, 1.0); 22 | } else if (params.length == 4) { 23 | // _hpgl.setScale(1.0, 1.0); 24 | } else if (params.length == 5) { 25 | 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdUniversalExitLanguage.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdUniversalExitLanguage extends CommandHPGL { 9 | 10 | public CmdUniversalExitLanguage(PrinterState printerState) { 11 | super(printerState); 12 | } 13 | 14 | char _cmd; 15 | 16 | protected int readNum(InputStream in) throws IOException { 17 | char c = (char) in.read(); 18 | String number = ""; 19 | 20 | while (c == '+' || c == '-' || Character.isDefined(c)) 21 | number += c; 22 | 23 | // TODO: state class variable, but I can't return 2 values 24 | _cmd = c; 25 | 26 | return Integer.parseInt(number); 27 | } 28 | 29 | public boolean execute(char cmd, InputStream in) throws IOException { 30 | if (cmd == '%') { 31 | int param = readNum(in); 32 | 33 | if ((param == -12345) && (_cmd == 'X')) { 34 | // _printerState.reset(); 35 | _printerState.setActiveLanguage(PrinterState.Language.PJL); 36 | 37 | return true; 38 | } 39 | } 40 | 41 | return false; 42 | } 43 | 44 | public boolean execute(String[] cmd) { 45 | // TODO Auto-generated method stub 46 | return false; 47 | } 48 | 49 | protected void execute(InputStream in) throws IOException { 50 | // TODO Auto-generated method stub 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CmdUnknownHPGL.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.getopt.pcl5.PrinterState; 6 | 7 | public class CmdUnknownHPGL extends CommandHPGL { 8 | 9 | public CmdUnknownHPGL(PrinterState printerState) { 10 | super(printerState); 11 | } 12 | 13 | public boolean execute(String cmd, InputStream in) { 14 | _printerState.trace(this.toString(), "Unknown HPGL command " + cmd); 15 | 16 | return false; 17 | } 18 | 19 | protected void execute(InputStream in) { 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/CommandHPGL.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public abstract class CommandHPGL { 9 | 10 | PrinterState _printerState; 11 | String _command; 12 | PrinterState.HPGLState _hpgl; 13 | 14 | public CommandHPGL(PrinterState printerState) { 15 | _printerState = printerState; 16 | _hpgl = _printerState.getHPGLState(); 17 | } 18 | 19 | public boolean execute(String cmd, InputStream in) throws IOException { 20 | if (cmd.equalsIgnoreCase(_command)) { 21 | execute(in); 22 | 23 | return true; 24 | } 25 | 26 | return false; 27 | } 28 | 29 | abstract protected void execute(InputStream in) throws IOException; 30 | 31 | protected String readInput(InputStream in) throws IOException { 32 | StringBuilder sb = new StringBuilder(); 33 | 34 | int data = in.read(); 35 | 36 | while (data != -1 && (char) data != ';') { 37 | sb.append((char) data); 38 | data = in.read(); 39 | } 40 | 41 | return sb.toString(); 42 | } 43 | 44 | /** 45 | * Can return command code in derived class, if returned class will be put in 46 | * hashtable 47 | * 48 | * @return code for command, null means not set 49 | */ 50 | public String getCommandString() { 51 | return _command; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/HPGLInterpreter/cmd/EscCommandHPGL.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.HPGLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class EscCommandHPGL { 9 | PrinterState _printerState; 10 | 11 | public EscCommandHPGL(PrinterState printerState) { 12 | _printerState = printerState; 13 | } 14 | 15 | public boolean execute(char cmd, InputStream in) throws IOException { 16 | return false; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/IPrint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-12 3 | * 4 | */ 5 | package org.getopt.pcl5; 6 | 7 | import java.awt.image.BufferedImage; 8 | 9 | /** 10 | * Callback interface, called when something to print happens Should be 11 | * implemented by rasterizer 12 | * 13 | * Every parameter is scaled in 72 DPI 14 | * 15 | */ 16 | public interface IPrint { 17 | /** 18 | * Called when new page 19 | * 20 | */ 21 | void newPage(); 22 | 23 | /** 24 | * Called when page size changed 25 | * 26 | * @param w 27 | * New width of page, in 72 DPI 28 | * @param h 29 | * New height of page, in 72 DPI 30 | */ 31 | void pageSize(float w, float h); 32 | 33 | /** 34 | * Called after every margins change and after each new page 35 | * 36 | * @param top 37 | * top margin, in 72 DPI 38 | * @param bottom 39 | * bottom margin, in 72 DPI 40 | * @param left 41 | * left margin, in 72 DPI 42 | * @param right 43 | * right margin, in 72 DPI 44 | */ 45 | void newMargins(float top, float bottom, float left, float right); 46 | 47 | /** 48 | * Called on beginning of processing, before any other method from this 49 | * interface is called 50 | * 51 | */ 52 | void processingStart(); 53 | 54 | /** 55 | * Called on end of processing, after last method from this interface was 56 | * called 57 | * 58 | */ 59 | void processingEnd(); 60 | 61 | /** 62 | * Called when text should be printed, text is limited to end of line (CR) or 63 | * to change in pronter state (ie font) 64 | * 65 | * @param x 66 | * Print location X in 72 DPI 67 | * @param y 68 | * Print location Y in 72 DPI 69 | * @param w 70 | * Width of text (bound box) in 72 DPI 71 | * @param h 72 | * Height of text in (bound box) 72 DPI 73 | * @param text 74 | * Text to print 75 | * @param state 76 | * Interface to query state of printer 77 | */ 78 | void printText(float x, float y, float w, float h, String text, 79 | int[] kerning, IPrinterState state); 80 | 81 | /** 82 | * Called when bitmap should be printed, bitmap is always complete method is 83 | * called when graphics mode is terminated 84 | * 85 | * @param x 86 | * X location of image in 72 DPI 87 | * @param y 88 | * Y location of image in 72 DPI 89 | * @param w 90 | * Width of bitmap in (bound box) 72 DPI 91 | * @param h 92 | * Height of bitmap in (bound box) 72 DPI 93 | * @param image 94 | * Image for output 95 | * @param state 96 | * Interface to query state of printer 97 | */ 98 | void printBitmap(float x, float y, float w, float h, BufferedImage image, 99 | IPrinterState state); 100 | 101 | /** 102 | * Called on condition like command without meaning for interpreter like BEL 103 | * 104 | * @param command 105 | * class 106 | * @param message 107 | * command name 108 | */ 109 | void trace(Object command, String message); 110 | 111 | /** 112 | * Called when command parameters are incorrect ie out of range 113 | * 114 | * @param command 115 | * class that detected problem 116 | * @param message 117 | * kind of problem 118 | */ 119 | void assertCondition(Object command, String message); 120 | 121 | /** 122 | * Called when found command that shouldn't be implemented ie CAN Cancel line 123 | * 124 | * @param command 125 | * class that detected problem 126 | * @param message 127 | * kind of problem 128 | */ 129 | void notImplemented(Object command, String message); 130 | } 131 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/IPrinterState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-12 3 | * 4 | */ 5 | package org.getopt.pcl5; 6 | 7 | import java.awt.*; 8 | import java.util.Map; 9 | 10 | /** 11 | * Printer state interface, allows access to internal printer state 12 | * 13 | * TODO Exception specification 14 | */ 15 | public interface IPrinterState { 16 | /** 17 | * Returns current font used by printer. Do not cache this value. 18 | * 19 | * @return current Font class 20 | */ 21 | Font getFont(); 22 | 23 | /** 24 | * Returns current font attributes 25 | * 26 | * @return current font attribute 27 | */ 28 | Map getFontAttributes(); 29 | 30 | /** 31 | * Return current color used by printer Do not cache this value. 32 | * 33 | * @return Current color 34 | */ 35 | Color getCurrentColor(); 36 | 37 | /** 38 | * Return true is printer has selected condensed font 39 | * 40 | * @return condensed printer state 41 | */ 42 | boolean isCondensed(); 43 | 44 | int getUnderliningMode(); 45 | } 46 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/BaseCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | import org.getopt.pcl5.PrinterState; 8 | 9 | /** 10 | * Base class for all command classes Contains instance of PrinterState 11 | */ 12 | class BaseCommand { 13 | PrinterState _printerState; 14 | 15 | BaseCommand(PrinterState printerState) { 16 | this._printerState = printerState; 17 | } 18 | 19 | /** 20 | * Can return command code in derived class, if returned class will be put in 21 | * hashtable 22 | * 23 | * @return code for command, 0 means not set 24 | */ 25 | public char getCommandCode() { 26 | return 0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | import org.getopt.pcl5.PrinterState; 8 | 9 | /** 10 | * Base class to handle control codes commands Main reason for this class is to 11 | * create dinstinct type of commands 12 | */ 13 | abstract class Command extends BaseCommand { 14 | /** 15 | * @param printerState 16 | */ 17 | Command(PrinterState printerState) { 18 | super(printerState); 19 | } 20 | 21 | /** 22 | * Execute command if possible 23 | * 24 | * @param data 25 | * command to execute 26 | * 27 | * @return true if handled 28 | */ 29 | abstract public boolean execute(int data); 30 | } 31 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/ControlCodes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | /** 8 | * Simple set of control codes constants 9 | */ 10 | public final class ControlCodes { 11 | // control codes 12 | static public final int ESC = 27; 13 | static public final int DEL = 127; 14 | 15 | static public final int NUL = 0; 16 | static public final int SOH = 1; 17 | static public final int STX = 2; 18 | static public final int ETX = 3; // END OF TEXT 19 | static public final int EOT = 4; 20 | static public final int ENQ = 5; 21 | static public final int ACK = 6; 22 | static public final int BEL = 7; 23 | static public final int BS = 8; 24 | static public final int HT = 9; 25 | static public final int LF = 10; 26 | static public final int VT = 11; 27 | static public final int FF = 12; 28 | static public final int CR = 13; 29 | static public final int SO = 14; 30 | static public final int SI = 15; 31 | static public final int DC1 = 17; 32 | static public final int DC2 = 18; 33 | static public final int DC3 = 19; 34 | static public final int DC4 = 20; 35 | static public final int CAN = 24; 36 | static public final int EM = 25; 37 | } 38 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/FontDescriptorPCLBitmappedFonts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2005-09-22 by piotrm 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | public class FontDescriptorPCLBitmappedFonts { 11 | public class FontType { 12 | public final static int LaserJetFamily = 4; 13 | public final static int IntellifontScalable = 10; 14 | public final static int TrueTypeScalable = 15; 15 | } 16 | 17 | public class FontClass { 18 | public final static int Bitmap = 1; 19 | public final static int CompressedBitmap = 2; 20 | public final static int Contour = 3; 21 | public final static int CompoundContour = 4; 22 | public final static int TrueTypeScalable = 5; 23 | } 24 | 25 | // private int _format; 26 | // private boolean _continuation; 27 | private int _descriptorSize; 28 | private int _class; 29 | private int _orientation; 30 | private int _reserved; 31 | private int _leftOffset; 32 | private int _topOffset; 33 | private int _characterWidth; 34 | private int _characterHeight; 35 | private int _deltaX; 36 | private byte[] _rasterCharacterData; 37 | 38 | public FontDescriptorPCLBitmappedFonts(int numOfBytes, InputStream in) 39 | throws IOException { 40 | // _format = 4; // LaserJet Family 41 | _descriptorSize = in.read(); // The descriptor size used by the HP LaserJet 42 | // printer family for bitmap fonts is 14. 43 | _class = in.read(); 44 | _orientation = in.read(); 45 | _reserved = in.read(); 46 | _leftOffset = 256 * in.read() + in.read(); 47 | _topOffset = 256 * in.read() + in.read(); 48 | _characterWidth = 256 * in.read() + in.read(); 49 | _characterHeight = 256 * in.read() + in.read(); 50 | _deltaX = 256 * in.read() + in.read(); 51 | _rasterCharacterData = new byte[numOfBytes - 16]; 52 | in.read(_rasterCharacterData); 53 | } 54 | 55 | public void continueFont(int numOfBytes, InputStream in) throws IOException { 56 | int newLen = _rasterCharacterData.length + numOfBytes - 2; 57 | byte[] characterData = new byte[numOfBytes - 2]; 58 | in.read(characterData); 59 | } 60 | 61 | public int getCharacterHeight() { 62 | return _characterHeight; 63 | } 64 | 65 | public int getCharacterWidth() { 66 | return _characterWidth; 67 | } 68 | 69 | public int getLeftOffset() { 70 | return _leftOffset; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/FontHeaderIntellifontBound.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PCL5Interpreter; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | public class FontHeaderIntellifontBound extends FontHeaderCommon { 7 | private final static int DESCRIPTOR_SIZE = 80; 8 | 9 | private int _firstCode; 10 | private int _lastCode; 11 | private int _pitchExtended; 12 | private int _heightExtended; 13 | private int _capHeight; 14 | private int _scaleFactor; 15 | private int _xResolution; 16 | private int _yResolution; 17 | private int _masterUnderlinePosition; 18 | private int _masterUnderlineThickness; 19 | private int _orThreshold; 20 | private int _globalItalicAngle; 21 | private int _globalIntellifontDataSize; 22 | private byte[] _globalIntellifontData; 23 | private int _reserved2; 24 | private int _checksum; 25 | 26 | public FontHeaderIntellifontBound(int numOfBytes, InputStream in) 27 | throws IOException { 28 | super(numOfBytes, in); 29 | 30 | _descriptorSize = numOfBytes; 31 | _headerFormat = 10; 32 | 33 | _firstCode = 256 * in.read() + in.read(); 34 | _lastCode = 256 * in.read() + in.read(); 35 | _pitchExtended = in.read(); 36 | _heightExtended = in.read(); 37 | _capHeight = 256 * in.read() + in.read(); 38 | _nativeFont = in.read() == 0; 39 | _fontNumber = readFontNumber(in); 40 | _fontName = readFontName(in); 41 | _scaleFactor = 256 * in.read() + in.read(); 42 | _xResolution = 256 * in.read() + in.read(); 43 | _yResolution = 256 * in.read() + in.read(); 44 | _masterUnderlinePosition = 256 * in.read() + in.read(); 45 | _masterUnderlineThickness = 256 * in.read() + in.read(); 46 | _orThreshold = 256 * in.read() + in.read(); 47 | _globalItalicAngle = 256 * in.read() + in.read(); 48 | _globalIntellifontDataSize = 256 * in.read() + in.read(); 49 | _globalIntellifontData = new byte[_globalIntellifontDataSize]; 50 | in.read(_globalIntellifontData); 51 | _copyright = readCopyright(in, numOfBytes - DESCRIPTOR_SIZE); // (optional) 52 | _reserved2 = in.read(); 53 | _checksum = in.read(); 54 | } 55 | 56 | public static int getDESCRIPTOR_SIZE() { 57 | return DESCRIPTOR_SIZE; 58 | } 59 | 60 | public int getCapHeight() { 61 | return _capHeight; 62 | } 63 | 64 | public int getChecksum() { 65 | return _checksum; 66 | } 67 | 68 | public int getFirstCode() { 69 | return _firstCode; 70 | } 71 | 72 | public byte[] getGlobalIntellifontData() { 73 | return _globalIntellifontData; 74 | } 75 | 76 | public int getGlobalIntellifontDataSize() { 77 | return _globalIntellifontDataSize; 78 | } 79 | 80 | public int getGlobalItalicAngle() { 81 | return _globalItalicAngle; 82 | } 83 | 84 | public int getHeightExtended() { 85 | return _heightExtended; 86 | } 87 | 88 | public int getLastCode() { 89 | return _lastCode; 90 | } 91 | 92 | public int getMasterUnderlinePosition() { 93 | return _masterUnderlinePosition; 94 | } 95 | 96 | public int getMasterUnderlineThickness() { 97 | return _masterUnderlineThickness; 98 | } 99 | 100 | public int getOrThreshold() { 101 | return _orThreshold; 102 | } 103 | 104 | public int getPitchExtended() { 105 | return _pitchExtended; 106 | } 107 | 108 | public int getScaleFactor() { 109 | return _scaleFactor; 110 | } 111 | 112 | public int getXResolution() { 113 | return _xResolution; 114 | } 115 | 116 | public int getYResolution() { 117 | return _yResolution; 118 | } 119 | 120 | public boolean isScalable() { 121 | return true; 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/FontHeaderIntellifontUnbound.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PCL5Interpreter; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | public class FontHeaderIntellifontUnbound extends FontHeaderCommon { 7 | private final static int DESCRIPTOR_SIZE = 88; 8 | 9 | private int _reserved2; 10 | private int _numberOfCharacters; 11 | private int _pitchExtended; 12 | private int _heightExtended; 13 | private int _capHeight; 14 | private int _scaleFactor; 15 | private int _xResolution; 16 | private int _yResolution; 17 | private int _masterUnderlinePosition; 18 | private int _masterUnderlineThickness; 19 | private int _orThreshold; 20 | private int _globalItalicAngle; 21 | private byte[] _characterComplement; 22 | private int _globalIntellifontDataSize; 23 | private byte[] _globalIntellifontData; 24 | private int _reserved3; 25 | private int _checksum; 26 | 27 | public FontHeaderIntellifontUnbound(int numOfBytes, InputStream in) 28 | throws IOException { 29 | super(numOfBytes, in); 30 | 31 | _descriptorSize = numOfBytes; 32 | _headerFormat = 11; 33 | 34 | _reserved2 = 256 * in.read() + in.read(); 35 | _numberOfCharacters = 256 * in.read() + in.read(); 36 | _pitchExtended = in.read(); 37 | _heightExtended = in.read(); 38 | _capHeight = 256 * in.read() + in.read(); 39 | _nativeFont = in.read() == 0; 40 | _fontNumber = readFontNumber(in); 41 | _fontName = readFontName(in); 42 | _scaleFactor = 256 * in.read() + in.read(); 43 | _xResolution = 256 * in.read() + in.read(); 44 | _yResolution = 256 * in.read() + in.read(); 45 | _masterUnderlinePosition = 256 * in.read() + in.read(); 46 | _masterUnderlineThickness = 256 * in.read() + in.read(); 47 | _orThreshold = 256 * in.read() + in.read(); 48 | _globalItalicAngle = 256 * in.read() + in.read(); 49 | _characterComplement = new byte[8]; 50 | in.read(_characterComplement); 51 | _globalIntellifontDataSize = 256 * in.read() + in.read(); 52 | _globalIntellifontData = new byte[_globalIntellifontDataSize]; 53 | in.read(_globalIntellifontData); 54 | _copyright = readCopyright(in, numOfBytes - DESCRIPTOR_SIZE); // (optional) 55 | _reserved3 = in.read(); 56 | _checksum = in.read(); 57 | } 58 | 59 | public static int getDESCRIPTOR_SIZE() { 60 | return DESCRIPTOR_SIZE; 61 | } 62 | 63 | public int getCapHeight() { 64 | return _capHeight; 65 | } 66 | 67 | public byte[] getCharacterComplement() { 68 | return _characterComplement; 69 | } 70 | 71 | public int getChecksum() { 72 | return _checksum; 73 | } 74 | 75 | public byte[] getGlobalIntellifontData() { 76 | return _globalIntellifontData; 77 | } 78 | 79 | public int getGlobalIntellifontDataSize() { 80 | return _globalIntellifontDataSize; 81 | } 82 | 83 | public int getGlobalItalicAngle() { 84 | return _globalItalicAngle; 85 | } 86 | 87 | public int getHeightExtended() { 88 | return _heightExtended; 89 | } 90 | 91 | public int getMasterUnderlinePosition() { 92 | return _masterUnderlinePosition; 93 | } 94 | 95 | public int getMasterUnderlineThickness() { 96 | return _masterUnderlineThickness; 97 | } 98 | 99 | public int getNumberOfCharacters() { 100 | return _numberOfCharacters; 101 | } 102 | 103 | public int getOrThreshold() { 104 | return _orThreshold; 105 | } 106 | 107 | public int getPitchExtended() { 108 | return _pitchExtended; 109 | } 110 | 111 | public int getScaleFactor() { 112 | return _scaleFactor; 113 | } 114 | 115 | public int getXResolution() { 116 | return _xResolution; 117 | } 118 | 119 | public int getYResolution() { 120 | return _yResolution; 121 | } 122 | 123 | public boolean isScalable() { 124 | return true; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/FontHeaderPCLBitmappedFonts.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PCL5Interpreter; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | public class FontHeaderPCLBitmappedFonts extends FontHeaderCommon { 7 | private final static int DESCRIPTOR_SIZE = 64; 8 | 9 | private int _firstCode; 10 | private int _lastCode; 11 | private int _pitchExtended; 12 | private int _heightExtended; 13 | private int _capHeight; 14 | 15 | public FontHeaderPCLBitmappedFonts(int numOfBytes, InputStream in) 16 | throws IOException { 17 | super(numOfBytes, in); 18 | 19 | _descriptorSize = numOfBytes; 20 | _headerFormat = 0; 21 | 22 | _firstCode = 256 * in.read() + in.read(); 23 | _lastCode = 256 * in.read() + in.read(); 24 | _pitchExtended = in.read(); 25 | _heightExtended = in.read(); 26 | _capHeight = 256 * in.read() + in.read(); 27 | byte fontInfo = (byte) in.read(); 28 | _nativeFont = (fontInfo & 0x80) == 0; 29 | if ((fontInfo & 0x7F) != 0) 30 | _vendorInitial = (char) (fontInfo & 0x7F); 31 | else 32 | _vendorInitial = ' '; 33 | 34 | _fontNumber = readFontNumber(in); 35 | _fontName = readFontName(in); 36 | _copyright = readCopyright(in, numOfBytes - DESCRIPTOR_SIZE); // (optional) 37 | } 38 | 39 | public int getCapHeight() { 40 | return _capHeight; 41 | } 42 | 43 | public int getFirstCode() { 44 | return _firstCode; 45 | } 46 | 47 | public int getLastCode() { 48 | return _lastCode; 49 | } 50 | 51 | public int getPitchExtended() { 52 | return _pitchExtended; 53 | } 54 | 55 | public int getHeightExtended() { 56 | return _heightExtended; 57 | } 58 | 59 | public boolean isScalable() { 60 | return false; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/FontHeaderResolutionSpecifiedBitmapped.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PCL5Interpreter; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | public class FontHeaderResolutionSpecifiedBitmapped extends FontHeaderCommon { 7 | private final static int DESCRIPTOR_SIZE = 68; 8 | 9 | private int _firstCode; 10 | private int _lastCode; 11 | private int _pitchExtended; 12 | private int _heightExtended; 13 | private int _capHeight; 14 | private int _xResolution; 15 | private int _yResolution; 16 | 17 | public FontHeaderResolutionSpecifiedBitmapped(int numOfBytes, InputStream in) 18 | throws IOException { 19 | super(numOfBytes, in); 20 | 21 | _descriptorSize = numOfBytes; 22 | _headerFormat = 20; 23 | 24 | _firstCode = 256 * in.read() + in.read(); 25 | _lastCode = 256 * in.read() + in.read(); 26 | _pitchExtended = in.read(); 27 | _heightExtended = in.read(); 28 | _capHeight = 256 * in.read() + in.read(); 29 | _nativeFont = in.read() == 0; 30 | _fontNumber = readFontNumber(in); 31 | _fontName = readFontName(in); 32 | _xResolution = 256 * in.read() + in.read(); 33 | _yResolution = 256 * in.read() + in.read(); 34 | _copyright = readCopyright(in, numOfBytes - DESCRIPTOR_SIZE); // (optional) 35 | } 36 | 37 | public static int getDESCRIPTOR_SIZE() { 38 | return DESCRIPTOR_SIZE; 39 | } 40 | 41 | public int getCapHeight() { 42 | return _capHeight; 43 | } 44 | 45 | public int getFirstCode() { 46 | return _firstCode; 47 | } 48 | 49 | public int getHeightExtended() { 50 | return _heightExtended; 51 | } 52 | 53 | public int getLastCode() { 54 | return _lastCode; 55 | } 56 | 57 | public int getPitchExtended() { 58 | return _pitchExtended; 59 | } 60 | 61 | public int getXResolution() { 62 | return _xResolution; 63 | } 64 | 65 | public int getYResolution() { 66 | return _yResolution; 67 | } 68 | 69 | public boolean isScalable() { 70 | return true; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/FontHeaderTrueType.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PCL5Interpreter; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | public class FontHeaderTrueType extends FontHeaderCommon { 7 | private final static int DESCRIPTOR_SIZE = 72; 8 | 9 | private int _firstCode; 10 | private int _lastCode; 11 | private int _pitchExtended; 12 | private int _heightExtended; 13 | private int _capHeight; 14 | private int _scaleFactor; 15 | private int _masterUnderlinePosition; 16 | private int _masterUnderlineThickness; 17 | private int _fontScalingTechnology; 18 | private int _variety; 19 | private byte[] _additionalData; 20 | private byte[] _segmentFontData; 21 | private int _reserved2; 22 | private int _checksum; 23 | 24 | public FontHeaderTrueType(int numOfBytes, InputStream in) throws IOException { 25 | super(numOfBytes, in); 26 | 27 | _descriptorSize = numOfBytes; 28 | _headerFormat = 15; 29 | 30 | _firstCode = 256 * in.read() + in.read(); 31 | _lastCode = 256 * in.read() + in.read(); 32 | _pitchExtended = in.read(); 33 | _heightExtended = in.read(); 34 | _capHeight = 256 * in.read() + in.read(); 35 | _nativeFont = in.read() == 0; 36 | _fontNumber = readFontNumber(in); 37 | _fontName = readFontName(in); 38 | _scaleFactor = 256 * in.read() + in.read(); 39 | _masterUnderlinePosition = 256 * in.read() + in.read(); 40 | _masterUnderlineThickness = 256 * in.read() + in.read(); 41 | _fontScalingTechnology = in.read(); 42 | _variety = in.read(); 43 | int additionalDataSize = numOfBytes - 72 - 2; 44 | if (additionalDataSize > 0) { 45 | _additionalData = new byte[additionalDataSize]; 46 | in.read(_additionalData); 47 | } 48 | _segmentFontData = new byte[1]; 49 | in.read(_segmentFontData); 50 | _reserved2 = in.read(); 51 | _checksum = in.read(); 52 | } 53 | 54 | public static int getDESCRIPTOR_SIZE() { 55 | return DESCRIPTOR_SIZE; 56 | } 57 | 58 | public byte[] getAdditionalData() { 59 | return _additionalData; 60 | } 61 | 62 | public int getCapHeight() { 63 | return _capHeight; 64 | } 65 | 66 | public int getChecksum() { 67 | return _checksum; 68 | } 69 | 70 | public int getFirstCode() { 71 | return _firstCode; 72 | } 73 | 74 | public int getFontScalingTechnology() { 75 | return _fontScalingTechnology; 76 | } 77 | 78 | public int getHeightExtended() { 79 | return _heightExtended; 80 | } 81 | 82 | public int getLastCode() { 83 | return _lastCode; 84 | } 85 | 86 | public int getMasterUnderlinePosition() { 87 | return _masterUnderlinePosition; 88 | } 89 | 90 | public int getMasterUnderlineThickness() { 91 | return _masterUnderlineThickness; 92 | } 93 | 94 | public int getPitchExtended() { 95 | return _pitchExtended; 96 | } 97 | 98 | public int getScaleFactor() { 99 | return _scaleFactor; 100 | } 101 | 102 | public byte[] getSegmentFontData() { 103 | return _segmentFontData; 104 | } 105 | 106 | public int getVariety() { 107 | return _variety; 108 | } 109 | 110 | public boolean isScalable() { 111 | return true; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/FontsetPCLBitmappedFonts.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Implementation of char set 3 | */ 4 | package org.getopt.pcl5.PCL5Interpreter; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class FontsetPCLBitmappedFonts { 9 | ArrayList _fonts; 10 | 11 | public FontsetPCLBitmappedFonts() { 12 | _fonts = new ArrayList(256); 13 | for (int i = 0; i < 256; i++) 14 | _fonts.add(null); 15 | } 16 | 17 | public void addFont(int code, FontDescriptorPCLBitmappedFonts font) { 18 | // _fonts.ensureCapacity(code); 19 | 20 | _fonts.set(code, font); 21 | } 22 | 23 | public FontDescriptorPCLBitmappedFonts getFont(int code) { 24 | return (FontDescriptorPCLBitmappedFonts) _fonts.get(code); 25 | } 26 | 27 | public int getCharacterWidth(int code) { 28 | FontDescriptorPCLBitmappedFonts font = getFont(code); 29 | 30 | if (font == null) 31 | return 0; // TODO: get value from font header 32 | 33 | return font.getCharacterWidth(); 34 | } 35 | 36 | public int getCharacterHeight(int code) { 37 | FontDescriptorPCLBitmappedFonts font = getFont(code); 38 | 39 | if (font == null) 40 | return 0; 41 | 42 | return font.getCharacterHeight(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/IInitialSetup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-12 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | /** 8 | * This is interface for printer interpreter setup. 9 | * 10 | * TODO Exception specification 11 | */ 12 | public interface IInitialSetup { 13 | void setBoundBoxColor(boolean boudBox); 14 | } 15 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/IParse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-12 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | import java.io.*; 8 | 9 | import org.getopt.pcl5.IPrint; 10 | 11 | /** 12 | * PCL parser interface 13 | */ 14 | public interface IParse { 15 | /** 16 | * Main parser 17 | * 18 | * @param in 19 | * input stream 20 | * @param print 21 | * callback interface to rasterizer 22 | */ 23 | void parse(InputStream in, IPrint print) throws IOException; 24 | } 25 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/IPrint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-12 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | import java.awt.image.BufferedImage; 8 | 9 | import org.getopt.pcl5.IPrinterState; 10 | 11 | /** 12 | * Callback interface, called when something to print happens Should be 13 | * implemented by rasterizer 14 | * 15 | * Every parameter is scaled in 72 DPI 16 | * 17 | */ 18 | public interface IPrint { 19 | /** 20 | * Called when new page 21 | * 22 | */ 23 | void newPage(); 24 | 25 | /** 26 | * Called when page size changed 27 | * 28 | * @param w 29 | * New width of page, in 72 DPI 30 | * @param h 31 | * New height of page, in 72 DPI 32 | */ 33 | void pageSize(float w, float h); 34 | 35 | /** 36 | * Called after every margins change and after each new page 37 | * 38 | * @param top 39 | * top margin, in 72 DPI 40 | * @param bottom 41 | * bottom margin, in 72 DPI 42 | * @param left 43 | * left margin, in 72 DPI 44 | * @param right 45 | * right margin, in 72 DPI 46 | */ 47 | void newMargins(float top, float bottom, float left, float right); 48 | 49 | /** 50 | * Called on beginning of processing, before any other method from this 51 | * interface is called 52 | * 53 | */ 54 | void processingStart(); 55 | 56 | /** 57 | * Called on end of processing, after last method from this interface was 58 | * called 59 | * 60 | */ 61 | void processingEnd(); 62 | 63 | /** 64 | * Called when text should be printed, text is limited to end of line (CR) or 65 | * to change in pronter state (ie font) 66 | * 67 | * @param x 68 | * Print location X in 72 DPI 69 | * @param y 70 | * Print location Y in 72 DPI 71 | * @param w 72 | * Width of text (bound box) in 72 DPI 73 | * @param h 74 | * Height of text in (bound box) 72 DPI 75 | * @param text 76 | * Text to print 77 | * @param state 78 | * Interface to query state of printer 79 | */ 80 | void printText(float x, float y, float w, float h, String text, 81 | IPrinterState state); 82 | 83 | /** 84 | * Called when bitmap should be printed, bitmap is always complete method is 85 | * called when graphics mode is terminated 86 | * 87 | * @param x 88 | * X location of image in 72 DPI 89 | * @param y 90 | * Y location of image in 72 DPI 91 | * @param w 92 | * Width of bitmap in (bound box) 72 DPI 93 | * @param h 94 | * Height of bitmap in (bound box) 72 DPI 95 | * @param image 96 | * Image for output 97 | * @param state 98 | * Interface to query state of printer 99 | */ 100 | void printBitmap(float x, float y, float w, float h, BufferedImage image, 101 | IPrinterState state); 102 | 103 | /** 104 | * Called on condition like command without meaning for interpreter like BEL 105 | * 106 | * @param command 107 | * class 108 | * @param message 109 | * command name 110 | */ 111 | void trace(Object command, String message); 112 | 113 | /** 114 | * Called when command parameters are incorrect ie out of range 115 | * 116 | * @param command 117 | * class that detected problem 118 | * @param message 119 | * kind of problem 120 | */ 121 | void assertCondition(Object command, String message); 122 | 123 | /** 124 | * Called when found command that shouldn't be implemented ie CAN Cancel line 125 | * 126 | * @param command 127 | * class that detected problem 128 | * @param message 129 | * kind of problem 130 | */ 131 | void notImplemented(Object command, String message); 132 | } 133 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/PatternGraphics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2005-10-03 by Piotrm 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | import java.awt.AlphaComposite; 8 | import java.awt.Color; 9 | import java.awt.Graphics2D; 10 | import java.awt.RenderingHints; 11 | import java.awt.geom.Rectangle2D; 12 | import java.awt.image.BufferedImage; 13 | 14 | public class PatternGraphics { 15 | final static int SOLID = 0; 16 | 17 | private int _width; 18 | private int _height; 19 | private BufferedImage _image; 20 | 21 | public PatternGraphics(int width, int height) { 22 | _image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); 23 | _width = width; 24 | _height = height; 25 | 26 | Graphics2D graphics; 27 | graphics = _image.createGraphics(); 28 | 29 | Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, _width, _height); 30 | graphics.setColor(Color.WHITE); 31 | graphics.fill(rect); 32 | } 33 | 34 | public void setPatternColor(Color color) { 35 | Graphics2D graphics; 36 | graphics = _image.createGraphics(); 37 | 38 | Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, _width, _height); 39 | graphics.setColor(color); 40 | graphics.fill(rect); 41 | } 42 | 43 | public void setPattern(UserDefinedPattern pattern) { 44 | Graphics2D graphics; 45 | graphics = _image.createGraphics(); 46 | 47 | for (int x = 0; x < _width; x += pattern.getWidth()) 48 | for (int y = 0; y < _height; y += pattern.getHeight()) 49 | graphics.drawImage(pattern.getImage(), x, y, null); 50 | } 51 | 52 | public BufferedImage getImage() { 53 | return _image; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/PrinterImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-23 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | import java.awt.AlphaComposite; 8 | import java.awt.Color; 9 | import java.awt.Graphics2D; 10 | import java.awt.RenderingHints; 11 | import java.awt.geom.Rectangle2D; 12 | import java.awt.image.BufferedImage; 13 | import java.awt.image.WritableRaster; 14 | 15 | /** 16 | * Support for printer-specific graphics 17 | */ 18 | public class PrinterImage extends BufferedImage { 19 | WritableRaster raster; 20 | Graphics2D graphics; 21 | int x; 22 | final int width; 23 | final int height; 24 | static final int[] SET_PIXEL = { 127, 127, 127, 0 }; 25 | static final int[] EMPTY_PIXEL = { 200, 200, 200, 255 }; 26 | Color _printColor = Color.BLACK; // new Color(0, 0, 0, 255); 27 | public static final Color EMPTY_COLOR = new Color(255, 255, 255, 0); 28 | 29 | /** 30 | * Creates BufferedImage 31 | * 32 | * @param w 33 | * width 34 | * @param h 35 | * height 36 | */ 37 | public PrinterImage(int w, int h) { 38 | super(w, h, BufferedImage.TYPE_INT_ARGB); 39 | // Raster r = getData(); 40 | // raster = r.createCompatibleWritableRaster(); 41 | 42 | height = h; 43 | width = w; 44 | 45 | graphics = createGraphics(); 46 | graphics.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, 47 | RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); 48 | 49 | // Clear image with transparent alpha by drawing a rectangle 50 | graphics.setComposite(AlphaComposite 51 | .getInstance(AlphaComposite.CLEAR, 0.0f)); 52 | Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, w, h); 53 | graphics.fill(rect); 54 | graphics.setComposite(AlphaComposite.SrcOver); 55 | graphics.setColor(_printColor); 56 | } 57 | 58 | /** 59 | * Set pixel at location 60 | * 61 | * @param bit 62 | * bit to test 63 | * @param offY 64 | * coordination offset 65 | * @param offset 66 | * bit offset 67 | */ 68 | private void px(int bit, int offY, int offset) { 69 | if (bit != 0) 70 | graphics.fillRect(x, offset + offY, 1, 1); 71 | } 72 | 73 | /** 74 | * Set pixel at location 75 | * 76 | * @param bit 77 | * bit to test 78 | * @param offY 79 | * coordination offset 80 | * @param offset 81 | * bit offset 82 | */ 83 | private void pxH(int bit, int offY, int offset) { 84 | if (bit != 0) 85 | graphics.fillRect(x + offset, offY, 1, 1); 86 | } 87 | 88 | /** 89 | * Interpret 8 bit data as print data 90 | * 91 | * @param data 92 | * data to interpret 93 | * @param offset 94 | * coordintion offset 95 | */ 96 | private void print8bit(byte data, int offset) { 97 | px(data & 0x01, 7, offset); 98 | px(data & 0x02, 6, offset); 99 | px(data & 0x04, 5, offset); 100 | px(data & 0x08, 4, offset); 101 | px(data & 0x10, 3, offset); 102 | px(data & 0x20, 2, offset); 103 | px(data & 0x40, 1, offset); 104 | px(data & 0x80, 0, offset); 105 | } 106 | 107 | private void print9bit(byte data) { 108 | if ((data & 0x01) == 0x01) 109 | graphics.fillRect(x, 8, 1, 1); 110 | } 111 | 112 | private void print(byte data, int repeat, int offset) { 113 | for (int i = 0; i < repeat; i++) { 114 | print8bit(data, offset); 115 | x++; 116 | } 117 | } 118 | 119 | /** 120 | * Print array of 8bit graphics data 121 | * 122 | * @param data 123 | * data to print 124 | */ 125 | public void print8bit(byte[] data) { 126 | for (int i = 0; i < data.length; i++) { 127 | print8bit(data[i], 0); 128 | x++; 129 | } 130 | } 131 | 132 | /** 133 | * Print array of 9bit graphics data 134 | * 135 | * @param data 136 | * data to print 137 | */ 138 | public void print9bit(byte[] data) { 139 | for (int i = 0; i < data.length; i += 2) { 140 | print8bit(data[i], 0); 141 | print9bit(data[i + 1]); 142 | x++; 143 | } 144 | } 145 | 146 | /** 147 | * Print array of 24bit graphics data (3 rows) 148 | * 149 | * @param data 150 | * data to print 151 | */ 152 | public void print24bit(byte[] data) { 153 | for (int i = 0; i < data.length; i += 3) { 154 | print8bit(data[i], 0); 155 | print8bit(data[i + 1], 8); 156 | print8bit(data[i + 2], 16); 157 | x++; 158 | } 159 | } 160 | 161 | /** 162 | * Print array of 48bit graphics data (6 rows) 163 | * 164 | * @param data 165 | * data to print 166 | */ 167 | public void print48bit(byte[] data) { 168 | for (int i = 0; i < data.length; i += 6) { 169 | print8bit(data[i], 0); 170 | print8bit(data[i + 1], 8); 171 | print8bit(data[i + 2], 16); 172 | print8bit(data[i + 3], 24); 173 | print8bit(data[i + 4], 32); 174 | print8bit(data[i + 5], 40); 175 | x++; 176 | } 177 | } 178 | 179 | int y; 180 | int rows; 181 | 182 | /** 183 | * Interpret 8 bit data as print data 184 | * 185 | * @param data 186 | * data to interpret 187 | * @param offset 188 | * coordintion offset 189 | */ 190 | private void print8bitH(byte data, int offset) { 191 | pxH(data & 0x01, offset, 7); 192 | pxH(data & 0x02, offset, 6); 193 | pxH(data & 0x04, offset, 5); 194 | pxH(data & 0x08, offset, 4); 195 | pxH(data & 0x10, offset, 3); 196 | pxH(data & 0x20, offset, 2); 197 | pxH(data & 0x40, offset, 1); 198 | pxH(data & 0x80, offset, 0); 199 | } 200 | 201 | boolean printRLE(byte data) { 202 | print8bitH(data, y); 203 | 204 | x += 8; 205 | 206 | if (x >= width) { 207 | x = 0; 208 | y++; 209 | } 210 | 211 | return y < rows; 212 | } 213 | 214 | public void startRLE(int rows) { 215 | y = 0; 216 | x = 0; 217 | this.rows = rows; 218 | } 219 | 220 | /** 221 | * Print array of RLE encoded graphics data 222 | * 223 | * @param data 224 | * data to print 225 | * @param rows 226 | * number of 8 bit rows to print 227 | */ 228 | public boolean printRLE(byte[] data) { 229 | int i; 230 | int n; 231 | 232 | if (data[0] > 0) { 233 | n = data[0] + 1; 234 | for (i = 0; i < n; i++) 235 | printRLE(data[i + 1]); 236 | } else { 237 | n = 1 - data[0]; // 257-data[pos] but data[pos] is < 0 238 | for (i = 0; i < n; i++) 239 | printRLE(data[1]); 240 | } 241 | 242 | return y < rows; 243 | } 244 | 245 | /** 246 | * Print array of TIFF encoded graphics data 247 | * 248 | * @param data 249 | * data to print 250 | */ 251 | public void printTIFF(byte[] data) { 252 | 253 | } 254 | 255 | /** 256 | * @return Returns the height. 257 | */ 258 | public int getHeight() { 259 | return height; 260 | } 261 | 262 | /** 263 | * @return Returns the width. 264 | */ 265 | public int getWidth() { 266 | return width; 267 | } 268 | 269 | /** 270 | * @return Returns the printColor. 271 | */ 272 | public Color getPrintColor() { 273 | return _printColor; 274 | } 275 | 276 | /** 277 | * @param printColor 278 | * The printColor to set. 279 | */ 280 | public void setPrintColor(Color printColor) { 281 | _printColor = printColor; 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/PrinterScore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-20 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | /** 8 | * Printer scores 9 | */ 10 | public class PrinterScore { 11 | static final int SC_UNDERLINE = 1; 12 | static final int SC_STRIKETHROUGH = 2; 13 | static final int SC_OVERSCORE = 3; 14 | 15 | static final int LN_NONE = 0; 16 | static final int LN_SINGLE_CONTINUOUS = 1; 17 | static final int LN_DOUBLE_CONTINUOUS = 2; 18 | static final int LN_SINGLE_BROKEN = 5; 19 | static final int LN_DOUBLE_BROKEN = 6; 20 | } 21 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/PrinterTIFF.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-10-09 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | public class PrinterTIFF { 8 | // TIFF code masks 9 | static final int XFER = 0x20; 10 | static final int MOVX = 0x40; 11 | static final int MOVY = 0x60; 12 | static final int COLR = 0x80; 13 | static final int CR = 0xE2; 14 | static final int EXIT = 0xE3; 15 | static final int MOVXBYTE = 0x24; // conflict with XFER 16 | static final int MOVXDOT = 0x25; // conflict with XFER 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/PrinterType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | /** 8 | * Printer types 9 | */ 10 | public class PrinterType { 11 | public static final int PIN_24 = 0; 12 | public static final int PIN_9 = 1; 13 | } 14 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/PrinterTypeface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-14 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | import java.util.*; 8 | 9 | /** 10 | * Printer typefaces 11 | */ 12 | public class PrinterTypeface { 13 | static final int TF_ROMAN = 0; 14 | static final int TF_SANS_SERIF = 1; 15 | static final int TF_COURIER = 2; 16 | static final int TF_PRESTIGE = 3; 17 | static final int TF_SCRIPT = 4; 18 | static final int TF_OCR_B = 5; 19 | static final int TF_OCR_A = 6; 20 | static final int TF_ORATOR = 7; 21 | static final int TF_ORATOR_S = 8; 22 | static final int TF_SCRIPT_C = 9; 23 | static final int TF_ROMAN_T = 10; 24 | static final int TF_SANS_SERIF_H = 11; 25 | static final int TF_SV_BUSABA = 30; 26 | static final int TF_SV_JITTRA = 31; 27 | 28 | static private Hashtable typefaceMap; 29 | 30 | static String getFontTypeface(int typeface) { 31 | if (typefaceMap == null) 32 | loadTypefaceMap(); 33 | 34 | String result = (String) typefaceMap.get(new Integer(typeface)); 35 | 36 | if (result == null) 37 | result = "Default"; 38 | 39 | return result; 40 | } 41 | 42 | // TODO: for next release, load params from config file 43 | static private void loadTypefaceMap() { 44 | typefaceMap = new Hashtable(); 45 | 46 | typefaceMap.put(new Integer(TF_ROMAN), "Serif"); 47 | typefaceMap.put(new Integer(TF_ROMAN_T), "Serif"); 48 | typefaceMap.put(new Integer(TF_SANS_SERIF), "SansSerif"); 49 | typefaceMap.put(new Integer(TF_SANS_SERIF_H), "SansSerif"); 50 | typefaceMap.put(new Integer(TF_COURIER), "Monospaced"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/RasterGraphics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2005-10-04 by Piotrm 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | import java.awt.AlphaComposite; 8 | import java.awt.Color; 9 | import java.awt.Graphics2D; 10 | import java.awt.Point; 11 | import java.awt.RenderingHints; 12 | import java.awt.geom.Rectangle2D; 13 | import java.awt.image.BufferedImage; 14 | 15 | import org.getopt.pcl5.PrinterState; 16 | 17 | public class RasterGraphics { 18 | private final static int BUFFER_INCREMENT = 128; 19 | private int _height; 20 | private int _width; 21 | private int _position; 22 | private BufferedImage _image; 23 | // private Graphics2D _graphics; 24 | private Point _start; 25 | private Point _end; 26 | 27 | public RasterGraphics(int width, int height) { 28 | _width = width; 29 | _height = height; 30 | 31 | createImage(); 32 | } 33 | 34 | protected void createImage() { 35 | _image = new BufferedImage(_width, _height, BufferedImage.TYPE_BYTE_GRAY); 36 | 37 | Graphics2D graphics = _image.createGraphics(); 38 | // _graphics.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, 39 | // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); 40 | 41 | // Clear image with transparent alpha by drawing a rectangle 42 | // _graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 43 | // 0.0f)); 44 | Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, _width, _height); 45 | graphics.setColor(Color.WHITE); 46 | graphics.fill(rect); 47 | // _graphics.setComposite(AlphaComposite.SrcOver); 48 | graphics.setColor(Color.BLACK); 49 | 50 | _start = new Point(_width, _height); 51 | _end = new Point(0, 0); 52 | } 53 | 54 | public int decodeImage(byte[] data, int compressionMethod, int x, int y, 55 | int w, int h) { 56 | byte[] decodedData; 57 | 58 | if (compressionMethod == PrinterState.CompressionMode.TIFF) 59 | decodedData = decompressTIFF(data); 60 | else 61 | decodedData = data; 62 | 63 | if (h == 0) 64 | h = 1; 65 | 66 | if (w == 0) 67 | w = decodedData.length * 8; 68 | 69 | // calculate 'real' side of image, for cropping 70 | if (x < _start.x) 71 | _start.x = x; 72 | 73 | if (y < _start.y) 74 | _start.y = y; 75 | 76 | if (x + w > _end.x) 77 | _end.x = x + w; 78 | 79 | if (y + h > _end.y) 80 | _end.y = y + h; 81 | 82 | fillPattern(decodedData, x, y, w, h); 83 | 84 | return h; 85 | } 86 | 87 | // -3 Literal Pattern Values 88 | // # of Bytes Binary value Decimal value 89 | // 1 0000 0000 1 90 | // to to to 91 | // 127 0111 1111 127 92 | // 93 | // No Operation Value 94 | // NOP value Binary value Decimal value 95 | // 128 (-128) 1000 000 128 96 | // 97 | // Repeated Pattern Values 98 | // # of Repetitions Binary value Decimal value 99 | // 1 (-1) 1111 1111 255 100 | // to to to 101 | // 127 (-127) 1000 0001 129 102 | private byte[] decompressTIFF(byte[] data) { 103 | int offset = 0; 104 | byte[] decodedData = new byte[BUFFER_INCREMENT]; 105 | _position = 0; 106 | 107 | while (offset < data.length) { 108 | offset = decompress(decodedData, offset, data); 109 | if (_position + 128 > decodedData.length) { 110 | byte[] newData = new byte[decodedData.length + BUFFER_INCREMENT]; 111 | System.arraycopy(decodedData, 0, newData, 0, _position); 112 | decodedData = newData; 113 | } 114 | } 115 | 116 | byte[] newData = new byte[_position]; 117 | System.arraycopy(decodedData, 0, newData, 0, _position); 118 | decodedData = newData; 119 | 120 | return decodedData; 121 | } 122 | 123 | private int decompress(byte[] dest, int offset, byte[] src) { 124 | int n = src[offset++]; 125 | 126 | if (n >= 0 && n < 128) { 127 | n++; 128 | copyData(dest, src, offset, n); 129 | offset += n; 130 | } else if (n < 0 && n != 128) { 131 | n = Math.abs(n); 132 | n++; 133 | repeatByte(dest, src[offset], n); 134 | offset++; 135 | } 136 | 137 | return offset; 138 | } 139 | 140 | private void repeatByte(byte[] dest, byte b, int n) { 141 | while (n > 0) { 142 | dest[_position] = b; 143 | n--; 144 | _position++; 145 | } 146 | } 147 | 148 | private void copyData(byte[] dest, byte[] src, int offset, int n) { 149 | while (n > 0) { 150 | dest[_position] = src[offset++]; 151 | n--; 152 | _position++; 153 | } 154 | } 155 | 156 | protected void fillPattern(byte[] src, int dx, int dy, int w, int h) { 157 | int bytesInRow = (w / 8) + 1; 158 | 159 | for (int y = 0; y < _height; y++) { 160 | for (int i = 0; i < bytesInRow; i++) { 161 | int offset = y * bytesInRow + i; 162 | if (offset < src.length) { 163 | byte b = src[offset]; 164 | 165 | if (b != 0x00) 166 | draw8bits(b, i * 8 + dx, y + dy); 167 | } 168 | } 169 | } 170 | } 171 | 172 | protected void draw8bits(byte bits, int x, int y) { 173 | // if (bits == -1) 174 | // _graphics.fillRect(x, y, 8, 1); 175 | // else 176 | { 177 | px(bits & 0x01, x + 7, y); 178 | px(bits & 0x02, x + 6, y); 179 | px(bits & 0x04, x + 5, y); 180 | px(bits & 0x08, x + 4, y); 181 | px(bits & 0x10, x + 3, y); 182 | px(bits & 0x20, x + 2, y); 183 | px(bits & 0x40, x + 1, y); 184 | px(bits & 0x80, x + 0, y); 185 | } 186 | } 187 | 188 | private void px(int bit, int x, int y) { 189 | if (bit != 0) 190 | _image.setRGB(x, y, 0xFF000000); 191 | // _graphics.fillRect(x, y, 1, 1 ); 192 | } 193 | 194 | /** 195 | * @return Returns the image. 196 | */ 197 | public BufferedImage getImage() { 198 | int w = _end.x - _start.x; 199 | int h = _end.y - _start.y; 200 | 201 | BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY); 202 | 203 | Graphics2D graphics = image.createGraphics(); 204 | 205 | graphics.drawImage(_image, -_start.x, -_start.y, null); 206 | 207 | return image; 208 | } 209 | 210 | public Point getStart() { 211 | return _start; 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/Resolution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter; 6 | 7 | public class Resolution { 8 | static final int RESOLUTION = 3600; 9 | static final int MAX_PAGE_HEIGHT_INCH = 22; 10 | static final int MAX_PAGE_HEIGHT_PIXEL = MAX_PAGE_HEIGHT_INCH * RESOLUTION; 11 | static final int A4_WIDTH = 2100; 12 | static final int A4_HEIGHT = 2970; 13 | static final int DECIMAL_MM_PER_INCH = 254; 14 | static final int DEFAULT_WIDTH = (RESOLUTION * A4_WIDTH) 15 | / DECIMAL_MM_PER_INCH; 16 | static final int DEFAULT_HEIGHT = (RESOLUTION * A4_HEIGHT) 17 | / DECIMAL_MM_PER_INCH; 18 | } 19 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/ScaleBW2Gray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2005-10-09 by Piotrm 3 | * 4 | * Scale B&W image (2 color) into gray image 5 | */ 6 | 7 | package org.getopt.pcl5.PCL5Interpreter; 8 | 9 | import java.awt.AlphaComposite; 10 | import java.awt.Color; 11 | import java.awt.Graphics2D; 12 | import java.awt.RenderingHints; 13 | import java.awt.geom.Rectangle2D; 14 | import java.awt.image.BufferedImage; 15 | 16 | public class ScaleBW2Gray { 17 | BufferedImage _destImage; 18 | int _boundBoxColor; 19 | 20 | // Graphics2D _graphics; 21 | 22 | public ScaleBW2Gray(BufferedImage srcImage, float width, float height, 23 | boolean boundBox) { 24 | _boundBoxColor = 0x00000000; 25 | 26 | if (boundBox) 27 | _boundBoxColor = 0x20080808; 28 | 29 | float probeWidth = srcImage.getWidth() / width; 30 | float probeHeight = srcImage.getHeight() / height; 31 | 32 | if (probeWidth == 0 || probeHeight == 0) 33 | throw new IllegalArgumentException( 34 | "Dest image must be smaller than original"); 35 | 36 | createDestImage((int) width, (int) height); 37 | 38 | // _graphics = _img.createGraphics(); 39 | 40 | float probeScale = 256 / (probeWidth * probeHeight); 41 | 42 | float probesX = srcImage.getWidth() / probeWidth + 1; 43 | float probesY = srcImage.getHeight() / probeHeight + 1; 44 | 45 | for (int x = 0; x < (int) width; x++) 46 | for (int y = 0; y < (int) height; y++) 47 | processProbe(srcImage, x, y, probeWidth, probeHeight, probeScale); 48 | } 49 | 50 | private void createDestImage(int width, int height) { 51 | _destImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 52 | 53 | Graphics2D graphics = _destImage.createGraphics(); 54 | graphics.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, 55 | RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); 56 | 57 | // Clear image with transparent alpha by drawing a rectangle 58 | graphics.setComposite(AlphaComposite 59 | .getInstance(AlphaComposite.CLEAR, 0.5f)); 60 | // graphics.setBackground(boundBox); 61 | Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, width, height); 62 | graphics.fill(rect); 63 | graphics.setComposite(AlphaComposite.SrcOver); 64 | graphics.setColor(Color.BLACK); 65 | } 66 | 67 | private void processProbe(BufferedImage srcImage, int x, int y, 68 | float probeWidth, float probeHeight, float probeScale) { 69 | int probeValue = 0; 70 | 71 | for (int dx = 0; dx < Math.round(probeWidth); dx++) 72 | for (int dy = 0; dy < Math.round(probeHeight); dy++) { 73 | int srcX = Math.round(x * probeWidth + dx); 74 | int srcY = Math.round(y * probeHeight + dy); 75 | 76 | if (srcX < srcImage.getWidth() && srcY < srcImage.getHeight()) { 77 | if (srcImage.getRGB(srcX, srcY) == 0xFF000000) // black 78 | probeValue++; 79 | } 80 | } 81 | 82 | int value = 0xFF & Math.round(255.0f - probeValue * probeScale); 83 | int color = 0xFF000000; 84 | 85 | if (probeValue == 0) // if empty 86 | color = _boundBoxColor; // set transparent color 87 | else { 88 | // color |= value; 89 | // color |= value << 8; 90 | color |= value << 16; 91 | } 92 | 93 | _destImage.setRGB(x, y, color); 94 | } 95 | 96 | public BufferedImage getImage() { 97 | return _destImage; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/UserDefinedPattern.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PCL5Interpreter; 2 | 3 | import java.awt.*; 4 | import java.awt.geom.Rectangle2D; 5 | import java.awt.image.BufferedImage; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | 9 | public class UserDefinedPattern { 10 | private int _format; 11 | private int _continuation; 12 | private int _pixelEncoding; 13 | private int _reserved; 14 | private int _height; 15 | private int _width; 16 | private int _masterXResolution; 17 | private int _masterYResoulution; 18 | 19 | private byte[] _data; 20 | 21 | private BufferedImage _image; 22 | 23 | public UserDefinedPattern(int numOfBytes, InputStream in) throws IOException { 24 | _format = in.read(); 25 | _continuation = in.read(); 26 | _pixelEncoding = in.read(); 27 | _reserved = in.read(); 28 | _height = 256 * in.read() + in.read(); 29 | _width = 256 * in.read() + in.read(); 30 | _masterXResolution = 256 * in.read() + in.read(); 31 | _masterYResoulution = 256 * in.read() + in.read(); 32 | 33 | _data = new byte[numOfBytes - 12]; 34 | in.read(_data); 35 | 36 | _image = null; 37 | } 38 | 39 | public BufferedImage getImage() { 40 | if (_image == null) 41 | createImage(); 42 | 43 | return _image; 44 | } 45 | 46 | protected void createImage() { 47 | _image = new BufferedImage(_width, _height, BufferedImage.TYPE_BYTE_GRAY); 48 | 49 | Graphics2D graphics; 50 | graphics = _image.createGraphics(); 51 | Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, _width, _height); 52 | graphics.setColor(Color.WHITE); 53 | graphics.fill(rect); 54 | 55 | fillPattern(); 56 | } 57 | 58 | protected void fillPattern() { 59 | int bytesInRow = (_width / 8); 60 | 61 | for (int y = 0; y < _height; y++) { 62 | for (int i = 0; i < bytesInRow; i++) { 63 | int offset = y * bytesInRow + i; 64 | 65 | if (_data[offset] != 0x00) 66 | draw8bits(_data[offset], i * 8, y); 67 | } 68 | } 69 | } 70 | 71 | protected void draw8bits(byte bits, int x, int y) { 72 | px(bits & 0x01, x + 7, y); 73 | px(bits & 0x02, x + 6, y); 74 | px(bits & 0x04, x + 5, y); 75 | px(bits & 0x08, x + 4, y); 76 | px(bits & 0x10, x + 3, y); 77 | px(bits & 0x20, x + 2, y); 78 | px(bits & 0x40, x + 1, y); 79 | px(bits & 0x80, x + 0, y); 80 | } 81 | 82 | private void px(int bit, int x, int y) { 83 | if (bit != 0 && x < _width && y < _height) 84 | _image.setRGB(x, y, 0xFF000000); 85 | } 86 | 87 | public int getHeight() { 88 | return _height; 89 | } 90 | 91 | public int getWidth() { 92 | return _width; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/BaseCommandPCL5.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter.cmd; 6 | 7 | import org.getopt.pcl5.PrinterState; 8 | 9 | /** 10 | * Base class for all command classes Contains instance of PrinterState 11 | */ 12 | public class BaseCommandPCL5 { 13 | PrinterState _printerState; 14 | 15 | public BaseCommandPCL5(PrinterState printerState) { 16 | this._printerState = printerState; 17 | } 18 | 19 | /** 20 | * Can return command code in derived class, if returned class will be put in 21 | * hashtable 22 | * 23 | * @return code for command, 0 means not set 24 | */ 25 | public char getCommandCode() { 26 | return 0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdCarriageReturn.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command CR 3 | * Moves the print position to the left margin position. 4 | * 5 | * implemented Sep 20, 2005 6 | * 7 | * @author Piotrm 8 | */ 9 | package org.getopt.pcl5.PCL5Interpreter.cmd; 10 | 11 | import org.getopt.pcl5.PrinterState; 12 | import org.getopt.pcl5.PCL5Interpreter.ControlCodes; 13 | 14 | public class CmdCarriageReturn extends CommandPCL5 { 15 | 16 | public CmdCarriageReturn(PrinterState printerState) { 17 | super(printerState); 18 | } 19 | 20 | public boolean execute(int data) { 21 | if (data == ControlCodes.CR) { 22 | _printerState.setColumn(_printerState.getLeftMargin()); 23 | 24 | return true; 25 | } 26 | 27 | return false; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdCharacterCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * c # E 3 | * The Character Code command establishes the decimal code that is 4 | * associated with the next character downloaded. This value is used to 5 | * reference the character for printing. 6 | * 7 | * Default = 0 8 | * Range = 0 - 65535 9 | * 10 | * # = character code 11 | * 12 | * Notes 13 | * For unbound fonts, the character code for a given character equals its symbol index value. 14 | * For TrueType fonts, a special code must be used to download glyphs 15 | * which never stand alone as characters. FFFF (hex) should be used for this purpose. 16 | * 17 | * implemented Sep 21, 2005 18 | * 19 | */ 20 | package org.getopt.pcl5.PCL5Interpreter.cmd; 21 | 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | 25 | import org.getopt.pcl5.PrinterState; 26 | 27 | public class CmdCharacterCode extends EscExtendedCommandPCL5 { 28 | public CmdCharacterCode(PrinterState printerState) { 29 | super(printerState); 30 | } 31 | 32 | public boolean execute(char family, char subfamily, String parameter, 33 | char cmd, InputStream in) throws IOException { 34 | if (family == '*' && subfamily == 'c' && cmd == 'E') { 35 | int param = Integer.parseInt(parameter); 36 | _printerState.setCharacterCode(param); 37 | 38 | return true; 39 | } 40 | 41 | return false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdCharacterDefinition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC ( s # W 3 | * The Character Descriptor and Data command is used to download 4 | * character data blocks to the printer for both bitmap and scalable fonts. 5 | * 6 | * Default = N/A 7 | * Range = 0 - 23767 8 | * 9 | * # = identifies the number of bytes in the immediately 10 | * following character data block. The maximum number is 32767. 11 | * 12 | * Notes 13 | * 14 | * Implementation 15 | * User defined fonts are not implemented 16 | * 17 | * implemented Sep 21, 2005 18 | * 19 | */ 20 | package org.getopt.pcl5.PCL5Interpreter.cmd; 21 | 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | 25 | import org.getopt.pcl5.PrinterState; 26 | import org.getopt.pcl5.PCL5Interpreter.FontDescriptorPCLBitmappedFonts; 27 | 28 | public class CmdCharacterDefinition extends EscExtendedCommandPCL5 { 29 | 30 | public CmdCharacterDefinition(PrinterState printerState) { 31 | super(printerState); 32 | } 33 | 34 | public boolean execute(char family, char subfamily, String parameter, 35 | char cmd, InputStream in) throws IOException { 36 | if (family == '(' && subfamily == 's' && cmd == 'W') { 37 | int param = Integer.parseInt(parameter); 38 | 39 | int format = in.read(); 40 | boolean continuation = in.read() != 0; 41 | 42 | FontDescriptorPCLBitmappedFonts font = null; 43 | 44 | if (continuation) { 45 | font = _printerState.getDefinedCharacter(); 46 | font.continueFont(param, in); 47 | } else { 48 | switch (format) { 49 | case FontDescriptorPCLBitmappedFonts.FontType.LaserJetFamily: 50 | font = new FontDescriptorPCLBitmappedFonts(param, in); 51 | break; 52 | } 53 | } 54 | 55 | _printerState.setDefinedCharacter(font); 56 | 57 | return true; 58 | } 59 | 60 | return false; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdEndRasterGraphics.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * r B 3 | * The End Raster Graphics command signifies the end of a raster graphic data transfer. 4 | * 5 | * 6 | * Notes 7 | * Receipt of this command causes 5 operations: 8 | * - Resets the raster compression seed row to zeros. 9 | * - Moves the cursor to the raster row immediately following the end of the raster area 10 | * (if a source raster height was specified). 11 | * - Allows raster commands which were previously locked out to be processed. 12 | 13 | * implemented Sep 21, 2005 14 | * 15 | */ 16 | package org.getopt.pcl5.PCL5Interpreter.cmd; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | 21 | import org.getopt.pcl5.PrinterState; 22 | 23 | public class CmdEndRasterGraphics extends EscExtendedCommandPCL5 { 24 | 25 | public CmdEndRasterGraphics(PrinterState printerState) { 26 | super(printerState); 27 | } 28 | 29 | public boolean execute(char family, char subfamily, String parameter, 30 | char cmd, InputStream in) throws IOException { 31 | if (family == '*' && subfamily == 'r' && cmd == 'B') { 32 | _printerState.endGraphicsMode(); 33 | 34 | return true; 35 | } 36 | 37 | return false; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdEndRasterGraphicsEx.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * r C 3 | * The End Raster Graphics command signifies the end of a raster graphic data transfer. 4 | * 5 | * 6 | * Notes 7 | * Receipt of this command causes 5 operations: 8 | * ? Resets the raster compression seed row to zeros. 9 | * ? Moves the cursor to the raster row immediately following the end of the raster area 10 | * (if a source raster height was specified). 11 | * ? Allows raster commands which were previously locked out to be processed. 12 | * ? Sets compression mode to 0 (no compression) 13 | * ? Defaults the left graphics margin to X-position 0. 14 | 15 | * implemented Sep 21, 2005 16 | * 17 | */ 18 | package org.getopt.pcl5.PCL5Interpreter.cmd; 19 | 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | 23 | import org.getopt.pcl5.PrinterState; 24 | 25 | public class CmdEndRasterGraphicsEx extends EscExtendedCommandPCL5 { 26 | 27 | public CmdEndRasterGraphicsEx(PrinterState printerState) { 28 | super(printerState); 29 | } 30 | 31 | public boolean execute(char family, char subfamily, String parameter, 32 | char cmd, InputStream in) throws IOException { 33 | if (family == '*' && subfamily == 'r' && cmd == 'C') { 34 | _printerState.endGraphicsMode(); 35 | 36 | return true; 37 | } 38 | 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdEscUnknownPCL5.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter.cmd; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | import org.getopt.pcl5.PrinterState; 11 | 12 | /** 13 | * Unknown Esc command, traces out info about unrecognized command 14 | */ 15 | public class CmdEscUnknownPCL5 extends BaseCommandPCL5 { 16 | /** 17 | * @param printerState 18 | */ 19 | public CmdEscUnknownPCL5(PrinterState printerState) { 20 | super(printerState); 21 | } 22 | 23 | public boolean execute(char cmd, InputStream in) throws IOException { 24 | _printerState.trace(this.toString(), "Unknown Esc printer command [0x" 25 | + Integer.toHexString(cmd) + "]"); 26 | 27 | return true; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdExtendedEscUnknownPCL5.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter.cmd; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | import org.getopt.pcl5.PrinterState; 11 | 12 | /** 13 | * Unknown Extended Esc command, traces out info about unrecognized command 14 | */ 15 | public class CmdExtendedEscUnknownPCL5 extends BaseCommandPCL5 { 16 | /** 17 | * @param printerState 18 | */ 19 | public CmdExtendedEscUnknownPCL5(PrinterState printerState) { 20 | super(printerState); 21 | } 22 | 23 | public boolean execute(char family, char subfamily, String parameter, 24 | char cmd, InputStream in) throws IOException { 25 | _printerState.trace(this.toString(), 26 | "Unknown extended Esc printer command [" + family + subfamily 27 | + parameter + cmd + "]"); 28 | 29 | return true; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdFillRectangularArea.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * c # P 3 | * This command fills (prints) a rectangular area of the specified width 4 | * and height with the specified area fill. 5 | * 6 | * Default = 0 7 | * Range = 0 - 5 (values outside the range are ignored) 8 | * 9 | * # =0 - Black fill (rule) 10 | * 1 - Erase (white) fill 11 | * 2 - Shaded fill 12 | * 3 - Cross-hatch fill 13 | * 4 - User-defined pattern fill 14 | * 5 - Current pattern fill 15 | * 16 | * Notes 17 | * Black fill � fills the rectangular area with black fill. 18 | * White fill � erases any fill in the rectangular area 19 | * (it fills the rectangular area with white fill). 20 | * Shaded fill � fills the rectangular area with one of the eight shading patterns 21 | * as specified by the Pattern ID command. 22 | * Cross-Hatch fill � fills the rectangular area with one of the six cross-hatched 23 | * patterns as specified by the Pattern ID command. 24 | * User-defined fill � fills the rectangular area with custom pattern data 25 | * as specified by the Pattern ID command and downloaded 26 | * by the User-Defined Pattern command. 27 | * Current Pattern � fills the rectangular area with the current pattern. 28 | * 29 | * implemented Sep 21, 2005 30 | * 31 | */ 32 | package org.getopt.pcl5.PCL5Interpreter.cmd; 33 | 34 | import java.io.IOException; 35 | import java.io.InputStream; 36 | 37 | import org.getopt.pcl5.PrinterState; 38 | 39 | public class CmdFillRectangularArea extends EscExtendedCommandPCL5 { 40 | public CmdFillRectangularArea(PrinterState printerState) { 41 | super(printerState); 42 | } 43 | 44 | public boolean execute(char family, char subfamily, String parameter, 45 | char cmd, InputStream in) throws IOException { 46 | if (family == '*' && subfamily == 'c' && cmd == 'P') { 47 | int param = Integer.parseInt((parameter)); 48 | 49 | if (param < 0 || param > 5) 50 | _printerState.assertCondition(this, "Parameer should be in 0-5 range."); 51 | 52 | _printerState.fillRectangularArea(param); 53 | 54 | return true; 55 | } 56 | 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdFontHeader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC ) s # W 3 | * The Font Header command is used to download font header data to 4 | * the printer. 5 | * 6 | * Default = 0 7 | * Range = 0 - 32767 8 | * 9 | * # = identifies the number of bytes in the font header. 10 | * 11 | * Notes 12 | * There are different font formats 13 | * Format 0 Font Header for PCL Bitmapped Fonts 14 | * ? Format 20 Font Header for Resolution-Specified Bitmapped 15 | * Format 10 Font Header for Intellifont Bound Scalable Fonts 16 | * Format 11 Font Header for Intellifont Unbound Scalable 17 | * Format 15 TrueType Scalable Font Header 18 | * 19 | * implemented Sep 20, 2005 20 | * 21 | */ 22 | package org.getopt.pcl5.PCL5Interpreter.cmd; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import org.getopt.pcl5.PrinterState; 28 | import org.getopt.pcl5.PCL5Interpreter.FontHeaderCommon; 29 | import org.getopt.pcl5.PCL5Interpreter.FontHeaderIntellifontBound; 30 | import org.getopt.pcl5.PCL5Interpreter.FontHeaderIntellifontUnbound; 31 | import org.getopt.pcl5.PCL5Interpreter.FontHeaderPCLBitmappedFonts; 32 | import org.getopt.pcl5.PCL5Interpreter.FontHeaderResolutionSpecifiedBitmapped; 33 | import org.getopt.pcl5.PCL5Interpreter.FontHeaderTrueType; 34 | 35 | public class CmdFontHeader extends EscExtendedCommandPCL5 { 36 | 37 | public CmdFontHeader(PrinterState printerState) { 38 | super(printerState); 39 | } 40 | 41 | public boolean execute(char family, char subfamily, String parameter, 42 | char cmd, InputStream in) throws IOException { 43 | if (family == ')' && subfamily == 's' && cmd == 'W') { 44 | int descriptorSize = 256 * in.read() + in.read(); 45 | int headerFormat = in.read(); 46 | 47 | FontHeaderCommon fontHeader = null; 48 | 49 | switch (headerFormat) { 50 | case FontHeaderCommon.PCL_BITMAPPED: 51 | fontHeader = new FontHeaderPCLBitmappedFonts(descriptorSize, in); 52 | break; 53 | 54 | case FontHeaderCommon.INTELLIFONT_BOUND: 55 | fontHeader = new FontHeaderIntellifontBound(descriptorSize, in); 56 | break; 57 | 58 | case FontHeaderCommon.INTELLIFONT_UNBOUND: 59 | fontHeader = new FontHeaderIntellifontUnbound(descriptorSize, in); 60 | break; 61 | 62 | case FontHeaderCommon.RESOLUTION_SPECIFIED_BITMAPPED: 63 | fontHeader = new FontHeaderResolutionSpecifiedBitmapped(descriptorSize, 64 | in); 65 | break; 66 | 67 | case FontHeaderCommon.TRUE_TYPE: 68 | fontHeader = new FontHeaderTrueType(descriptorSize, in); 69 | break; 70 | 71 | default: 72 | _printerState.assertCondition(this, "Unknown font type"); 73 | } 74 | 75 | _printerState.setFontHeader(fontHeader); 76 | 77 | return true; 78 | } 79 | 80 | return false; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdFontID.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * c # D 3 | * The Font ID command is used to specify an ID number for use in 4 | * subsequent font management commands. The ID number of a font 5 | * can be used to select the font for printing 6 | * 7 | * Default = 0 8 | * Range = 0 - 32767 9 | * 10 | * # = ID number 11 | * 12 | * Notes 13 | * The font ID number is used during subsequent soft font downloads, selections or deletions. 14 | * The factory default font ID is 0 (if no Font ID command is sent, an ID of 0 is assigned). 15 | * 16 | * implemented Sep 18, 2005 17 | * 18 | */ 19 | package org.getopt.pcl5.PCL5Interpreter.cmd; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | import org.getopt.pcl5.PrinterState; 25 | 26 | public class CmdFontID extends EscExtendedCommandPCL5 { 27 | 28 | public CmdFontID(PrinterState printerState) { 29 | super(printerState); 30 | } 31 | 32 | public boolean execute(char family, char subfamily, String parameter, 33 | char cmd, InputStream in) throws IOException { 34 | if (family == '*' && subfamily == 'c' && cmd == 'D') { 35 | int param = Integer.parseInt((parameter)); 36 | _printerState.setFontID(param); 37 | 38 | return true; 39 | } 40 | 41 | return false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdFontSelectionbyID.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC ) # X 3 | * Soft fonts can be specified using their associated ID numbers. 4 | * (ID numbers are assigned to soft fonts using the Font ID command) 5 | * 6 | * Default = 0 7 | * Range = 0 - 32767 8 | * 9 | * # = font ID 10 | * 11 | * Notes 12 | * If the designated font is present, the font is selected as the primary/secondary 13 | * font and all primary/secondary font characteristics in the printer�s Font 14 | * Select Table are set to those of the selected font. 15 | * However, if the selected font is proportionally spaced, the pitch 16 | * characteristic is not changed. 17 | * If the designated font is not present, the current font is retained. 18 | * 19 | * implemented Sep 21, 2005 20 | * 21 | */ 22 | package org.getopt.pcl5.PCL5Interpreter.cmd; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import org.getopt.pcl5.PrinterState; 28 | import org.getopt.pcl5.PCL5Interpreter.FontHeaderCommon; 29 | 30 | public class CmdFontSelectionbyID extends EscExtendedCommandPCL5 { 31 | 32 | public CmdFontSelectionbyID(PrinterState printerState) { 33 | super(printerState); 34 | } 35 | 36 | public boolean execute(char family, char subfamily, String parameter, 37 | char cmd, InputStream in) throws IOException { 38 | if ((family == '(' || family == ')') && subfamily == 0 && cmd == 'X') { 39 | int param = Integer.parseInt((parameter)); 40 | _printerState.setFontID(param, family == '('); 41 | 42 | return true; 43 | } 44 | 45 | return false; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdFormFeed.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command CR 3 | * Moves the print position to the left margin position. 4 | * 5 | * implemented Sep 20, 2005 6 | * 7 | * @author Piotrm 8 | */ 9 | package org.getopt.pcl5.PCL5Interpreter.cmd; 10 | 11 | import org.getopt.pcl5.PrinterState; 12 | import org.getopt.pcl5.PCL5Interpreter.ControlCodes; 13 | 14 | public class CmdFormFeed extends CommandPCL5 { 15 | 16 | public CmdFormFeed(PrinterState printerState) { 17 | super(printerState); 18 | } 19 | 20 | public boolean execute(int data) { 21 | if (data == ControlCodes.FF) { 22 | _printerState.newPage(); 23 | 24 | return true; 25 | } 26 | 27 | return false; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdHeight.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command Esc ( s # V 3 | * The Height command specifies the height of the font in points. 4 | * This characteristic is ignored when selecting a fixed-spaced scalable font; 5 | * however, the value is saved and available when a bitmap font or 6 | * a proportionally-spaced scalable font is selected. 7 | * 8 | * # = Height in points 9 | * 10 | * Default = 12 11 | * Range = 0.25 - 999.75 12 | * 13 | * Notes 14 | * The value field (#) is valid to two decimal places. 15 | * 16 | * implemented Sep 27, 2005 17 | * 18 | * @author piotrm 19 | * 20 | */ 21 | package org.getopt.pcl5.PCL5Interpreter.cmd; 22 | 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | 26 | import org.getopt.pcl5.PrinterState; 27 | 28 | public class CmdHeight extends EscExtendedCommandPCL5 { 29 | 30 | public CmdHeight(PrinterState printerState) { 31 | super(printerState); 32 | } 33 | 34 | public boolean execute(char family, char subfamily, String parameter, 35 | char cmd, InputStream in) throws IOException { 36 | if ((family == '(' || family == ')') && subfamily == 's' && cmd == 'V') { 37 | int param = Integer.parseInt((parameter)); 38 | _printerState.setHeight(param, family == '('); 39 | 40 | return true; 41 | } 42 | 43 | return false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdHorizontalCursorPositioning.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * p # X 3 | * This Vertical Cursor Positioning command moves the cursor to a new 4 | * position along the vertical axis. 5 | * 6 | * Default = N/A 7 | * Range = 0 - logical page right bound 8 | * 9 | * # = Number of PCL Units 10 | * 11 | * Notes 12 | * A value field (#) with a plus sign (+) indicates the new position is to 13 | * the right of and relative to the current cursor position; a minus sign (�) 14 | * indicates the new position is to the left of and relative to the current 15 | * cursor position. No sign indicates an absolute distance which is 16 | * referenced from the left edge of the logical page. The left most 17 | * position is 0 and the right most position is the right bound of the 18 | * logical page. 19 | * If a request is made for a location outside the printer�s logical page, 20 | * the current active position (CAP) is moved to the appropriate logical 21 | * page limit. 22 | * 23 | * implemented Sep 21, 2005 24 | * 25 | */ 26 | package org.getopt.pcl5.PCL5Interpreter.cmd; 27 | 28 | import java.io.IOException; 29 | import java.io.InputStream; 30 | 31 | import org.getopt.pcl5.PrinterState; 32 | 33 | public class CmdHorizontalCursorPositioning extends EscExtendedCommandPCL5 { 34 | public CmdHorizontalCursorPositioning(PrinterState printerState) { 35 | super(printerState); 36 | } 37 | 38 | public boolean execute(char family, char subfamily, String parameter, 39 | char cmd, InputStream in) throws IOException { 40 | if (family == '*' && subfamily == 'p' && cmd == 'X') { 41 | int param = Integer.parseInt((parameter)); 42 | 43 | // if first char is + or - it's relative posiotioning 44 | if (Character.isDigit(parameter.charAt(0))) 45 | _printerState.setAbsoluteHorizontalCursorPosition(param); 46 | else 47 | _printerState.setRelativeHorizontalCursorPosition(param); 48 | 49 | return true; 50 | } 51 | 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdHorizontalRectangleSize.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * c # A 3 | * This Horizontal Rectangle Size command specifies the rectangle width in PCL Units. 4 | * 5 | * Default = 0 6 | * Range = 0 - 32767 7 | * 8 | * # = Number of PCL Units 9 | * 10 | * Notes 11 | * For example, if the unit of measure is set to 300 units-per-inch, to 12 | * specify a two-inch wide rectangle, send the command: Esc*c600A 13 | * The same command specifies a one-inch wide rectangle if the unit of 14 | * measure is set to 600 units-per-inch. 15 | * 16 | * implemented Sep 21, 2005 17 | * 18 | */ 19 | package org.getopt.pcl5.PCL5Interpreter.cmd; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | import org.getopt.pcl5.PrinterState; 25 | 26 | public class CmdHorizontalRectangleSize extends EscExtendedCommandPCL5 { 27 | public CmdHorizontalRectangleSize(PrinterState printerState) { 28 | super(printerState); 29 | } 30 | 31 | public boolean execute(char family, char subfamily, String parameter, 32 | char cmd, InputStream in) throws IOException { 33 | if (family == '*' && subfamily == 'c' && cmd == 'A') { 34 | int param = Integer.parseInt((parameter)); 35 | _printerState.setHorizontalRectangleSize(param); 36 | 37 | return true; 38 | } 39 | 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdLeftMargin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & a # L 3 | * The Left Margin command sets the left margin to the left edge of the 4 | * specified column. 5 | * 6 | * Default = Column 0 (Left bound of logical page) 7 | * Range = 0 - Right margin 8 | * 9 | * # = Column number 10 | * 11 | * Notes 12 | * The first column within a line is column 0, which is located at the left 13 | * edge of the logical page (the HMI setting defines the distance 14 | * between columns, which thereby defines the maximum number of 15 | * columns on the logical page). If the value field specifies a column 16 | * greater than the current right margin, the command is ignored. 17 | * Margins represent a physical position and once set do not change 18 | * with subsequent changes in HMI. 19 | * If the cursor is to the left of the new left margin, the cursor is moved to 20 | * the new left margin. 21 | * 22 | * implemented Sep 18, 2005 23 | * 24 | */ 25 | package org.getopt.pcl5.PCL5Interpreter.cmd; 26 | 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | 30 | import org.getopt.pcl5.PrinterState; 31 | 32 | public class CmdLeftMargin extends EscExtendedCommandPCL5 { 33 | public CmdLeftMargin(PrinterState printerState) { 34 | super(printerState); 35 | } 36 | 37 | public boolean execute(char family, char subfamily, String parameter, 38 | char cmd, InputStream in) throws IOException { 39 | if (family == '&' && subfamily == 'a' && cmd == 'L') { 40 | int param = Integer.parseInt((parameter)); 41 | _printerState.setLeftMargin(param); 42 | 43 | return true; 44 | } 45 | 46 | return false; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdLogicalPageOrientation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & l # O 3 | * Orientation defines the position of the logical page and the default 4 | * direction of print with respect to the physical page. 5 | * 6 | * Default = 3 7 | * Range = 0-3 (Other values ignored) 8 | * 9 | * # = 0 - Portrait 10 | * 1 - Landscape 11 | * 2 - Reverse Portrait 12 | * 3 - Reverse Landscape 13 | * 14 | * Notes 15 | * This command can be used only once per page. To print multiple 16 | * directions per page use the Print Direction command. 17 | * This command affects the HP-GL/2 environment 18 | * 19 | * implemented Sep 19, 2005 20 | * 21 | */ 22 | package org.getopt.pcl5.PCL5Interpreter.cmd; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import org.getopt.pcl5.IPrinterState; 28 | import org.getopt.pcl5.PrinterState; 29 | 30 | public class CmdLogicalPageOrientation extends EscExtendedCommandPCL5 { 31 | 32 | public CmdLogicalPageOrientation(PrinterState printerState) { 33 | super(printerState); 34 | } 35 | 36 | public boolean execute(char family, char subfamily, String parameter, 37 | char cmd, InputStream in) throws IOException { 38 | if (family == '&' && subfamily == 'l' && cmd == 'O') { 39 | int param = Integer.parseInt((parameter)); 40 | 41 | if (param < 0 || param > 3) 42 | _printerState.assertCondition(this, 43 | "Parameter should be in 0 - 3 range"); 44 | 45 | _printerState.setPageOrientation(param); 46 | return true; 47 | } 48 | 49 | return false; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdNumberOfCopies.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & l # X 3 | * The Number of Copies command designates the number of printed 4 | * copies of each page. 5 | * 6 | * Default = 1 (Configurable from control panel) 7 | * Range = 1-32767 8 | * 9 | * # = Number of copies (1 to 32767 maximum) 10 | * 11 | * Notes 12 | * This command can be received anywhere within a page and affects 13 | * the current page as well as subsequent pages. 14 | * The HP-GL/2 Replot (RP) command is inactive for PCL 5 printers; 15 | * use the Number of Copies command for multiple HP-GL/2 plots. 16 | * To be effective, the Number of Copies command must be issued from 17 | * PCL prior to closing the page on which the plot is defined. 18 | * 19 | * Implementation notes 20 | * This command is ignored by interpreter 21 | * 22 | * implemented Sep 18, 2005 23 | * 24 | */ 25 | package org.getopt.pcl5.PCL5Interpreter.cmd; 26 | 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | 30 | import org.getopt.pcl5.PrinterState; 31 | 32 | public class CmdNumberOfCopies extends EscExtendedCommandPCL5 { 33 | 34 | public CmdNumberOfCopies(PrinterState printerState) { 35 | super(printerState); 36 | } 37 | 38 | public boolean execute(char family, char subfamily, String parameter, 39 | char cmd, InputStream in) throws IOException { 40 | if (family == '&' && subfamily == 'l' && cmd == 'X') { 41 | return true; 42 | } 43 | 44 | return false; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdPageSize.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & l # A 3 | * The Page Size command designates the size of the paper which in 4 | * turn defines the size of the logical page. 5 | * 6 | * Default = 2 (Configurable from Control Panel) 7 | * Range = 1, 2, 3, 6, 26, 27, 80, 81, 90, 91, 100 (Other values ignored) 8 | * 9 | * PAPER: 10 | * # = 1 - Executive (7? x 10? in.) 11 | * 2 - Letter (8? x 11 in.) 12 | * 3 - Legal (8? x 14 in.) 13 | * 6 - Ledger (11 x 17 in.) 14 | * 26 - A4 (210mm x 297mm) 15 | * 27 - A3 (297mm x 420mm) 16 | * ENVELOPES: 17 | * # = 80 - Monarch (Letter - 3 7/8 x 7? in.) 18 | * 81 - Com-10 (Business - 4 1/8 x 9? in.) 19 | * 90 - International DL (110mm x 220mm) 20 | * 91 - International C5 (162mm x 229mm) 21 | * 100 - International B5 (176mm x 250mm) 22 | * 23 | * Notes 24 | * Upon receipt of this command any unprinted pages are printed, the 25 | * top margin, text length, and left and right margins are set to their user 26 | * defaults, and any automatic macro overlay is disabled. The cursor is moved to 27 | * the left edge of the logical page at the top margin on the following page. 28 | * Also, certain HP-GL/2 state variables are reset 29 | * 30 | * implemented Sep 19, 2005 31 | * 32 | */ 33 | 34 | package org.getopt.pcl5.PCL5Interpreter.cmd; 35 | 36 | import java.io.IOException; 37 | import java.io.InputStream; 38 | 39 | import org.getopt.pcl5.IPrinterState; 40 | import org.getopt.pcl5.PrinterState; 41 | 42 | public class CmdPageSize extends EscExtendedCommandPCL5 { 43 | 44 | public CmdPageSize(PrinterState printerState) { 45 | super(printerState); 46 | } 47 | 48 | public boolean execute(char family, char subfamily, String parameter, 49 | char cmd, InputStream in) throws IOException { 50 | if (family == '&' && subfamily == 'l' && cmd == 'A') { 51 | int param = Integer.parseInt((parameter)); 52 | 53 | if (param != 1 && param != 2 && param != 3 && param != 6 && param != 26 54 | && param != 27 && param != 80 && param != 81 && param != 90 55 | && param != 91 && param != 100) 56 | _printerState.assertCondition(this, "Parameter has incorrect value"); 57 | 58 | _printerState.finishPage(); 59 | _printerState.setPageSize(param); 60 | 61 | return true; 62 | } 63 | 64 | return false; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdPaperSource.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & l # H 3 | * Prints front side of a page or both sides (front and back - in either of two binding modes). 4 | * 5 | * Default = Printer Dependent (Configurable from Control Panel) 6 | * Range = Printer Dependent 7 | * 8 | * # = 0 - Print the current page (paper source remains unchanged). 9 | * 1 - Feed paper from the a printer-specific tray. 10 | * 2 - Feed paper from manual input. 11 | * 3 - Feed envelope from manual input. 12 | * 4 - Feed paper from lower tray. 13 | * 5 - Feed from optional paper source. 14 | * 6 - Feed envelope from optional envelope feeder (Must be used in conjunction with Page Size command, envelope selection.) 15 | * 16 | * Notes 17 | * Not all HP LaserJet printers support all possible paper sources. The 18 | * implementation of paper source locations varies slightly from printer 19 | * to printer. 20 | * The Paper Source command causes the current page to be printed 21 | * and the cursor to be moved to the left edge of the logical page at the 22 | * top margin position for the next page (see Figure 5-5). 23 | * 24 | * Implementation notes 25 | * This command is ignored by interpreter. 26 | * 27 | * implemented Sep 18, 2005 28 | * 29 | */ 30 | 31 | package org.getopt.pcl5.PCL5Interpreter.cmd; 32 | 33 | import java.io.IOException; 34 | import java.io.InputStream; 35 | 36 | import org.getopt.pcl5.IPrinterState; 37 | import org.getopt.pcl5.PrinterState; 38 | 39 | public class CmdPaperSource extends EscExtendedCommandPCL5 { 40 | 41 | public CmdPaperSource(PrinterState printerState) { 42 | super(printerState); 43 | } 44 | 45 | public boolean execute(char family, char subfamily, String parameter, 46 | char cmd, InputStream in) throws IOException { 47 | if (family == '&' && subfamily == 'l' && cmd == 'H') { 48 | _printerState.newPage(); 49 | 50 | return true; 51 | } 52 | 53 | return false; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdPatternID.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * c # G 3 | * The Pattern ID command identifies the specific shading, cross-hatch, 4 | * or user-defined pattern to be used when filling a rectangular area. 5 | * 6 | * # = 1 thru 2 = 1- 2% shade # = 1 - Pattern #1 7 | * 3 thru 10 = 3-10% shade 2 - Pattern #2 8 | * 11 thru 20 = 11-20% shade 3 - Pattern #3 9 | * 21 thru 35 = 21-35% shade 4 - Pattern #4 10 | * 36 thru 55 = 36-55% shade 5 - Pattern #5 11 | * 56 thru 80 = 56-80% shade 6 - Pattern #6 12 | * 81 thru 99 = 81-99% shade 13 | * 100 = 100% shade 14 | * 15 | * Default = 0 (no pattern) 16 | * Range = 0 - 32767 (values outside the range are ignored) 17 | * 18 | * Notes 19 | * The value field (#) identifies the level of shading, the cross-hatch 20 | * pattern, or the user-defined pattern. 21 | * There are eight HP defined shading patterns defined within the PCL 22 | * language. To specify one of the eight shading patterns, use any value 23 | * within the value field range for the desired shade. 24 | * For example, to select the 56-80% shade use a value of 56, or 80, or any value in between such as 73. 25 | * 26 | * implemented Sep 22, 2005 27 | * 28 | */ 29 | package org.getopt.pcl5.PCL5Interpreter.cmd; 30 | 31 | import java.io.IOException; 32 | import java.io.InputStream; 33 | 34 | import org.getopt.pcl5.PrinterState; 35 | 36 | public class CmdPatternID extends EscExtendedCommandPCL5 { 37 | 38 | public CmdPatternID(PrinterState printerState) { 39 | super(printerState); 40 | } 41 | 42 | public boolean execute(char family, char subfamily, String parameter, 43 | char cmd, InputStream in) throws IOException { 44 | if (family == '*' && subfamily == 'c' && cmd == 'G') { 45 | int param = Integer.parseInt((parameter)); 46 | int pattern = 0; 47 | 48 | if (param >= 1 && param <= 2) 49 | pattern = 1; 50 | else if (param >= 3 && param <= 10) 51 | pattern = 2; 52 | else if (param >= 11 && param <= 20) 53 | pattern = 3; 54 | else if (param >= 21 && param <= 35) 55 | pattern = 4; 56 | else if (param >= 36 && param <= 55) 57 | pattern = 5; 58 | else if (param >= 56 && param <= 80) 59 | pattern = 6; 60 | else if (param >= 81 && param <= 99) 61 | pattern = 7; 62 | else 63 | pattern = 8; 64 | 65 | _printerState.setPatternID(pattern); 66 | return true; 67 | } 68 | 69 | return false; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdPatternTransparencyMode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * v # O 3 | * The Character Descriptor and Data command is used to download 4 | * character data blocks to the printer for both bitmap and scalable fonts. 5 | * 6 | * Default = N/A 7 | * Range = 0, 1 (other values cause the command to be ignored) 8 | * 9 | * # =0 - Transparent 10 | * 1 - Opaque 11 | * 12 | * Notes 13 | * A transparency mode of �0� (transparent) means that the white 14 | * regions of the pattern image are not copied onto the destination. 15 | * A transparency mode of �1� (opaque) means that the white pixels 16 | * in the pattern are applied directly onto the destination. 17 | * When printing white rules, the pattern transparency is treated as if it 18 | * were �opaque�; white rules erase black rules regardless of the transparency mode. 19 | * 20 | * implemented Sep 21, 2005 21 | * 22 | */ 23 | package org.getopt.pcl5.PCL5Interpreter.cmd; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | 28 | import org.getopt.pcl5.PrinterState; 29 | import org.getopt.pcl5.PCL5Interpreter.FontDescriptorPCLBitmappedFonts; 30 | 31 | public class CmdPatternTransparencyMode extends EscExtendedCommandPCL5 { 32 | 33 | public CmdPatternTransparencyMode(PrinterState printerState) { 34 | super(printerState); 35 | } 36 | 37 | public boolean execute(char family, char subfamily, String parameter, 38 | char cmd, InputStream in) throws IOException { 39 | if (family == '*' && subfamily == 'v' && cmd == 'O') { 40 | int param = Integer.parseInt((parameter)); 41 | 42 | if (param != 0 && param != 1) 43 | _printerState.assertCondition(this, "Parameter should be 0 or 1."); 44 | 45 | _printerState.setPatternTransparencyMode(param); 46 | 47 | return true; 48 | } 49 | 50 | return false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdPictureFrameHorizontalSize.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * c # X 3 | * This PCL command specifies the horizontal dimension of the window 4 | * to be used for printing an HP-GL/2 plot. 5 | * 6 | * # =Horizontal size in decipoints (1/720th inch) 7 | * 8 | * Default = width of the current logical page 9 | * Range = 0 - 32767 (valid to 4 decimal places) 10 | * 11 | * Notes 12 | * Using this command defaults the location of P1 to the lower left 13 | * corner of the picture frame, and P2 to the upper right corner of the 14 | * picture frame. It also resets the soft-clip window to the PCL Picture 15 | * Frame boundaries, clears the polygon buffer, and updates the 16 | * HP-GL/2 pen position to the lower-left corner of the picture frame 17 | * (P1), as viewed from the current orientation. 18 | * 19 | * implemented Sep 22, 2005 20 | * 21 | */ 22 | package org.getopt.pcl5.PCL5Interpreter.cmd; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import org.getopt.pcl5.PrinterState; 28 | 29 | public class CmdPictureFrameHorizontalSize extends EscExtendedCommandPCL5 { 30 | 31 | public CmdPictureFrameHorizontalSize(PrinterState printerState) { 32 | super(printerState); 33 | } 34 | 35 | public boolean execute(char family, char subfamily, String parameter, 36 | char cmd, InputStream in) throws IOException { 37 | if (family == '*' && subfamily == 'c' && cmd == 'X') { 38 | int param = Integer.parseInt((parameter)); 39 | _printerState.setHorizontalPictureFrameSize(param); 40 | return true; 41 | } 42 | 43 | return false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdPictureFrameVerticalSize.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * c # Y 3 | * This PCL command specifies the vertical dimension of the window 4 | * to be used for printing an HP-GL/2 plot. 5 | * 6 | * # =Vertical size in decipoints (1/720th inch) 7 | * 8 | * Default = The distance between the default top and bottom margins (the default text length) 9 | * Range = 0 - 32767 (valid to 4 decimal places) 10 | * 11 | * Notes 12 | * 13 | * implemented Sep 22, 2005 14 | * 15 | */ 16 | package org.getopt.pcl5.PCL5Interpreter.cmd; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | 21 | import org.getopt.pcl5.PrinterState; 22 | 23 | public class CmdPictureFrameVerticalSize extends EscExtendedCommandPCL5 { 24 | 25 | public CmdPictureFrameVerticalSize(PrinterState printerState) { 26 | super(printerState); 27 | } 28 | 29 | public boolean execute(char family, char subfamily, String parameter, 30 | char cmd, InputStream in) throws IOException { 31 | if (family == '*' && subfamily == 'c' && cmd == 'Y') { 32 | int param = Integer.parseInt((parameter)); 33 | _printerState.setVerticalPictureFrameSize(param); 34 | return true; 35 | } 36 | 37 | return false; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdPitch.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command Esc ( s # H 3 | * Inter-character spacing can be specified as either proportional or fixed. 4 | * 5 | * # = Pitch in characters/inch 6 | * 7 | * Default = 10 8 | * Range = 0.00 9 | * 10 | * Notes 11 | * The range of valid pitch selections for a fixed-spaced scalable font is 12 | * 576 to .10 characters/inch. 13 | * 14 | * implemented Sep 27, 2005 15 | * 16 | * @author piotrm 17 | * 18 | */ 19 | package org.getopt.pcl5.PCL5Interpreter.cmd; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | import org.getopt.pcl5.PrinterState; 25 | 26 | public class CmdPitch extends EscExtendedCommandPCL5 { 27 | 28 | public CmdPitch(PrinterState printerState) { 29 | super(printerState); 30 | } 31 | 32 | public boolean execute(char family, char subfamily, String parameter, 33 | char cmd, InputStream in) throws IOException { 34 | if ((family == '(' || family == ')') && subfamily == 's' && cmd == 'H') { 35 | int param = Integer.parseInt((parameter)); 36 | _printerState.setPitch(param, family == '('); 37 | 38 | return true; 39 | } 40 | 41 | return false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdPrinterReset.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command Esc E 3 | * Restores the User Default Environment, deletes temporary fonts and macros, 4 | * and prints any remaining data. 5 | * 6 | * Notes 7 | * Receipt of the Printer Reset command restores the User Default Environment, 8 | * deletes temporary fonts, macros, user-defined symbol sets and patterns. 9 | * It also prints any partial pages of data which may have been received. 10 | * 11 | * implemented Sep 18, 2005 12 | * 13 | * @author piotrm 14 | * 15 | */ 16 | package org.getopt.pcl5.PCL5Interpreter.cmd; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | 21 | import org.getopt.pcl5.IPrinterState; 22 | import org.getopt.pcl5.PrinterState; 23 | 24 | public class CmdPrinterReset extends EscCommandPCL5 { 25 | /** 26 | * @param printerState 27 | */ 28 | public CmdPrinterReset(PrinterState printerState) { 29 | super(printerState); 30 | } 31 | 32 | public boolean execute(char cmd, InputStream in) throws IOException { 33 | if (cmd == 'E') { 34 | _printerState.reset(); 35 | 36 | return true; 37 | } 38 | 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdRasterGraphicsPresentationMode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * r # F 3 | * The Raster Graphics Presentation command specifies the orientation 4 | * of the raster image on the logical page. 5 | * 6 | * Default = 3 7 | * Range = 0, 3 8 | * 9 | * # =0 - Raster image prints in orientation of logical page 10 | * 3 - Raster image prints along the width of the physical page 11 | * 12 | * Notes 13 | * A value of 0 indicates that a raster row �will be printed in the positive 14 | * X-direction of the PCL coordinate system. (The print direction 15 | * translates the PCL coordinate system.) 16 | * A value of 3 indicates that the raster graphics will be printed along 17 | * the width of the physical page, regardless of logical page orientation. 18 | * In portrait orientation, a raster row is printed in the positive X-direction 19 | * of the PCL coordinate system and a subsequent raster row is printed 20 | * beginning at the next dot row position in the positive Y-direction. 21 | * In landscape orientation, a raster row is printed in the positive 22 | * Y-direction of the PCL coordinate system and a subsequent raster 23 | * row is printed beginning at the next dot row position in the negative 24 | * X-direction. 25 | * 26 | * implemented Sep 18, 2005 27 | * 28 | */ 29 | package org.getopt.pcl5.PCL5Interpreter.cmd; 30 | 31 | import java.io.IOException; 32 | import java.io.InputStream; 33 | 34 | import org.getopt.pcl5.IPrinterState; 35 | import org.getopt.pcl5.PrinterState; 36 | 37 | public class CmdRasterGraphicsPresentationMode extends EscExtendedCommandPCL5 { 38 | 39 | public CmdRasterGraphicsPresentationMode(PrinterState printerState) { 40 | super(printerState); 41 | } 42 | 43 | public boolean execute(char family, char subfamily, String parameter, 44 | char cmd, InputStream in) throws IOException { 45 | if (family == '*' && subfamily == 'r' && cmd == 'F') { 46 | int param = Integer.parseInt((parameter)); 47 | 48 | if (param != 0 && param != 3) 49 | _printerState.assertCondition(this, "Parameter should be 0 or 3"); 50 | 51 | _printerState.setRasterMode(param); 52 | return true; 53 | } 54 | 55 | return false; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdRasterGraphicsResolution.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * t # R 3 | * Raster graphics can be printed at various resolutions. This command 4 | * designates the resolution of subsequent raster data transfers in 5 | * dots-per inch. 6 | * 7 | * Default = 75 8 | * Range = 75, 100, 150, 200, 300, 600 9 | * 10 | * # = 75 - 75 dots-per-inch 11 | * 100 - 100 dots-per-inch 12 | * 150 - 150 dots-per-inch 13 | * 200 - 200 dots-per-inch 14 | * 300 - 300 dots-per-inch 15 | * 600 - 600 dots-per-inch 16 | * 17 | * Notes 18 | * When configured for 300 dpi resolution, the printer automatically 19 | * expands raster graphics transferred at resolutions less than 300 20 | * dots-per-inch to 300 dots-per-inch during printing. 21 | * 22 | * implemented Sep 18, 2005 23 | * 24 | */ 25 | package org.getopt.pcl5.PCL5Interpreter.cmd; 26 | 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | 30 | import org.getopt.pcl5.PrinterState; 31 | 32 | public class CmdRasterGraphicsResolution extends EscExtendedCommandPCL5 { 33 | 34 | public CmdRasterGraphicsResolution(PrinterState printerState) { 35 | super(printerState); 36 | } 37 | 38 | public boolean execute(char family, char subfamily, String parameter, 39 | char cmd, InputStream in) throws IOException { 40 | if (family == '*' && subfamily == 't' && cmd == 'R') { 41 | int param = Integer.parseInt((parameter)); 42 | 43 | if (param != 75 && param != 100 && param != 150 && param != 200 44 | && param != 300 && param != 600) 45 | _printerState.assertCondition(this, 46 | "Parameter should be 75, 100, 150, 200, 300, 600"); 47 | 48 | _printerState.setResolution(param); 49 | return true; 50 | } 51 | 52 | return false; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdRightMargin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & a # M 3 | * The Right Margin command sets the right margin to the right edge of 4 | * the specified column. 5 | * 6 | * Default = Logical Page right bound 7 | * Range = Current left margin - Logical page right bound 8 | * 9 | * # = Column number 10 | * 11 | * Notes 12 | * The maximum right column is located at the right edge of the logical 13 | * page (the HMI setting defines the distance between columns, which 14 | * thereby defines the maximum number of columns on the logical 15 | * page). If the value field specifies a column which is greater than the 16 | * right edge of the logical page, the right margin is set to the right edge 17 | * of the logical page. If the value field specifies a column less than the 18 | * left margin, the command is ignored. 19 | * Margins represent a physical position and once set do not change 20 | * with subsequent changes in HMI. 21 | * If the cursor position is to the right of the new right margin, the cursor 22 | * is moved to the new right margin. 23 | * 24 | * implemented Sep 18, 2005 25 | * 26 | */ 27 | package org.getopt.pcl5.PCL5Interpreter.cmd; 28 | 29 | import java.io.IOException; 30 | import java.io.InputStream; 31 | 32 | import org.getopt.pcl5.PrinterState; 33 | 34 | public class CmdRightMargin extends EscExtendedCommandPCL5 { 35 | public CmdRightMargin(PrinterState printerState) { 36 | super(printerState); 37 | } 38 | 39 | public boolean execute(char family, char subfamily, String parameter, 40 | char cmd, InputStream in) throws IOException { 41 | if (family == '&' && subfamily == 'a' && cmd == 'M') { 42 | int param = Integer.parseInt((parameter)); 43 | _printerState.setRightMargin(param); 44 | 45 | return true; 46 | } 47 | 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdSelectCurrentPattern.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * v # T 3 | * The Select Current Pattern command identifies the type of pattern to 4 | * be applied onto the destination. 5 | * 6 | * Default = 0 7 | * Range = 0 - 4 (other values cause the command to be ignored) 8 | * 9 | * # =0 - Solid black (default) 10 | * 1 - Solid white 11 | * 2 - Shading pattern 12 | * 3 - Cross-hatch pattern 13 | * 4 - User-defined pattern 14 | * 15 | * Notes 16 | * This command selects which type of pattern is applied. 17 | * 18 | * implemented Sep 21, 2005 19 | * 20 | */ 21 | package org.getopt.pcl5.PCL5Interpreter.cmd; 22 | 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | 26 | import org.getopt.pcl5.PrinterState; 27 | 28 | public class CmdSelectCurrentPattern extends EscExtendedCommandPCL5 { 29 | 30 | public CmdSelectCurrentPattern(PrinterState printerState) { 31 | super(printerState); 32 | } 33 | 34 | public boolean execute(char family, char subfamily, String parameter, 35 | char cmd, InputStream in) throws IOException { 36 | if (family == '*' && subfamily == 'v' && cmd == 'T') { 37 | int param = Integer.parseInt((parameter)); 38 | if (param < 0 || param > 4) 39 | _printerState.assertCondition(this, 40 | "Parameter should be in 0 - 4 range."); 41 | 42 | _printerState.setCurrentPattern(param); 43 | 44 | return true; 45 | } 46 | 47 | return false; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdSetCompressionMethod.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * b # M 3 | * The Set Compression Method command allows you to code raster 4 | * data in one of four compressed formats: Run-length encoding, 5 | * tagged imaged file format (TIFF) rev. 4.0, delta row compression, 6 | * and adaptive compression. The choice of compression methods 7 | * affects both the amount of code needed to generate a raster 8 | * graphic image and the efficiency with which the image is printed. 9 | * 10 | * Default = 0 11 | * Range = 0 - 5 (values outside the range are ignored) 12 | * 13 | * # =0- Unencoded 14 | * 1 - Run-length encoding 15 | * 2 - Tagged Imaged File Format (TIFF) rev. 4.0 16 | * 3 - Delta row compression 17 | * 4 - Reserved 18 | * 5 - Adaptive compression 19 | * 20 | * Notes 21 | * 22 | * implemented Sep 21, 2005 23 | * 24 | */ 25 | package org.getopt.pcl5.PCL5Interpreter.cmd; 26 | 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | 30 | import org.getopt.pcl5.PrinterState; 31 | 32 | public class CmdSetCompressionMethod extends EscExtendedCommandPCL5 { 33 | 34 | public CmdSetCompressionMethod(PrinterState printerState) { 35 | super(printerState); 36 | } 37 | 38 | public boolean execute(char family, char subfamily, String parameter, 39 | char cmd, InputStream in) throws IOException { 40 | if (family == '*' && subfamily == 'b' && cmd == 'M') { 41 | int param = Integer.parseInt((parameter)); 42 | 43 | if (param < 0 || param > 5) 44 | _printerState.assertCondition(this, 45 | "Parameter should be in range 0 - 5."); 46 | 47 | _printerState.setCompressionMethod(param); 48 | 49 | return true; 50 | } 51 | 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdSetCompressionMode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * b # M 3 | * The Set Compression Method command allows you to code raster 4 | * data in one of four compressed formats: Run-length encoding, 5 | * tagged imaged file format (TIFF) rev. 4.0, delta row compression, 6 | * and adaptive compression. The choice of compression methods 7 | * affects both the amount of code needed to generate a raster 8 | * graphic image and the efficiency with which the image is printed. 9 | * 10 | * 11 | * Default = 0 12 | * Range = 0 - 5 (values outside the range are ignored) 13 | * 14 | * # = 0- Unencoded 15 | * 1 - Run-length encoding 16 | * 2 - Tagged Imaged File Format (TIFF) rev. 4.0 17 | * 3 - Delta row compression 18 | * 4 - Reserved 19 | * 5 - Adaptive compression 20 | * 21 | * Notes 22 | * 23 | * implemented Sep 18, 2005 24 | * 25 | */ 26 | package org.getopt.pcl5.PCL5Interpreter.cmd; 27 | 28 | import java.io.IOException; 29 | import java.io.InputStream; 30 | 31 | import org.getopt.pcl5.PrinterState; 32 | 33 | public class CmdSetCompressionMode extends EscExtendedCommandPCL5 { 34 | 35 | public CmdSetCompressionMode(PrinterState printerState) { 36 | super(printerState); 37 | } 38 | 39 | public boolean execute(char family, char subfamily, String parameter, 40 | char cmd, InputStream in) throws IOException { 41 | if (family == '*' && subfamily == 'b' && cmd == 'M') { 42 | int param = Integer.parseInt((parameter)); 43 | 44 | if (param < 0 || param > 5) 45 | _printerState.assertCondition(this, "Parameter should be in 0-5 range"); 46 | 47 | _printerState.setCompressionMode(param); 48 | 49 | return true; 50 | } 51 | 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdSetPictureFrameAnchorPoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * c 0 T 3 | * The Unit of Measure command establishes the unit of measure for 4 | * PCL Unit cursor movements. 5 | * 6 | * Default = 0 7 | * Range = 0 8 | * 9 | * Notes 10 | * The position of the picture frame anchor point defines the location of 11 | * the upper left corner of the PCL Picture Frame. The �upper left� refers 12 | * to the corner for which X and Y coordinates are minimized when the 13 | * print direction is 0. 14 | * A parameter value of zero (ESC*c0T) specifies that the picture frame 15 | * anchor point should be set to the cursor position. Sending a cursor 16 | * move command prior to sending this command places the picture 17 | * frame anchor in the desired location. All parameter values other than 18 | * zero are ignored, but if you do not send a Set Picture Frame Anchor 19 | * command, the printer defaults the anchor point to the left edge of the 20 | * logical page and the default top margin. 21 | * 22 | * implemented Sep 22, 2005 23 | * 24 | */ 25 | package org.getopt.pcl5.PCL5Interpreter.cmd; 26 | 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | 30 | import org.getopt.pcl5.PrinterState; 31 | 32 | public class CmdSetPictureFrameAnchorPoint extends EscExtendedCommandPCL5 { 33 | 34 | public CmdSetPictureFrameAnchorPoint(PrinterState printerState) { 35 | super(printerState); 36 | } 37 | 38 | public boolean execute(char family, char subfamily, String parameter, 39 | char cmd, InputStream in) throws IOException { 40 | if (family == '*' && subfamily == 'c' && cmd == 'T') { 41 | int param = Integer.parseInt((parameter)); 42 | 43 | if (param != 0) 44 | _printerState.assertCondition(this, "Parameter should be 0"); 45 | 46 | _printerState.setPictureFrameAnchorPoint(param); 47 | return true; 48 | } 49 | 50 | return false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdSimplexDuplexPrintCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & l # S 3 | * Prints front side of a page or both sides (front and back - in either of two binding modes). 4 | * 5 | * Default = 0 6 | * Range = 0 - 2 (Other values ignored) 7 | * 8 | * # = 0 - Simplex 9 | * 1 - Duplex, Long-Edge Binding 10 | * 2 - Duplex, Short-Edge Binding 11 | * 12 | * Notes 13 | * This command designates either simplex or duplex printing mode for 14 | * duplex printers. Simplex mode prints an image on only one side of a 15 | * sheet (page). Duplex mode prints images on both sides of a sheet. 16 | * If this command is received by a printer which does not contain the 17 | * duplex feature, it is ignored. Printers which do not contain the duplex 18 | * feature print in simplex mode (front side of sheet) only. 19 | * 20 | * Implementation notes 21 | * This command is ignored by interpreter. 22 | * 23 | * implemented Sep 18, 2005 24 | * 25 | */ 26 | package org.getopt.pcl5.PCL5Interpreter.cmd; 27 | 28 | import java.io.IOException; 29 | import java.io.InputStream; 30 | 31 | import org.getopt.pcl5.IPrinterState; 32 | import org.getopt.pcl5.PrinterState; 33 | 34 | public class CmdSimplexDuplexPrintCommand extends EscExtendedCommandPCL5 { 35 | 36 | /** 37 | * @param printerState 38 | */ 39 | public CmdSimplexDuplexPrintCommand(PrinterState printerState) { 40 | super(printerState); 41 | } 42 | 43 | public boolean execute(char family, char subfamily, String parameter, 44 | char cmd, InputStream in) throws IOException { 45 | if (family == '&' && subfamily == 'l' && cmd == 'S') { 46 | int param = Integer.parseInt((parameter)); 47 | if (param < 0 || param > 2) 48 | _printerState.assertCondition(this, "Parameter should be 0-2 range"); 49 | 50 | return true; 51 | } 52 | 53 | return false; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdSpacing.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command Esc ( s # P 3 | * Inter-character spacing can be specified as either proportional or fixed. 4 | * 5 | * # = 0 - Fixed spacing 6 | * 1 - Proportional spacing 7 | * 8 | * Default = 4099, Body Text 9 | * Range = 0, 1 (values outside the range are ignored) 10 | * 11 | * Notes 12 | * When proportional spacing is specified and a proportionally-spaced 13 | * font is not available (in the requested symbol set), a fixed pitch font 14 | * with the current pitch specification is selected. If fixed spacing is 15 | * specified but is not available, a proportional-spaced font is selected 16 | * and the pitch characteristic is ignored. 17 | * 18 | * implemented Sep 27, 2005 19 | * 20 | * @author piotrm 21 | * 22 | */ 23 | package org.getopt.pcl5.PCL5Interpreter.cmd; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | 28 | import org.getopt.pcl5.PrinterState; 29 | 30 | public class CmdSpacing extends EscExtendedCommandPCL5 { 31 | 32 | public CmdSpacing(PrinterState printerState) { 33 | super(printerState); 34 | } 35 | 36 | public boolean execute(char family, char subfamily, String parameter, 37 | char cmd, InputStream in) throws IOException { 38 | if ((family == '(' || family == ')') && subfamily == 's' && cmd == 'P') { 39 | int param = Integer.parseInt((parameter)); 40 | 41 | if (param != 0 && param != 1) 42 | _printerState.assertCondition(this, "Paramater should be in range 0-1"); 43 | 44 | _printerState.setSpacing(param, family == '('); 45 | 46 | return true; 47 | } 48 | 49 | return false; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdStartRasterGraphics.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * r # A 3 | * The Start Raster Graphics command identifies the beginning of the 4 | * raster data and also specifies the left graphics margin. 5 | * 6 | * Default = 0 7 | * Range = 0, 1 (values outside the range default to 0) 8 | * 9 | * # =0- Start graphics at default left graphics margin X-position 0). 10 | * 1 - Start graphics at current cursor position (current X-position). 11 | * 12 | * Notes 13 | * A value of 0 specifies that the left graphics margin is at the default left 14 | * margin of the page (X-position 0). A value of 1 specifies that the left 15 | * graphics margin is at the current X-position. In presentation mode 3, 16 | * the location of the left graphics margin varies depending on the orientation. 17 | * Once a Start Raster Graphics command is received by the printer, 18 | * raster graphics resolution, raster graphics presentation mode, raster 19 | * height, raster width, and left raster graphics margin are fixed until an 20 | * end raster graphics command is received. 21 | * 22 | * Once in Raster Graphics Mode, PCL commands and text imply an End Raster Graphics 23 | * (ESC*rC) except for the following commands: 24 | * - Transfer Raster Data 25 | * - Set Raster Compression Method 26 | * - Raster Y Offset 27 | * 28 | * In addition, the following commands are ignored (i.e., locked out) 29 | * while in Raster Graphics Mode and do not imply an End Raster Graphics command: 30 | * -? Start Raster Graphics 31 | * - ?Set Raster Width 32 | * - Set Raster Height 33 | * - Set Raster Presentation Mode 34 | * - Set Raster Graphics Resolution 35 | * 36 | * implemented Sep 21, 2005 37 | * 38 | */ 39 | package org.getopt.pcl5.PCL5Interpreter.cmd; 40 | 41 | import java.io.IOException; 42 | import java.io.InputStream; 43 | 44 | import org.getopt.pcl5.PrinterState; 45 | 46 | public class CmdStartRasterGraphics extends EscExtendedCommandPCL5 { 47 | 48 | public CmdStartRasterGraphics(PrinterState printerState) { 49 | super(printerState); 50 | } 51 | 52 | public boolean execute(char family, char subfamily, String parameter, 53 | char cmd, InputStream in) throws IOException { 54 | if (family == '*' && subfamily == 'r' && cmd == 'A') { 55 | int param = Integer.parseInt((parameter)); 56 | 57 | if (param < 0 || param > 1) 58 | _printerState.assertCondition(this, "Parameer should be 0 or 1."); 59 | 60 | _printerState.startRasterGraphics(param); 61 | 62 | return true; 63 | } 64 | 65 | return false; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdStrokeWeight.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command Esc ( s # S 3 | * The Stroke Weight command designates the thickness of the strokes 4 | * that compose the characters of a font. 5 | * 6 | * # = stroke weight 7 | * 8 | * Default = 0 9 | * Range = - 7 to 7 (less than -7 maps to -7; greater than 7 maps to 7) 10 | * 11 | * Notes 12 | * For selecting style, an exact match is required. If there is no match, 13 | * this characteristic is ignored, but stored in the font select table, 14 | * available for the next selection. 15 | * 16 | * implemented Sep 27, 2005 17 | * 18 | * @author piotrm 19 | * 20 | */ 21 | package org.getopt.pcl5.PCL5Interpreter.cmd; 22 | 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | 26 | import org.getopt.pcl5.PrinterState; 27 | 28 | public class CmdStrokeWeight extends EscExtendedCommandPCL5 { 29 | 30 | public CmdStrokeWeight(PrinterState printerState) { 31 | super(printerState); 32 | } 33 | 34 | public boolean execute(char family, char subfamily, String parameter, 35 | char cmd, InputStream in) throws IOException { 36 | if ((family == '(' || family == ')') && subfamily == 's' && cmd == 'B') { 37 | int param = Integer.parseInt((parameter)); 38 | 39 | if (param < -7 || param > 7) 40 | _printerState.assertCondition(this, 41 | "Parameter should be in range -7 - +7"); 42 | 43 | _printerState.setStrokeWeight(param, family == '('); 44 | 45 | return true; 46 | } 47 | 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdStyle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command Esc ( s # S 3 | * The Style command identifies the posture of a character, its width, 4 | * and structure of the font symbols. 5 | * 6 | * # = 0 (upright, solid) 7 | * 1 italic 8 | * 4 condensed 9 | * 5 condensed italic 10 | * 8 compressed, or extra condensed 11 | * 24 expanded 12 | * 32 outline 13 | * 64 inline 14 | * 128 shadowed 15 | * 160 outline shadowed 16 | * 17 | * Default = 0 18 | * Range = 0 - 32767 (values greater than 32767 are set to 32767) 19 | * 20 | * Notes 21 | * For selecting style, an exact match is required. If there is no match, 22 | * this characteristic is ignored, but stored in the font select table, 23 | * available for the next selection. 24 | * 25 | * implemented Sep 27, 2005 26 | * 27 | * @author piotrm 28 | * 29 | */ 30 | package org.getopt.pcl5.PCL5Interpreter.cmd; 31 | 32 | import java.io.IOException; 33 | import java.io.InputStream; 34 | 35 | import org.getopt.pcl5.PrinterState; 36 | 37 | public class CmdStyle extends EscExtendedCommandPCL5 { 38 | 39 | public CmdStyle(PrinterState printerState) { 40 | super(printerState); 41 | } 42 | 43 | public boolean execute(char family, char subfamily, String parameter, 44 | char cmd, InputStream in) throws IOException { 45 | if ((family == '(' || family == ')') && subfamily == 's' && cmd == 'S') { 46 | int param = Integer.parseInt((parameter)); 47 | _printerState.setStyle(param, family == '('); 48 | 49 | return true; 50 | } 51 | 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdSymbolSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command Esc ( ID 3 | * The Symbol Set command identifies the specific set of symbols in a font. 4 | * 5 | * Notes 6 | * 7 | * implemented Sep 18, 2005 8 | * 9 | * @author piotrm 10 | * 11 | */ 12 | package org.getopt.pcl5.PCL5Interpreter.cmd; 13 | 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | 17 | import org.getopt.pcl5.PrinterState; 18 | 19 | public class CmdSymbolSet extends EscExtendedCommandPCL5 { 20 | 21 | public CmdSymbolSet(PrinterState printerState) { 22 | super(printerState); 23 | } 24 | 25 | public boolean execute(char family, char subfamily, String parameter, 26 | char cmd, InputStream in) throws IOException { 27 | if ((family == '(' || family == ')') && subfamily == 0 && cmd != 'X') { 28 | _printerState.setSymbolSet(parameter + cmd, family == '('); 29 | 30 | return true; 31 | } 32 | 33 | return false; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdTopMargin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & l # E 3 | * The Top Margin command designates the number of lines between 4 | * the top of the logical page and the top of the text area. 5 | * 6 | * Default = 1/2 inch down from top of logical page 7 | * If logical page length is Range = 0 - Length of logical page (Other values ignored) 10 | * 11 | * # = Number of lines 12 | * 13 | * Notes 14 | * The Top Margin command is ignored if the value field (#) is greater 15 | * than the current logical page length or if the current VMI is 0 (VMI 16 | * defines the distance between lines of text). 17 | * Receipt of a Top Margin command resets the text length according to 18 | * the following equation: 19 | * Text Length = (logical page len in inches) - (top margin in inches + 1/2 inch) 20 | * 21 | * The top margin represents a physical position and once set does not 22 | * change with subsequent changes in VMI or line spacing. 23 | * 24 | * The vertical cursor position for the first line of print is 25 | * determined by the current values of the top margin and VMI 26 | * using the following equation: 27 | * first line in inches = top margin in inches + (0.75 * VMI) 28 | * 29 | * Note The default cursor position is not located at the intersection of the 30 | * top margin and the left bound of the logical page. 31 | * The cursor is actually positioned down 75% of the VMI distance 32 | * (0.75 � VMI) from the top margin. This positions the cursor at the 33 | * relative base line position of a character cell for correct character 34 | * positioning. 35 | * 36 | * 37 | * implemented Sep 18, 2005 38 | * 39 | */ 40 | package org.getopt.pcl5.PCL5Interpreter.cmd; 41 | 42 | import java.io.IOException; 43 | import java.io.InputStream; 44 | 45 | import org.getopt.pcl5.PrinterState; 46 | 47 | public class CmdTopMargin extends EscExtendedCommandPCL5 { 48 | public CmdTopMargin(PrinterState printerState) { 49 | super(printerState); 50 | } 51 | 52 | public boolean execute(char family, char subfamily, String parameter, 53 | char cmd, InputStream in) throws IOException { 54 | if (family == '&' && subfamily == 'l' && cmd == 'E') { 55 | int param = Integer.parseInt((parameter)); 56 | _printerState.setTopMargin(param); 57 | 58 | return true; 59 | } 60 | 61 | return false; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdTransferRasterData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * b # W 3 | * The Transfer Raster Data command is used to transfer a row of raster data to the printer. 4 | * 5 | * Default = N/A 6 | * Range = 0 - 32767 7 | * 8 | * # = identifies the number of bytes in the raster row. 9 | * 10 | * Notes 11 | * 12 | * implemented Sep 21, 2005 13 | * 14 | */ 15 | package org.getopt.pcl5.PCL5Interpreter.cmd; 16 | 17 | import java.io.IOException; 18 | import java.io.InputStream; 19 | 20 | import org.getopt.pcl5.PrinterState; 21 | 22 | public class CmdTransferRasterData extends EscExtendedCommandPCL5 { 23 | 24 | public CmdTransferRasterData(PrinterState printerState) { 25 | super(printerState); 26 | } 27 | 28 | public boolean execute(char family, char subfamily, String parameter, 29 | char cmd, InputStream in) throws IOException { 30 | if (family == '*' && subfamily == 'b' && cmd == 'W') { 31 | int param = Integer.parseInt((parameter)); 32 | byte[] data = new byte[param]; 33 | in.read(data); 34 | 35 | _printerState.transferRasterData(data); 36 | 37 | return true; 38 | } 39 | 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdTypefaceFamily.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command Esc ( s # T 3 | * The Typeface Family command designates the design of the font. 4 | * 5 | * # = Typeface family value 6 | * 7 | * Default = 4099, Body Text 8 | * Range = 10 - 65535 (values greater than 65535 are set to 65535) 9 | * 10 | * Notes 11 | * 12 | * implemented Sep 27, 2005 13 | * 14 | * @author piotrm 15 | * 16 | */ 17 | package org.getopt.pcl5.PCL5Interpreter.cmd; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | import org.getopt.pcl5.PrinterState; 23 | 24 | public class CmdTypefaceFamily extends EscExtendedCommandPCL5 { 25 | 26 | public CmdTypefaceFamily(PrinterState printerState) { 27 | super(printerState); 28 | } 29 | 30 | public boolean execute(char family, char subfamily, String parameter, 31 | char cmd, InputStream in) throws IOException { 32 | if ((family == '(' || family == ')') && subfamily == 's' && cmd == 'T') { 33 | int param = Integer.parseInt((parameter)); 34 | _printerState.setTypefaceFamily(param, family == '('); 35 | 36 | return true; 37 | } 38 | 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdUnderline.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & d # D 3 | * Command ESC & d @ 4 | * The Underline command controls automatic text underlining. 5 | * 6 | * Default = 0 7 | * Range = 0, 3 (values outside range are ignored) 8 | * 9 | * # = 0 - Fixed position 10 | * 3 - Floating position 11 | * ESC & d @ - disable underline 12 | * 13 | * Notes 14 | * Once underlining is enabled, any positive horizontal movement causes an underline 15 | * to be drawn. Positive horizontal movement includes the printing of text and positive 16 | * horizontal cursor motion. 17 | * When fixed position underlining is enabled, the underline is drawn five dots below 18 | * the baseline and is three dots thick. (The baseline is the dot row on which 19 | * all of the characters in a given line appear to stand, see Chapter 11.) 20 | * When floating position underline is enabled, the underline position is determined by 21 | * the greatest underline distance below the baseline of all of the fonts printed on 22 | * the current line. 23 | * 24 | * implemented Sep 21, 2005 25 | * 26 | */ 27 | package org.getopt.pcl5.PCL5Interpreter.cmd; 28 | 29 | import java.io.IOException; 30 | import java.io.InputStream; 31 | 32 | import org.getopt.pcl5.PrinterState; 33 | 34 | public class CmdUnderline extends EscExtendedCommandPCL5 { 35 | 36 | public CmdUnderline(PrinterState printerState) { 37 | super(printerState); 38 | } 39 | 40 | public boolean execute(char family, char subfamily, String parameter, 41 | char cmd, InputStream in) throws IOException { 42 | if (family == '&' && subfamily == 'd' && cmd == 'D') { 43 | int param = Integer.parseInt((parameter)); 44 | _printerState.setUnderlineType(param); 45 | 46 | return true; 47 | } 48 | 49 | if (family == '&' && subfamily == 'd' && cmd == '@') { 50 | _printerState.setUnderlineType(-1); 51 | 52 | return true; 53 | } 54 | 55 | return false; 56 | } 57 | } -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdUnitOfMeasure.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & u # D 3 | * The Unit of Measure command establishes the unit of measure for 4 | * PCL Unit cursor movements. 5 | * 6 | * Default = 75 7 | * Range = 96, 100, 120, 144, 150, 160, 180, 200, 225, 240, 288, 300, 8 | * 360, 400, 450, 480, 600, 720, 800, 900, 1200, 1440, 1800, 9 | * 2400, 3600, 7200. 10 | * 11 | * # =Number of units-per-inch 12 | * 13 | * Notes 14 | * The value field defines the number of units-per-inch used in the following commands: 15 | * -? Vertical Cursor Position (PCL Units). 16 | * - Horizontal Cursor Position (PCL Units). 17 | * - Vertical Rectangle Size (PCL Units). 18 | * -? Horizontal Rectangle Size (PCL Units). 19 | * In addition, the current unit of measure setting affects the HMI setting, 20 | * which in turn determines how cursor movement values are rounded. 21 | * This affects the result of the following commands: 22 | * -? Horizontal Cursor Position (Columns). 23 | * -? Horizontal Tab (HT control code). 24 | * -? Space (SP control code). 25 | * -? Backspace (BS control code). 26 | * -? Bitmap Character Delta X. 27 | * For example, if the unit of measure is set to 96 (one PCL Unit = 1/96 inch), 28 | * then the HMI is rounded to the nearest 1/96 inch. If the unit of measure 29 | * is set to 300 (one PCL Unit = 1/300 inch), the HMI is rounded to the nearest 1/300 inch. 30 | * 31 | * implemented Sep 22, 2005 32 | * 33 | */ 34 | package org.getopt.pcl5.PCL5Interpreter.cmd; 35 | 36 | import java.io.IOException; 37 | import java.io.InputStream; 38 | 39 | import org.getopt.pcl5.PrinterState; 40 | 41 | public class CmdUnitOfMeasure extends EscExtendedCommandPCL5 { 42 | 43 | public CmdUnitOfMeasure(PrinterState printerState) { 44 | super(printerState); 45 | } 46 | 47 | public boolean execute(char family, char subfamily, String parameter, 48 | char cmd, InputStream in) throws IOException { 49 | if (family == '&' && subfamily == 'u' && cmd == 'D') { 50 | int param = Integer.parseInt((parameter)); 51 | _printerState.setUnitOfMeasure(param); 52 | return true; 53 | } 54 | 55 | return false; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdUniversalExitLanguage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC % � 1 2 3 4 5 X 3 | * Causes the printer to exit the current language and return control to PJL. 4 | * 5 | * Default = N/A 6 | * Range = �12345 7 | * 8 | * Notes 9 | * This command performs the following actions: 10 | * Prints all data received before the Exit Language command. 11 | * Performs a printer reset (same effect as ? E). 12 | * Shuts down the PCL 5 printer language processor. 13 | * Turns control over to PJL. 14 | * 15 | * implemented Sep 17, 2005 16 | * 17 | */ 18 | package org.getopt.pcl5.PCL5Interpreter.cmd; 19 | 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | 23 | import org.getopt.pcl5.IPrinterState; 24 | import org.getopt.pcl5.PrinterState; 25 | 26 | public class CmdUniversalExitLanguage extends EscExtendedCommandPCL5 { 27 | /** 28 | * @param printerState 29 | */ 30 | public CmdUniversalExitLanguage(PrinterState printerState) { 31 | super(printerState); 32 | } 33 | 34 | public boolean execute(char family, char subfamily, String parameter, 35 | char cmd, InputStream in) throws IOException { 36 | if (family == '%' && cmd == 'X') { 37 | int param = Integer.parseInt((parameter)); 38 | if (subfamily != '\0') 39 | _printerState.assertCondition(this, "Subfamily should be 0"); 40 | 41 | if (param != -12345) 42 | _printerState.assertCondition(this, "Parameter should be -12345"); 43 | 44 | _printerState.reset(); 45 | _printerState.setActiveLanguage(PrinterState.Language.PJL); 46 | 47 | return true; 48 | } 49 | 50 | return false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdUnknownPCL5.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter.cmd; 6 | 7 | import org.getopt.pcl5.PrinterState; 8 | 9 | /** 10 | * Unknown command, traces out info about unrecognized command 11 | */ 12 | public class CmdUnknownPCL5 extends BaseCommandPCL5 { 13 | /** 14 | * @param printerState 15 | */ 16 | public CmdUnknownPCL5(PrinterState printerState) { 17 | super(printerState); 18 | } 19 | 20 | public boolean execute(int data) { 21 | _printerState.trace(this.toString(), "Unknown printer command [0x" 22 | + Integer.toHexString(data) + "]"); 23 | 24 | return true; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdUserDefinedPattern.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * c # W 3 | * The User-Defined Pattern command provides the means for 4 | * downloading the binary pattern data that defines the user pattern. 5 | * 6 | * # =Number of pattern data bytes 7 | * 8 | * Default = 0 9 | * Range = 0 - 32767 (values outside the range are ignored) 10 | * 11 | * Notes 12 | * 13 | * implemented Sep 22, 2005 14 | * 15 | */ 16 | package org.getopt.pcl5.PCL5Interpreter.cmd; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | 21 | import org.getopt.pcl5.PrinterState; 22 | import org.getopt.pcl5.PCL5Interpreter.UserDefinedPattern; 23 | 24 | public class CmdUserDefinedPattern extends EscExtendedCommandPCL5 { 25 | 26 | public CmdUserDefinedPattern(PrinterState printerState) { 27 | super(printerState); 28 | } 29 | 30 | public boolean execute(char family, char subfamily, String parameter, 31 | char cmd, InputStream in) throws IOException { 32 | if (family == '*' && subfamily == 'c' && cmd == 'W') { 33 | int param = Integer.parseInt((parameter)); 34 | UserDefinedPattern pattern = new UserDefinedPattern(param, in); 35 | 36 | _printerState.setUserDefinedPattern(pattern); 37 | return true; 38 | } 39 | 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdVerticalCursorPositioning.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * p # Y 3 | * This Vertical Cursor Positioning command moves the cursor to a new 4 | * position along the vertical axis. 5 | * 6 | * Default = N/A 7 | * Range = �32767 to 32767 8 | * 9 | * # = Number of PCL Units 10 | * 11 | * Notes 12 | * A value field (#) with a plus sign (+) indicates the new position is 13 | * downward from and relative to the current cursor position; a minus 14 | * sign (�) indicates the new position is upward from and relative to the 15 | * current cursor position. No sign indicates an absolute distance from 16 | * the top margin. The top position, defined by the top margin, is 0 and 17 | * the bottom position is determined by the bottom of the logical page. 18 | * If a request is made for a location outside the printer�s logical page, 19 | * the current active position (CAP) is moved to the appropriate logical 20 | * page limit. 21 | * The current unit size used in PCL Unit moves is determined by the 22 | * value specified in the Unit of Measure command. If no other value is 23 | * specified, the number of units-per-inch for PCL unit moves is one unit 24 | * equals 1/300 inch. 25 | * 26 | * implemented Sep 21, 2005 27 | * 28 | */ 29 | package org.getopt.pcl5.PCL5Interpreter.cmd; 30 | 31 | import java.io.IOException; 32 | import java.io.InputStream; 33 | 34 | import org.getopt.pcl5.PrinterState; 35 | 36 | public class CmdVerticalCursorPositioning extends EscExtendedCommandPCL5 { 37 | public CmdVerticalCursorPositioning(PrinterState printerState) { 38 | super(printerState); 39 | } 40 | 41 | public boolean execute(char family, char subfamily, String parameter, 42 | char cmd, InputStream in) throws IOException { 43 | if (family == '*' && subfamily == 'p' && cmd == 'Y') { 44 | int param = Integer.parseInt((parameter)); 45 | 46 | // if first char is + or - it's relative posiotioning 47 | if (Character.isDigit(parameter.charAt(0))) 48 | _printerState.setAbsoluteVerticalCursorPosition(param); 49 | else 50 | _printerState.setRelativeVerticalCursorPosition(param); 51 | 52 | return true; 53 | } 54 | 55 | return false; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdVerticalMotionIndex.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC & l # C 3 | * The Vertical Motion Index (VMI) command designates the height of 4 | * the rows. (The vertical distance the cursor moves for a Line Feed operation.) 5 | * 6 | * Default = 8 7 | * Range = 0 - Current logical page length up to a maximum of 32767 8 | * 9 | * # = number of 1/48 inch increments between rows. 10 | * 11 | * Notes 12 | * If the specified VMI is greater than the current logical page length, 13 | * the command is ignored. 14 | * 15 | * The value field is valid to 4 decimal places. A ? in the value field indicates 16 | * no vertical movement. This command affects the Line Feed and Half-Line Feed spacing. 17 | * The factory default VMI is 8, which corresponds to 6 lines-per-inch. 18 | * A user default VMI can be selected from the control panel using the 19 | * FORM menu item (refer to the printer User�s Manual for additional information). 20 | * 21 | * implemented Sep 20, 2005 22 | * 23 | */ 24 | package org.getopt.pcl5.PCL5Interpreter.cmd; 25 | 26 | import java.io.IOException; 27 | import java.io.InputStream; 28 | 29 | import org.getopt.pcl5.IPrinterState; 30 | import org.getopt.pcl5.PrinterState; 31 | 32 | public class CmdVerticalMotionIndex extends EscExtendedCommandPCL5 { 33 | 34 | public CmdVerticalMotionIndex(PrinterState printerState) { 35 | super(printerState); 36 | } 37 | 38 | public boolean execute(char family, char subfamily, String parameter, 39 | char cmd, InputStream in) throws IOException { 40 | if (family == '&' && subfamily == 'l' && cmd == 'C') { 41 | int param = Integer.parseInt((parameter)); 42 | _printerState.setVerticalMotionIndex(param); 43 | 44 | return true; 45 | } 46 | 47 | return false; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CmdVerticalRectangleSize.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command ESC * c # B 3 | * This Vertical Rectangle Size command specifies the rectangle height in PCL Units. 4 | * 5 | * Default = 0 6 | * Range = 0 - 32767 7 | * 8 | * # = Number of PCL Units 9 | * 10 | * Notes 11 | * For example, if the unit of measure is set to 300 units-per-inch, to 12 | * specify a two-inch wide rectangle, send the command: Esc*c600A 13 | * The same command specifies a one-inch wide rectangle if the unit of 14 | * measure is set to 600 units-per-inch. 15 | * 16 | * implemented Sep 21, 2005 17 | * 18 | */ 19 | package org.getopt.pcl5.PCL5Interpreter.cmd; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | import org.getopt.pcl5.PrinterState; 25 | 26 | public class CmdVerticalRectangleSize extends EscExtendedCommandPCL5 { 27 | public CmdVerticalRectangleSize(PrinterState printerState) { 28 | super(printerState); 29 | } 30 | 31 | public boolean execute(char family, char subfamily, String parameter, 32 | char cmd, InputStream in) throws IOException { 33 | if (family == '*' && subfamily == 'c' && cmd == 'B') { 34 | int param = Integer.parseInt((parameter)); 35 | _printerState.setVerticalRectangleSize(param); 36 | 37 | return true; 38 | } 39 | 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/CommandPCL5.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter.cmd; 6 | 7 | import org.getopt.pcl5.PrinterState; 8 | 9 | /** 10 | * Base class to handle control codes commands Main reason for this class is to 11 | * create dinstinct type of commands 12 | */ 13 | public abstract class CommandPCL5 extends BaseCommandPCL5 { 14 | /** 15 | * @param printerState 16 | */ 17 | CommandPCL5(PrinterState printerState) { 18 | super(printerState); 19 | } 20 | 21 | /** 22 | * Execute command if possible 23 | * 24 | * @param data 25 | * command to execute 26 | * 27 | * @return true if handled 28 | */ 29 | abstract public boolean execute(int data); 30 | } 31 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/EscCommandPCL5.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter.cmd; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | import org.getopt.pcl5.IPrinterState; 11 | import org.getopt.pcl5.PrinterState; 12 | 13 | /** 14 | * Base class to handle Esc command Main reason for this class is to create 15 | * dinstinct type of commands 16 | */ 17 | public class EscCommandPCL5 extends BaseCommandPCL5 { 18 | /** 19 | * @param printerState 20 | */ 21 | public EscCommandPCL5(PrinterState printerState) { 22 | super(printerState); 23 | } 24 | 25 | /** 26 | * Main method class, it should check in can interpret command and interpret 27 | * one 28 | * 29 | * @param cmd 30 | * Command code (after Esc ( ) 31 | * @param in 32 | * Input stream for reading parameters 33 | * 34 | * @return should return true if handled else false 35 | * 36 | * @throws IOException 37 | */ 38 | public boolean execute(char cmd, InputStream in) throws IOException { 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PCL5Interpreter/cmd/EscExtendedCommandPCL5.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-17 3 | * 4 | */ 5 | package org.getopt.pcl5.PCL5Interpreter.cmd; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | import org.getopt.pcl5.PrinterState; 11 | 12 | /** 13 | * Base class to handle extended Esc command, extended Esc command is command 14 | * that starts with Esc ( 15 | */ 16 | public class EscExtendedCommandPCL5 extends BaseCommandPCL5 { 17 | /** 18 | * @param printerState 19 | */ 20 | public EscExtendedCommandPCL5(PrinterState printerState) { 21 | super(printerState); 22 | } 23 | 24 | /** 25 | * Main method class, it should check if can interpret command and interpret 26 | * one 27 | * 28 | * @param family 29 | * Command family (first char after Esc)(non letter and non digit) 30 | * @param subfamily 31 | * Additional parameter (second char after Esc)(small letter) 32 | * @param parameter 33 | * Numeric parameter for command (if missing set to 0) 34 | * @param cmd 35 | * Command code 36 | * @param in 37 | * Input stream for reading parameters 38 | * 39 | * @return should return true if handled else false 40 | * 41 | * @throws IOException 42 | */ 43 | public boolean execute(char family, char subfamily, String parameter, 44 | char cmd, InputStream in) throws IOException { 45 | return false; 46 | } 47 | 48 | /** 49 | * Helper method to read number of bytes from stream 50 | * 51 | * @param in 52 | * Input stream 53 | * @param size 54 | * Number of bytes to read 55 | * @return Byte array of given size filled from stream 56 | * @throws IOException 57 | */ 58 | protected byte[] loadFromStream(InputStream in, int size) throws IOException { 59 | byte[] data = new byte[size]; 60 | 61 | in.read(data); 62 | 63 | return data; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PJLInterpreter/cmd/BaseCommandPJL.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PJLInterpreter.cmd; 2 | 3 | import org.getopt.pcl5.PrinterState; 4 | 5 | /** 6 | * Base class for all command classes Contains instance of PrinterState 7 | */ 8 | public class BaseCommandPJL { 9 | PrinterState _printerState; 10 | 11 | public BaseCommandPJL(PrinterState printerState) { 12 | this._printerState = printerState; 13 | } 14 | 15 | /** 16 | * Can return command code in derived class, if returned class will be put in 17 | * hashtable 18 | * 19 | * @return code for command, null means not set 20 | */ 21 | public String getCommandString() { 22 | return null; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PJLInterpreter/cmd/CmdComment.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PJLInterpreter.cmd; 2 | 3 | import org.getopt.pcl5.PrinterState; 4 | 5 | public class CmdComment extends CommandPJL { 6 | 7 | private final String COMMAND = "COMMENT"; 8 | 9 | public CmdComment(PrinterState printerState) { 10 | super(printerState); 11 | } 12 | 13 | public boolean execute(String[] cmd) { 14 | if (cmd[1].equalsIgnoreCase(COMMAND)) { 15 | String comment = ""; 16 | for (int i = 2; i < cmd.length; i++) 17 | comment += cmd[i] + " "; 18 | 19 | _printerState.trace(this, comment); 20 | } 21 | 22 | return false; 23 | } 24 | 25 | public String getCommandString() { 26 | return COMMAND; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PJLInterpreter/cmd/CmdEnter.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PJLInterpreter.cmd; 2 | 3 | import org.getopt.pcl5.PrinterState; 4 | 5 | public class CmdEnter extends CommandPJL { 6 | 7 | private final String COMMAND = "ENTER"; 8 | 9 | public CmdEnter(PrinterState printerState) { 10 | super(printerState); 11 | } 12 | 13 | public boolean execute(String[] cmd) { 14 | if (cmd[1].equalsIgnoreCase(COMMAND)) { 15 | _printerState.trace(this, cmd.toString()); 16 | 17 | String[] params = cmd[2].split("="); 18 | 19 | if (params[1].equalsIgnoreCase("PCL")) 20 | _printerState.setActiveLanguage(PrinterState.Language.PCL5); 21 | else if (params[1].equalsIgnoreCase("HPGL")) 22 | _printerState.setActiveLanguage(PrinterState.Language.HPGL); 23 | else 24 | _printerState.assertCondition(this, "Unknown language: " + params[0]); 25 | } 26 | 27 | return false; 28 | } 29 | 30 | public String getCommandString() { 31 | return COMMAND; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PJLInterpreter/cmd/CmdEscUnknownPJL.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PJLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | /** 9 | * Unknown Esc command, traces out info about unrecognized command 10 | */ 11 | public class CmdEscUnknownPJL extends BaseCommandPJL { 12 | 13 | public CmdEscUnknownPJL(PrinterState printerState) { 14 | super(printerState); 15 | } 16 | 17 | public boolean execute(char cmd, InputStream in) throws IOException { 18 | _printerState.trace(this.toString(), "Unknown Esc printer command [0x" 19 | + Integer.toHexString(cmd) + "]"); 20 | 21 | return true; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PJLInterpreter/cmd/CmdSet.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PJLInterpreter.cmd; 2 | 3 | import org.getopt.pcl5.PrinterState; 4 | 5 | public class CmdSet extends CommandPJL { 6 | 7 | private static final String COMMAND = "SET"; 8 | 9 | public CmdSet(PrinterState printerState) { 10 | super(printerState); 11 | } 12 | 13 | public boolean execute(String[] cmd) { 14 | if (cmd[1].equalsIgnoreCase(COMMAND)) { 15 | _printerState.trace(this, cmd.toString()); 16 | 17 | String[] params = cmd[2].split("="); 18 | _printerState.setEnvironment(params[0], params[1]); 19 | } 20 | 21 | return false; 22 | } 23 | 24 | public String getCommandString() { 25 | return COMMAND; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PJLInterpreter/cmd/CmdUniversalExitLanguage.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PJLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | public class CmdUniversalExitLanguage extends EscCommandPJL { 9 | 10 | public CmdUniversalExitLanguage(PrinterState printerState) { 11 | super(printerState); 12 | } 13 | 14 | char _cmd; 15 | 16 | protected int readNum(InputStream in) throws IOException { 17 | char c = (char) in.read(); 18 | String number = ""; 19 | 20 | while (c == '+' || c == '-' || Character.isDefined(c)) 21 | number += c; 22 | 23 | // TODO: state class variable, but I can't return 2 values 24 | _cmd = c; 25 | 26 | return Integer.parseInt(number); 27 | } 28 | 29 | public boolean execute(char cmd, InputStream in) throws IOException { 30 | if (cmd == '%') { 31 | int param = readNum(in); 32 | 33 | if ((param == -12345) && (_cmd == 'X')) { 34 | // _printerState.reset(); 35 | _printerState.setActiveLanguage(PrinterState.Language.PJL); 36 | 37 | return true; 38 | } 39 | } 40 | 41 | return false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PJLInterpreter/cmd/CmdUnknownPJL.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PJLInterpreter.cmd; 2 | 3 | import org.getopt.pcl5.PrinterState; 4 | 5 | public class CmdUnknownPJL extends CommandPJL { 6 | 7 | public CmdUnknownPJL(PrinterState printerState) { 8 | super(printerState); 9 | } 10 | 11 | public boolean execute(String[] cmd) { 12 | _printerState.trace(this.toString(), "Unknown PJL printer command " 13 | + cmd[1]); 14 | 15 | return false; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PJLInterpreter/cmd/CommandPJL.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PJLInterpreter.cmd; 2 | 3 | import org.getopt.pcl5.PrinterState; 4 | 5 | public abstract class CommandPJL extends BaseCommandPJL { 6 | 7 | public CommandPJL(PrinterState printerState) { 8 | super(printerState); 9 | } 10 | 11 | /** 12 | * Execute command if possible 13 | * 14 | * @param data 15 | * command to execute 16 | * 17 | * @return true if handled 18 | */ 19 | abstract public boolean execute(String[] cmd); 20 | } 21 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PJLInterpreter/cmd/EscCommandPJL.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5.PJLInterpreter.cmd; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.getopt.pcl5.PrinterState; 7 | 8 | /** 9 | * Base class to handle Esc command Main reason for this class is to create 10 | * dinstinct type of commands 11 | * 12 | * @author Piotrm 13 | */ 14 | public class EscCommandPJL extends BaseCommandPJL { 15 | /** 16 | * @param printerState 17 | */ 18 | public EscCommandPJL(PrinterState printerState) { 19 | super(printerState); 20 | } 21 | 22 | /** 23 | * Main method class, it should check in can interpret command and interpret 24 | * one 25 | * 26 | * @param cmd 27 | * Command code (after Esc ( ) 28 | * @param in 29 | * Input stream for reading parameters 30 | * 31 | * @return should return true if handled else false 32 | * 33 | * @throws IOException 34 | */ 35 | public boolean execute(char cmd, InputStream in) throws IOException { 36 | return false; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PackageLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on 2004-09-23 3 | * 4 | */ 5 | package org.getopt.pcl5; 6 | 7 | import java.io.*; 8 | import java.util.*; 9 | 10 | /** 11 | * Package class loader, this class tries to load all class in package with 12 | * names that fit into class schema name. 13 | */ 14 | public class PackageLoader { 15 | // private String classSchemaName = "Cmd.*"; 16 | // private String classExt = "\\.class"; 17 | // private Pattern clsPattern = Pattern.compile(classSchemaName + classExt); 18 | 19 | // private final static String RESOURCE_NAME = "res/commands.properties"; 20 | 21 | private ArrayList classList = new ArrayList(); 22 | 23 | /** 24 | * Loads list of class names from resourceName file. 25 | * 26 | * @throws IOException 27 | */ 28 | public PackageLoader(String resourceName, String pkg) throws IOException { 29 | InputStream is = this.getClass().getResourceAsStream(resourceName); 30 | BufferedReader rd = new BufferedReader(new InputStreamReader(is)); 31 | 32 | String pckgName = this.getClass().getPackage().getName(); 33 | String line = rd.readLine(); 34 | while (line != null) { 35 | classList.add(pckgName + "." + pkg + ".cmd." + line); 36 | line = rd.readLine(); 37 | } 38 | } 39 | 40 | // public PackageLoader() 41 | // { 42 | // String pckgName = this.getClass().getPackage().getName(); 43 | // 44 | // String pckgPath = new String(pckgName); 45 | // 46 | // if (!pckgPath.startsWith("/")) 47 | // { 48 | // pckgPath = "/" + pckgPath; 49 | // } 50 | // pckgPath = pckgPath.replace('.','/'); 51 | // 52 | // URL url = this.getClass().getResource(pckgPath); 53 | // 54 | // // Happens only if the jar file is not well constructed, i.e. 55 | // // if the directories do not appear alone in the jar file 56 | // if (url == null) 57 | // throw new RuntimeException("Unable to open package: " + pckgName); 58 | // 59 | // File directory = new File(url.getFile()); 60 | // if (directory.exists()) 61 | // loadClassesFromDirectory(pckgName, directory); 62 | // else 63 | // loadClassesFromJar(url); 64 | // } 65 | // 66 | // private void loadClassesFromDirectory(String pckgName, File directory) 67 | // { 68 | // // Get the list of the files contained in the package 69 | // String[] files = directory.list(); 70 | // 71 | // for (int i = 0; i < files.length; i++) 72 | // { 73 | // // we are only interested in .class files that fits to pattern 74 | // Matcher m = clsPattern.matcher(files[i]); 75 | // 76 | // if (m.matches()) 77 | // { 78 | // // removes the .class extension 79 | // String classname = files[i].substring(0, files[i].length() - 6); 80 | // classList.add(pckgName + "." + classname); 81 | // } 82 | // } 83 | // } 84 | // 85 | // // FIXME: not tested yet!! 86 | // private void loadClassesFromJar(URL url) 87 | // { 88 | // try 89 | // { 90 | // JarURLConnection conn = (JarURLConnection)url.openConnection(); 91 | // 92 | // String starts = conn.getEntryName(); 93 | // JarFile jfile = conn.getJarFile(); 94 | // 95 | // Enumeration e = jfile.entries(); 96 | // 97 | // while (e.hasMoreElements()) 98 | // { 99 | // ZipEntry entry = (ZipEntry)e.nextElement(); 100 | // 101 | // String entryname = entry.getName(); 102 | // 103 | // Matcher m = clsPattern.matcher(entryname); 104 | // 105 | // if (m.matches()) 106 | // { 107 | // String classname = entryname.substring(0, entryname.length() - 6); 108 | // 109 | // if (classname.startsWith("/")) 110 | // classname = classname.substring(1); 111 | // 112 | // classname = classname.replace('/','.'); 113 | // 114 | // classList.add(classname); 115 | // } 116 | // } 117 | // } 118 | // catch (IOException ex) 119 | // { 120 | // System.err.println(ex); 121 | // } 122 | // } 123 | 124 | /** 125 | * @return Returns the classList. 126 | */ 127 | public ArrayList getClassList() { 128 | return classList; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/PageSize.java: -------------------------------------------------------------------------------- 1 | package org.getopt.pcl5; 2 | 3 | import java.util.*; 4 | 5 | public class PageSize { 6 | final public static int Letter = 2; 7 | final public static int LegalList1 = 3; 8 | final public static int LEDGER = 6; 9 | final public static int EXECUTIVE = 1; 10 | final public static int A4 = 26; 11 | final public static int A3 = 27; 12 | final public static int COM10 = 81; 13 | final public static int MONARCH = 80; 14 | final public static int C5 = 91; 15 | final public static int B5 = 100; 16 | final public static int DL = 90; 17 | 18 | final public static int Portrait = 0; 19 | final public static int Landscape = 1; 20 | final public static int ReversePortrait = 2; 21 | final public static int ReverseLandscape = 3; 22 | 23 | private int _orientation; 24 | private int _size; 25 | private PageDimensions _selectedSize; 26 | 27 | static class PageDimensions { 28 | // pages parameters are for 300 DPI we are using internally 7200 DPI 29 | final private static int RESOLUTION_MULT = 7200 / 300; 30 | private int _physicalPageWidth; 31 | private int _physicalPageLength; 32 | private int _logicalPageWidth; 33 | private int _maxLogicalPageLength; 34 | private int _distSizeToLogicalPage; 35 | private int _distTopToLogicalPage; 36 | private int _distSideToPrintableArea; 37 | private int _distTopToPrintableArea; 38 | 39 | public PageDimensions(int physicalPageWidth, int physicalPageLength, 40 | int logicalPageWidth, int maxLogicalPageLength, 41 | int distSizeToLogicalPage, int distTopToLogicalPage, 42 | int distSideToPrintableArea, int distTopToPrintableArea) { 43 | _physicalPageWidth = physicalPageWidth * RESOLUTION_MULT; 44 | _physicalPageLength = physicalPageLength * RESOLUTION_MULT; 45 | _logicalPageWidth = logicalPageWidth * RESOLUTION_MULT; 46 | _maxLogicalPageLength = maxLogicalPageLength * RESOLUTION_MULT; 47 | _distSizeToLogicalPage = distSizeToLogicalPage * RESOLUTION_MULT; 48 | _distTopToLogicalPage = distTopToLogicalPage * RESOLUTION_MULT; 49 | _distSideToPrintableArea = distSideToPrintableArea * RESOLUTION_MULT; 50 | _distTopToPrintableArea = distTopToPrintableArea * RESOLUTION_MULT; 51 | } 52 | 53 | /** 54 | * 55 | * @return distance from edge to printable area in 7200 dpi 56 | */ 57 | public int getDistSideToPrintableArea() { 58 | return _distSideToPrintableArea; 59 | } 60 | 61 | /** 62 | * 63 | * @return distance from edge to logical page in 7200 dpi 64 | */ 65 | public int getDistSizeToLogicalPage() { 66 | return _distSizeToLogicalPage; 67 | } 68 | 69 | public int getDistTopToLogicalPage() { 70 | return _distTopToLogicalPage; 71 | } 72 | 73 | public int getDistTopToPrintableArea() { 74 | return _distTopToPrintableArea; 75 | } 76 | 77 | /** 78 | * 79 | * @return logical page width in 7200 dpi units 80 | */ 81 | public int getLogicalPageWidth() { 82 | return _logicalPageWidth; 83 | } 84 | 85 | public int getMaxLogicalPageLength() { 86 | return _maxLogicalPageLength; 87 | } 88 | 89 | public int getPhysicalPageLength() { 90 | return _physicalPageLength; 91 | } 92 | 93 | public int getPhysicalPageWidth() { 94 | return _physicalPageWidth; 95 | } 96 | } 97 | 98 | final static HashMap _portaitPages = new HashMap(); 99 | final static HashMap _landscapePages = new HashMap(); 100 | 101 | static { 102 | // default if for 300 dpi 103 | // because we are using internally 7200 dpi all paramteres are multiplied by 104 | // 24 105 | // inside page dimensions class 106 | _portaitPages.put(new Integer(Letter), new PageDimensions(2550, 3300, 2400, 107 | 3300, 75, 0, 50, 150)); 108 | 109 | _portaitPages.put(new Integer(LegalList1), new PageDimensions(2550, 4200, 110 | 2400, 4200, 75, 0, 50, 150)); 111 | 112 | _portaitPages.put(new Integer(LEDGER), new PageDimensions(3300, 5100, 3150, 113 | 5100, 75, 0, 50, 150)); 114 | 115 | _portaitPages.put(new Integer(EXECUTIVE), new PageDimensions(2175, 3150, 116 | 2025, 3150, 75, 0, 50, 150)); 117 | 118 | _portaitPages.put(new Integer(A4), new PageDimensions(2480, 3507, 2338, 119 | 3507, 71, 0, 50, 150)); 120 | 121 | _portaitPages.put(new Integer(A3), new PageDimensions(3507, 4960, 3365, 122 | 4960, 71, 0, 50, 150)); 123 | 124 | _portaitPages.put(new Integer(COM10), new PageDimensions(1237, 2850, 1087, 125 | 2850, 75, 0, 50, 150)); 126 | 127 | _portaitPages.put(new Integer(MONARCH), new PageDimensions(1162, 2250, 128 | 1012, 2250, 75, 0, 50, 150)); 129 | 130 | _portaitPages.put(new Integer(C5), new PageDimensions(1913, 2704, 1771, 131 | 2704, 71, 0, 50, 150)); 132 | 133 | _portaitPages.put(new Integer(B5), new PageDimensions(2078, 2952, 1936, 134 | 2952, 71, 0, 50, 150)); 135 | 136 | _portaitPages.put(new Integer(DL), new PageDimensions(1299, 2598, 1157, 137 | 2598, 71, 0, 50, 150)); 138 | 139 | _landscapePages.put(new Integer(Letter), new PageDimensions(3300, 2550, 140 | 3180, 2550, 60, 0, 50, 150)); 141 | 142 | _landscapePages.put(new Integer(LegalList1), new PageDimensions(4200, 2550, 143 | 4080, 2550, 60, 0, 50, 150)); 144 | 145 | _landscapePages.put(new Integer(LEDGER), new PageDimensions(5100, 3300, 146 | 4980, 3300, 60, 0, 50, 150)); 147 | 148 | _landscapePages.put(new Integer(EXECUTIVE), new PageDimensions(3150, 2175, 149 | 3030, 2175, 60, 0, 50, 150)); 150 | 151 | _landscapePages.put(new Integer(A4), new PageDimensions(3507, 2480, 3389, 152 | 2480, 59, 0, 50, 150)); 153 | 154 | _landscapePages.put(new Integer(A3), new PageDimensions(4960, 3507, 4842, 155 | 3507, 59, 0, 50, 150)); 156 | 157 | _landscapePages.put(new Integer(COM10), new PageDimensions(2850, 1237, 158 | 2730, 1237, 60, 0, 50, 150)); 159 | 160 | _landscapePages.put(new Integer(MONARCH), new PageDimensions(2250, 1162, 161 | 2130, 1162, 60, 0, 50, 150)); 162 | 163 | _landscapePages.put(new Integer(C5), new PageDimensions(2704, 1913, 2586, 164 | 1913, 59, 0, 50, 150)); 165 | 166 | _landscapePages.put(new Integer(B5), new PageDimensions(2952, 2078, 2834, 167 | 2078, 59, 0, 50, 150)); 168 | 169 | _landscapePages.put(new Integer(DL), new PageDimensions(2598, 1299, 2480, 170 | 1299, 59, 0, 50, 150)); 171 | } 172 | 173 | public PageSize() { 174 | } 175 | 176 | public void setOrientation(int orientation) { 177 | _orientation = orientation; 178 | } 179 | 180 | public int getOrientation() { 181 | return _orientation; 182 | } 183 | 184 | public void setSize(int size) { 185 | _size = size; 186 | } 187 | 188 | private PageDimensions getDimensions() { 189 | if (_orientation == Portrait) 190 | return (PageDimensions) _portaitPages.get(new Integer(_size)); 191 | 192 | return (PageDimensions) _landscapePages.get(new Integer(_size)); 193 | } 194 | 195 | public int getPhysicalPageWidth() { 196 | return getDimensions().getPhysicalPageWidth(); 197 | } 198 | 199 | public int getPhysicalPageLength() { 200 | return getDimensions().getPhysicalPageLength(); 201 | } 202 | 203 | public int getPrintableAreaWidth() { 204 | return getPhysicalPageWidth() - 2 205 | * getDimensions().getDistSideToPrintableArea(); 206 | } 207 | 208 | public int getPrintableAreaLength() { 209 | return getPhysicalPageLength() - 2 210 | * getDimensions().getDistSideToPrintableArea(); 211 | } 212 | 213 | } 214 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/res/commands.properties: -------------------------------------------------------------------------------- 1 | CmdStrokeWeight 2 | CmdStyle 3 | CmdHeight 4 | CmdPitch 5 | CmdSpacing 6 | CmdTypefaceFamily 7 | CmdSymbolSet 8 | CmdUserDefinedPattern 9 | CmdPatternID 10 | CmdPictureFrameVerticalSize 11 | CmdPictureFrameHorizontalSize 12 | CmdSetPictureFrameAnchorPoint 13 | CmdUnitOfMeasure 14 | CmdEndRasterGraphics 15 | CmdEndRasterGraphicsEx 16 | CmdRasterGraphicsResolution 17 | CmdTransferRasterData 18 | CmdRasterGraphicsPresentationMode 19 | CmdSetCompressionMethod 20 | CmdStartRasterGraphics 21 | CmdFillRectangularArea 22 | CmdHorizontalRectangleSize 23 | CmdVerticalRectangleSize 24 | CmdVerticalCursorPositioning 25 | CmdHorizontalCursorPositioning 26 | CmdSelectCurrentPattern 27 | CmdPatternTransparencyMode 28 | CmdCharacterDefinition 29 | CmdCharacterCode 30 | CmdUnderline 31 | CmdFontSelectionbyID 32 | CmdFontHeader 33 | CmdFontID 34 | CmdCarriageReturn 35 | CmdSetCompressionMode 36 | CmdNumberOfCopies 37 | CmdRightMargin 38 | CmdLeftMargin 39 | CmdTopMargin 40 | CmdRasterGraphicsResolution 41 | CmdUniversalExitLanguage 42 | CmdPrinterReset 43 | CmdSimplexDuplexPrintCommand 44 | CmdRasterGraphicsPresentationMode 45 | CmdLogicalPageOrientation 46 | CmdPaperSource 47 | CmdPageSize 48 | CmdVerticalMotionIndex 49 | CmdFormFeed -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/res/hpglcommands.properties: -------------------------------------------------------------------------------- 1 | CmdEscCommand 2 | CmdComment 3 | CmdInputAbsolute 4 | CmdInputRelative 5 | CmdInputWindow 6 | CmdAdvanceFullPage 7 | CmdRotateCoordinateSystem 8 | CmdReplot 9 | -------------------------------------------------------------------------------- /src/java/org/getopt/pcl5/res/pjlcommands.properties: -------------------------------------------------------------------------------- 1 | CmdComment 2 | CmdSet 3 | CmdEnter --------------------------------------------------------------------------------