Class BarcodeDataMatrix


  • public class BarcodeDataMatrix
    extends Barcode2D
    A Data Matrix is a two-dimensional bar code consisting of black and white "cells" or dots arranged in either a square or rectangular pattern, also known as a matrix. The information to be encoded can be text or numeric data. Usual data size is from a few bytes up to 1556 bytes. The length of the encoded data depends on the number of cells in the matrix.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private int asciiEncodation​(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset)  
      private int b256Encodation​(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset)  
      private int C40OrTextEncodation​(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, boolean c40, int symbolIndex, int prevEnc, int origDataOffset)  
      java.awt.Image createAwtImage​(java.awt.Color foreground, java.awt.Color background)
      Creates a java.awt.Image.
      PdfFormXObject createFormXObject​(Color foreground, float moduleSide, PdfDocument document)
      Creates a PdfFormXObject with the barcode with given module width and module height.
      PdfFormXObject createFormXObject​(Color foreground, PdfDocument document)
      Creates a PdfFormXObject with the barcode.
      private void draw​(byte[] data, int dataSize, DmParams dm)  
      private int EdifactEncodation​(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset, boolean sizeFixed)  
      Rectangle getBarcodeSize()
      Gets the maximum area that the barcode and the text, if any, will occupy.
      Rectangle getBarcodeSize​(float moduleHeight, float moduleWidth)
      Gets the barcode size
      private int getEncodation​(byte[] text, int textOffset, int textSize, byte[] data, int dataOffset, int dataSize, int options, boolean sizeFixed)  
      java.lang.String getEncoding()
      getting encoding for data matrix code
      int getHeight()
      Gets the height of the barcode.
      private static int getNumber​(byte[] text, int ptrIn, int n)  
      int getOptions()
      Gets the barcode options.
      int getWidth()
      Gets the width of the barcode.
      int getWs()
      Gets the whitespace border around the barcode.
      private static boolean isDigit​(int c)  
      private static void makePadding​(byte[] data, int position, int count)  
      private static int minValueInColumn​(int[][] array, int column)  
      Rectangle placeBarcode​(PdfCanvas canvas, Color foreground)
      Places the barcode in a PdfCanvas.
      Rectangle placeBarcode​(PdfCanvas canvas, Color foreground, float moduleSide)
      Places the barcode in a PdfCanvas
      private int processExtensions​(byte[] text, int textOffset, int textSize, byte[] data)  
      private void randomizationAlgorithm255​(byte[] data, int j)  
      private void setBit​(int x, int y, int xByte)  
      int setCode​(byte[] text, int textOffset, int textSize)
      Creates a barcode.
      int setCode​(java.lang.String text)
      Creates a barcode.
      void setEncoding​(java.lang.String encoding)
      setting encoding for data matrix code ( default encoding iso-8859-1)
      void setHeight​(int height)
      Sets the height of the barcode.
      void setOptions​(int options)
      Sets the options for the barcode generation.
      void setWidth​(int width)
      Sets the width of the barcode.
      void setWs​(int ws)
      Sets the whitespace border around the barcode.
      private void solveFAndSwitchMode​(int[] forMin, int mode, int currIndex)  
      private static int valuePositionInColumn​(int[][] array, int column, int value)  
      private int X12Encodation​(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DM_ERROR_TEXT_TOO_BIG

        public static final int DM_ERROR_TEXT_TOO_BIG
        The text is too big for the symbology capabilities.
        See Also:
        Constant Field Values
      • DM_ERROR_INVALID_SQUARE

        public static final int DM_ERROR_INVALID_SQUARE
        The dimensions given for the symbol are illegal.
        See Also:
        Constant Field Values
      • DM_ERROR_EXTENSION

        public static final int DM_ERROR_EXTENSION
        An error while parsing an extension.
        See Also:
        Constant Field Values
      • DM_AUTO

        public static final int DM_AUTO
        The best encodation will be used.
        See Also:
        Constant Field Values
      • DM_RAW

        public static final int DM_RAW
        No encodation needed. The bytes provided are already encoded.
        See Also:
        Constant Field Values
      • DM_EXTENSION

        public static final int DM_EXTENSION
        Allows extensions to be embedded at the start of the text.
        See Also:
        Constant Field Values
      • DM_TEST

        public static final int DM_TEST
        Doesn't generate the image but returns all the other information.
        See Also:
        Constant Field Values
      • DEFAULT_DATA_MATRIX_ENCODING

        public static final java.lang.String DEFAULT_DATA_MATRIX_ENCODING
        See Also:
        Constant Field Values
      • encoding

        private java.lang.String encoding
      • dmSizes

        private static final DmParams[] dmSizes
      • extOut

        private int extOut
      • place

        private short[] place
      • image

        private byte[] image
      • height

        private int height
      • width

        private int width
      • ws

        private int ws
      • options

        private int options
      • f

        private int[][] f
      • switchMode

        private int[][] switchMode
    • Constructor Detail

      • BarcodeDataMatrix

        public BarcodeDataMatrix()
        Creates an instance of this class.
      • BarcodeDataMatrix

        public BarcodeDataMatrix​(java.lang.String code)
        Creates an instance of BarcodeDataMatrix
        Parameters:
        code - the code to generate. It should be noted that all characters will be encoded using the default encoding, ISO-8859-1
      • BarcodeDataMatrix

        public BarcodeDataMatrix​(java.lang.String code,
                                 java.lang.String encoding)
        Creates an instance of BarcodeDataMatrix
        Parameters:
        code - the code to generate.
        encoding - the encoding to use when generating the barcode
    • Method Detail

      • getBarcodeSize

        public Rectangle getBarcodeSize()
        Gets the maximum area that the barcode and the text, if any, will occupy. The lower left corner is always (0, 0).
        Specified by:
        getBarcodeSize in class Barcode2D
        Returns:
        the size the barcode occupies.
      • placeBarcode

        public Rectangle placeBarcode​(PdfCanvas canvas,
                                      Color foreground)
        Places the barcode in a PdfCanvas. The barcode is always placed at coordinates (0, 0). Use the translation matrix to move it elsewhere.
        Specified by:
        placeBarcode in class Barcode2D
        Parameters:
        canvas - the PdfCanvas where the barcode will be placed
        foreground - the foreground color. It can be null
        Returns:
        the dimensions the barcode occupies
      • createFormXObject

        public PdfFormXObject createFormXObject​(Color foreground,
                                                PdfDocument document)
        Creates a PdfFormXObject with the barcode.
        Specified by:
        createFormXObject in class Barcode2D
        Parameters:
        foreground - The color of the pixels. It can be null
        document - The document
        Returns:
        the XObject.
      • createFormXObject

        public PdfFormXObject createFormXObject​(Color foreground,
                                                float moduleSide,
                                                PdfDocument document)
        Creates a PdfFormXObject with the barcode with given module width and module height.
        Parameters:
        foreground - The color of the pixels. It can be null
        moduleSide - The side (width and height) of the pixels.
        document - The document
        Returns:
        the XObject.
      • placeBarcode

        public Rectangle placeBarcode​(PdfCanvas canvas,
                                      Color foreground,
                                      float moduleSide)
        Places the barcode in a PdfCanvas
        Parameters:
        canvas - the canvas to place the barcode on
        foreground - The foreground color of the barcode
        moduleSide - The side (width and height) of the pixels.
        Returns:
        the dimensions the barcode occupies
      • createAwtImage

        public java.awt.Image createAwtImage​(java.awt.Color foreground,
                                             java.awt.Color background)
        Creates a java.awt.Image. A successful call to the method generate() before calling this method is required.
        Parameters:
        foreground - the color of the bars
        background - the color of the background
        Returns:
        the image
      • getBarcodeSize

        public Rectangle getBarcodeSize​(float moduleHeight,
                                        float moduleWidth)
        Gets the barcode size
        Parameters:
        moduleHeight - The height of the module
        moduleWidth - The width of the module
        Returns:
        The size of the barcode
      • setCode

        public int setCode​(java.lang.String text)
        Creates a barcode. The String is interpreted with the ISO-8859-1 encoding
        Parameters:
        text - the text
        Returns:
        the status of the generation. It can be one of this values: DM_NO_ERROR - no error.
        DM_ERROR_TEXT_TOO_BIG - the text is too big for the symbology capabilities.
        DM_ERROR_INVALID_SQUARE - the dimensions given for the symbol are illegal.
        DM_ERROR_EXTENSION - an error was while parsing an extension.
      • setCode

        public int setCode​(byte[] text,
                           int textOffset,
                           int textSize)
        Creates a barcode.
        Parameters:
        text - the text
        textOffset - the offset to the start of the text
        textSize - the text size
        Returns:
        the status of the generation. It can be one of this values: DM_NO_ERROR - no error.
        DM_ERROR_TEXT_TOO_BIG - the text is too big for the symbology capabilities.
        DM_ERROR_INVALID_SQUARE - the dimensions given for the symbol are illegal.
        DM_ERROR_EXTENSION - an error was while parsing an extension.
      • getHeight

        public int getHeight()
        Gets the height of the barcode. Will contain the real height used after a successful call to generate(). This height doesn't include the whitespace border, if any.
        Returns:
        the height of the barcode
      • setHeight

        public void setHeight​(int height)
        Sets the height of the barcode. If the height is zero it will be calculated. This height doesn't include the whitespace border, if any. The allowed dimensions are (width, height):

        10, 10
        12, 12
        18, 8
        14, 14
        32, 8
        16, 16
        26, 12
        18, 18
        20, 20
        36, 12
        22, 22
        36, 16
        24, 24
        26, 26
        48, 16
        32, 32
        36, 36
        40, 40
        44, 44
        48, 48
        52, 52
        64, 64
        72, 72
        80, 80
        88, 88
        96, 96
        104, 104
        120, 120
        132, 132
        144, 144

        Parameters:
        height - the height of the barcode
      • getWidth

        public int getWidth()
        Gets the width of the barcode. Will contain the real width used after a successful call to generate(). This width doesn't include the whitespace border, if any.
        Returns:
        the width of the barcode
      • setWidth

        public void setWidth​(int width)
        Sets the width of the barcode. If the width is zero it will be calculated. This width doesn't include the whitespace border, if any. The allowed dimensions are (width, height):

        10, 10
        12, 12
        18, 8
        14, 14
        32, 8
        16, 16
        26, 12
        18, 18
        20, 20
        36, 12
        22, 22
        36, 16
        24, 24
        26, 26
        48, 16
        32, 32
        36, 36
        40, 40
        44, 44
        48, 48
        52, 52
        64, 64
        72, 72
        80, 80
        88, 88
        96, 96
        104, 104
        120, 120
        132, 132
        144, 144

        Parameters:
        width - the width of the barcode
      • getWs

        public int getWs()
        Gets the whitespace border around the barcode.
        Returns:
        the whitespace border around the barcode
      • setWs

        public void setWs​(int ws)
        Sets the whitespace border around the barcode.
        Parameters:
        ws - the whitespace border around the barcode
      • getOptions

        public int getOptions()
        Gets the barcode options.
        Returns:
        the barcode options
      • setOptions

        public void setOptions​(int options)
        Sets the options for the barcode generation. The options can be:

        One of:
        DM_AUTO - the best encodation will be used
        DM_ASCII - ASCII encodation
        DM_C40 - C40 encodation
        DM_TEXT - TEXT encodation
        DM_B256 - binary encodation
        DM_X12 - X12 encodation
        DM_EDIFACT - EDIFACT encodation
        DM_RAW - no encodation. The bytes provided are already encoded and will be added directly to the barcode, using padding if needed. It assumes that the encodation state is left at ASCII after the last byte.

        One of:
        DM_EXTENSION - allows extensions to be embedded at the start of the text:

        exxxxxx - ECI number xxxxxx
        m5 - macro 5
        m6 - macro 6
        f - FNC1
        saabbccccc - Structured Append, aa symbol position (1-16), bb total number of symbols (2-16), ccccc file identification (0-64515)
        p - Reader programming
        . - extension terminator

        Example for a structured append, symbol 2 of 6, with FNC1 and ECI 000005. The actual text is "Hello".

        s020600075fe000005.Hello

        One of:
        DM_TEST - doesn't generate the image but returns all the other information.

        Parameters:
        options - the barcode options
      • setEncoding

        public void setEncoding​(java.lang.String encoding)
        setting encoding for data matrix code ( default encoding iso-8859-1)
        Parameters:
        encoding - encoding for data matrix code
      • getEncoding

        public java.lang.String getEncoding()
        getting encoding for data matrix code
        Returns:
        encoding for data matrix code
      • makePadding

        private static void makePadding​(byte[] data,
                                        int position,
                                        int count)
      • isDigit

        private static boolean isDigit​(int c)
      • asciiEncodation

        private int asciiEncodation​(byte[] text,
                                    int textOffset,
                                    int textLength,
                                    byte[] data,
                                    int dataOffset,
                                    int dataLength,
                                    int symbolIndex,
                                    int prevEnc,
                                    int origDataOffset)
      • b256Encodation

        private int b256Encodation​(byte[] text,
                                   int textOffset,
                                   int textLength,
                                   byte[] data,
                                   int dataOffset,
                                   int dataLength,
                                   int symbolIndex,
                                   int prevEnc,
                                   int origDataOffset)
      • randomizationAlgorithm255

        private void randomizationAlgorithm255​(byte[] data,
                                               int j)
      • X12Encodation

        private int X12Encodation​(byte[] text,
                                  int textOffset,
                                  int textLength,
                                  byte[] data,
                                  int dataOffset,
                                  int dataLength,
                                  int symbolIndex,
                                  int prevEnc,
                                  int origDataOffset)
      • EdifactEncodation

        private int EdifactEncodation​(byte[] text,
                                      int textOffset,
                                      int textLength,
                                      byte[] data,
                                      int dataOffset,
                                      int dataLength,
                                      int symbolIndex,
                                      int prevEnc,
                                      int origDataOffset,
                                      boolean sizeFixed)
      • C40OrTextEncodation

        private int C40OrTextEncodation​(byte[] text,
                                        int textOffset,
                                        int textLength,
                                        byte[] data,
                                        int dataOffset,
                                        int dataLength,
                                        boolean c40,
                                        int symbolIndex,
                                        int prevEnc,
                                        int origDataOffset)
      • setBit

        private void setBit​(int x,
                            int y,
                            int xByte)
      • draw

        private void draw​(byte[] data,
                          int dataSize,
                          DmParams dm)
      • minValueInColumn

        private static int minValueInColumn​(int[][] array,
                                            int column)
      • valuePositionInColumn

        private static int valuePositionInColumn​(int[][] array,
                                                 int column,
                                                 int value)
      • solveFAndSwitchMode

        private void solveFAndSwitchMode​(int[] forMin,
                                         int mode,
                                         int currIndex)
      • getEncodation

        private int getEncodation​(byte[] text,
                                  int textOffset,
                                  int textSize,
                                  byte[] data,
                                  int dataOffset,
                                  int dataSize,
                                  int options,
                                  boolean sizeFixed)
      • getNumber

        private static int getNumber​(byte[] text,
                                     int ptrIn,
                                     int n)
      • processExtensions

        private int processExtensions​(byte[] text,
                                      int textOffset,
                                      int textSize,
                                      byte[] data)