Java Class «ImplCode128C» – Generate Code 128 C Barcode
- All Implemented Interfaces:
Cloneable
newInstance
static methods in the Barcode
class.
Code 128 C is a subset of Code 128, optimized for compact encoding of numeric data. Compactness is achieved by encoding digits in pairs, which allows the encoding to take up only half the space. A minor drawback is that the encoded number must always consist of an even number of digits. However, odd-length numbers can be automatically prefixed with a leading '0' to ensure an even length.
Code 128 C uses an internal checksum which is contained only within the barcode symbol and is not displayed in the plaintext representation of the barcode.
Note: Encoding the same number with Code 128 and Code 128 C will produce exactly the same barcode. However, Code 128 C can be used, for example, to provide additional validation of numeric values by throwing an exception if the value to be encoded contains non-numeric characters.
-
Field Summary
Fields inherited from class de.vwsoft.barcodelib4j.oned.ImplCode128
FNC1, FNC2, FNC3, FNC4
-
Method Summary
Modifier and TypeMethodDescriptionvoid
setContent
(String content, boolean autoComplete, boolean appendOptionalChecksum) Sets the number to be encoded in the barcode.Methods inherited from class de.vwsoft.barcodelib4j.oned.Barcode
clone, draw, draw, draw, getAddOn, getContent, getFont, getRatio, getText, getTextOffset, isFontSizeAdjusted, isOptionalChecksumVisible, isTextOnTop, isTextVisible, newInstance, newInstance, setAddOn, setCustomText, setFont, setFontSizeAdjusted, setOptionalChecksumVisible, setRatio, setTextOffset, setTextOnTop, setTextVisible, supportsAddOn, supportsCustomText, supportsOptionalChecksum, supportsRatio, supportsTextOnTop
-
Method Details
-
setContent
public void setContent(String content, boolean autoComplete, boolean appendOptionalChecksum) throws BarcodeException Sets the number to be encoded in the barcode.If the length of the number is odd and
autoComplete
istrue
, the method automatically adds a '0' at the beginning, as an odd length number cannot be encoded by Code 128 C according to the requirements of the barcode format.Alternatively, when
autoComplete
is set tofalse
, the method expects that the number is provided with the correct length. In certain scenarios, this can be used to double check the integrity of the number. For example, if it's assumed that the number is even in length, but the actual length turns out to be odd, this will be indicated by the method throwing aBarcodeException
.- Overrides:
setContent
in classImplCode128
- Parameters:
content
- the number to be encoded in the Code 128 C barcodeautoComplete
- whether to automatically add '0' at the beginning of the number if its length is oddappendOptionalChecksum
- has no function, as Code 128 C uses a fixed internal checksum which is not optional- Throws:
BarcodeException
- if the content is empty, contains non-numeric characters, or the length is odd whileautoComplete
isfalse
-