jbars
Class Barcode128

java.lang.Object
  |
  +--jbars.Barcode
        |
        +--jbars.Barcode128

public class Barcode128
extends Barcode

Implements the code 128 and UCC/EAN-128. Other symbologies are allowed in raw mode.

The code types allowed are:

The default parameters are:
 x = 1f;
 font = new Font("Helvetica",Font.PLAIN,20));
 textAlignment = ALIGN_CENTER;
 codeType = CODE128;
 transparent = true;
 shotText = true
 quietZone = true;
 quietZoneX = 10;
 
This class is based on iText "A Free Java-PDF library by Bruno Lowagie and Paulo Soares" using the Mozilla Public License(MPL)

Author:
Andres Ederra, Paulo Soares

Field Summary
(package private) static byte[][] BARS
          The bars to generate the code.
(package private) static byte[] BARS_STOP
          The stop bars.
static char CODE_AB_TO_C
          The charset code change.
static char CODE_AC_TO_B
          The charset code change.
static char CODE_BC_TO_A
          The charset code change.
static char FNC1
          The code for UCC/EAN-128.
static char START_A
          The start code.
static char START_B
          The start code.
static char START_C
          The start code.
 
Fields inherited from class jbars.Barcode
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, backgroundColor, barHeight, checksumText, CODABAR, code, CODE128, CODE128_RAW, CODE128_UCC, CODE93, codeType, EAN13, EAN8, extended, font, generateChecksum, guardBars, n, PLANET, POSTNET, quietZone, quietZoneX, ROTATE_0, ROTATE_180, ROTATE_270, ROTATE_90, showText, size, startStopText, SUPP2, SUPP5, textAlignment, transparent, TYPE_CODE128, TYPE_CODE93, TYPE_INTERLEAVED2OF5, UPCA, UPCE, x
 
Constructor Summary
Barcode128()
          Creates new Barcode128
 
Method Summary
 float getBarcodeWidth()
          Gets the maximum width that the barcode will occupy.
static byte[] getBarsCode128Raw(java.lang.String text)
          Generates the bars.
(package private) static java.lang.String getPackedRawDigits(java.lang.String text, int textIndex, int numDigits)
          Packs the digits for charset C.
static java.lang.String getRawText(java.lang.String text, boolean ucc)
          Converts the human readable text to the characters needed to create a barcode.
(package private) static boolean isNextDigits(java.lang.String text, int textIndex, int numDigits)
          Returns true if the next numDigits starting from index textIndex are numeric.
 void placeBarcode(java.awt.image.BufferedImage i, java.awt.Color barColor, java.awt.Color textColor)
          Places the barcode in a BufferedImage.
 
Methods inherited from class jbars.Barcode
createImage, createImage, createPNG, createPNG, createPNG, createPNG, createPNG, createPNG, encodePNG, getBackgroundColor, getBarHeight, getCode, getCodeType, getFont, getFontName, getFontSize, getFontStyle, getN, getQuietZoneX, getSize, getTextAlignment, getX, isChecksumText, isExtended, isGenerateChecksum, isGuardBars, isQuietZone, isShowText, isStartStopText, isTransparent, scale, setBackgroundColor, setBarHeight, setChecksumText, setCode, setCodeType, setExtended, setFont, setFontName, setFontSize, setFontStyle, setGenerateChecksum, setGuardBars, setN, setQuietZone, setQuietZoneX, setShowText, setSize, setStartStopText, setTextAlignment, setTransparent, setX
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BARS

static byte[][] BARS
The bars to generate the code.


BARS_STOP

static byte[] BARS_STOP
The stop bars.


CODE_AB_TO_C

public static final char CODE_AB_TO_C
The charset code change.

See Also:
Constant Field Values

CODE_AC_TO_B

public static final char CODE_AC_TO_B
The charset code change.

See Also:
Constant Field Values

CODE_BC_TO_A

public static final char CODE_BC_TO_A
The charset code change.

See Also:
Constant Field Values

FNC1

public static final char FNC1
The code for UCC/EAN-128.

See Also:
Constant Field Values

START_A

public static final char START_A
The start code.

See Also:
Constant Field Values

START_B

public static final char START_B
The start code.

See Also:
Constant Field Values

START_C

public static final char START_C
The start code.

See Also:
Constant Field Values
Constructor Detail

Barcode128

public Barcode128()
Creates new Barcode128

Method Detail

getBarcodeWidth

public float getBarcodeWidth()
Gets the maximum width that the barcode will occupy. The lower left corner is always (0, 0).

Specified by:
getBarcodeWidth in class Barcode
Returns:
the size the barcode occupies.

getBarsCode128Raw

public static byte[] getBarsCode128Raw(java.lang.String text)
Generates the bars. The input has the actual barcodes, not the human readable text.

Parameters:
text - the barcode
Returns:
the bars

getPackedRawDigits

static java.lang.String getPackedRawDigits(java.lang.String text,
                                           int textIndex,
                                           int numDigits)
Packs the digits for charset C. It assumes that all the parameters are valid.

Parameters:
text - the text to pack
textIndex - where to pack from
numDigits - the number of digits to pack. It is always an even number
Returns:
the packed digits, two digits per character

getRawText

public static java.lang.String getRawText(java.lang.String text,
                                          boolean ucc)
Converts the human readable text to the characters needed to create a barcode. Some optimization is done to get the shortest code.

Parameters:
text - the text to convert
ucc - true if it is an UCC/EAN-128. In this case the character FNC1 is added
Returns:
the code ready to be fed to getBarsCode128Raw()

isNextDigits

static boolean isNextDigits(java.lang.String text,
                            int textIndex,
                            int numDigits)
Returns true if the next numDigits starting from index textIndex are numeric.

Parameters:
text - the text to check
textIndex - where to check from
numDigits - the number of digits to check
Returns:
the check result

placeBarcode

public void placeBarcode(java.awt.image.BufferedImage i,
                         java.awt.Color barColor,
                         java.awt.Color textColor)
Places the barcode in a BufferedImage. The The bars and text are written in the following colors:

barColor

textColor

Result

null

null

bars and text painted with current fill color

barColor

null

bars and text painted with barColor

null

textColor

bars painted with current color
text painted with textColor

barColor

textColor

bars painted with barColor
text painted with textColor

Specified by:
placeBarcode in class Barcode
Parameters:
barColor - the color of the bars. It can be null
textColor - the color of the text. It can be null
Returns:
void