Class MinimalEncoder
java.lang.Object
com.google.zxing.datamatrix.encoder.MinimalEncoder
Encoder that encodes minimally
Algorithm:
Uses Dijkstra to produce mathematically minimal encodings that are in some cases smaller than the results produced
by the algorithm described in annex S in the specification ISO/IEC 16022:200(E). The biggest improvment of this
algorithm over that one is the case when the algorithm enters the most inefficient mode, the B256 mode. The
algorithm from the specification algorithm will exit this mode only if it encounters digits so that arbitrarily
inefficient results can be produced if the postfix contains no digits.
Multi ECI support and ECI switching:
For multi language content the algorithm selects the most compact representation using ECI modes. Note that unlike
the compaction algorithm used for QR-Codes, this implementation operates in two stages and therfore is not
mathematically optimal. In the first stage, the input string is encoded minimally as a stream of ECI character set
selectors and bytes encoded in the selected encoding. In this stage the algorithm might for example decide to
encode ocurrences of the characters "ŐŜ" (O-double-acute, S-circumflex) in UTF-8 by a single ECI or
alternatively by multiple ECIs that switch between IS0-8859-2 and ISO-8859-3 (e.g. in the case that the input
contains many * characters from ISO-8859-2 (Latin 2) and few from ISO-8859-3 (Latin 3)).
In a second stage this stream of ECIs and bytes is minimally encoded using the various Data Matrix encoding modes.
While both stages encode mathematically minimally it is not ensured that the result is mathematically minimal since
the size growth for inserting an ECI in the first stage can only be approximated as the first stage does not know
in which mode the ECI will occur in the second stage (may, or may not require an extra latch to ASCII depending on
the current mode). The reason for this shortcoming are difficulties in implementing it in a straightforward and
readable manner.
GS1 support
FNC1 delimiters can be encoded in the input string by using the FNC1 character specified in the encoding function.
When a FNC1 character is specified then a leading FNC1 will be encoded and all ocurrences of delimiter characters
while result in FNC1 codewords in the symbol.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
(package private) static enum
private static final class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static void
addEdge
(MinimalEncoder.Edge[][] edges, MinimalEncoder.Edge edge) (package private) static void
addEdges
(MinimalEncoder.Input input, MinimalEncoder.Edge[][] edges, int from, MinimalEncoder.Edge previous) (package private) static byte[]
encode
(String input, Charset priorityCharset, int fnc1, SymbolShapeHint shape, int macroId) Encodes input minimally and returns an array of the codewordsstatic String
encodeHighLevel
(String msg) Performs message encoding of a DataMatrix messagestatic String
encodeHighLevel
(String msg, Charset priorityCharset, int fnc1, SymbolShapeHint shape) Performs message encoding of a DataMatrix message(package private) static MinimalEncoder.Result
(package private) static int
getNumberOfC40Words
(MinimalEncoder.Input input, int from, boolean c40, int[] characterLength) (package private) static boolean
isExtendedASCII
(char ch, int fnc1) private static boolean
isInC40Shift1Set
(char ch) private static boolean
isInC40Shift2Set
(char ch, int fnc1) private static boolean
isInTextShift1Set
(char ch) private static boolean
isInTextShift2Set
(char ch, int fnc1)
-
Field Details
-
C40_SHIFT2_CHARS
static final char[] C40_SHIFT2_CHARS
-
-
Constructor Details
-
MinimalEncoder
private MinimalEncoder()
-
-
Method Details
-
isExtendedASCII
static boolean isExtendedASCII(char ch, int fnc1) -
isInC40Shift1Set
private static boolean isInC40Shift1Set(char ch) -
isInC40Shift2Set
private static boolean isInC40Shift2Set(char ch, int fnc1) -
isInTextShift1Set
private static boolean isInTextShift1Set(char ch) -
isInTextShift2Set
private static boolean isInTextShift2Set(char ch, int fnc1) -
encodeHighLevel
Performs message encoding of a DataMatrix message- Parameters:
msg
- the message- Returns:
- the encoded message (the char values range from 0 to 255)
-
encodeHighLevel
public static String encodeHighLevel(String msg, Charset priorityCharset, int fnc1, SymbolShapeHint shape) Performs message encoding of a DataMatrix message- Parameters:
msg
- the messagepriorityCharset
- The preferredCharset
. When the value of the argument is null, the algorithm chooses charsets that leads to a minimal representation. Otherwise the algorithm will use the priority charset to encode any character in the input that can be encoded by it if the charset is among the supported charsets.fnc1
- denotes the character in the input that represents the FNC1 character or -1 if this is not a GS1 bar code. If the value is not -1 then a FNC1 is also prepended.shape
- requested shape.- Returns:
- the encoded message (the char values range from 0 to 255)
-
encode
static byte[] encode(String input, Charset priorityCharset, int fnc1, SymbolShapeHint shape, int macroId) Encodes input minimally and returns an array of the codewords- Parameters:
input
- The string to encodepriorityCharset
- The preferredCharset
. When the value of the argument is null, the algorithm chooses charsets that leads to a minimal representation. Otherwise the algorithm will use the priority charset to encode any character in the input that can be encoded by it if the charset is among the supported charsets.fnc1
- denotes the character in the input that represents the FNC1 character or -1 if this is not a GS1 bar code. If the value is not -1 then a FNC1 is also prepended.shape
- requested shape.macroId
- Prepends the specified macro function in case that a value of 5 or 6 is specified.- Returns:
- An array of bytes representing the codewords of a minimal encoding.
-
addEdge
-
getNumberOfC40Words
static int getNumberOfC40Words(MinimalEncoder.Input input, int from, boolean c40, int[] characterLength) - Returns:
- the number of words in which the string starting at from can be encoded in c40 or text mode. The number of characters encoded is returned in characterLength. The number of characters encoded is also minimal in the sense that the algorithm stops as soon as a character encoding fills a C40 word competely (three C40 values). An exception is at the end of the string where two C40 values are allowed (according to the spec the third c40 value is filled with 0 (Shift 1) in this case).
-
addEdges
static void addEdges(MinimalEncoder.Input input, MinimalEncoder.Edge[][] edges, int from, MinimalEncoder.Edge previous) -
encodeMinimally
-