Package com.google.zxing.qrcode.encoder
Class MinimalEncoder
java.lang.Object
com.google.zxing.qrcode.encoder.MinimalEncoder
Encoder that encodes minimally
Algorithm:
The eleventh commandment was "Thou Shalt Compute" or "Thou Shalt Not Compute" - I forget which (Alan Perilis).
This implementation computes. As an alternative, the QR-Code specification suggests heuristics like this one:
If initial input data is in the exclusive subset of the Alphanumeric character set AND if there are less than
[6,7,8] characters followed by data from the remainder of the 8-bit byte character set, THEN select the 8-
bit byte mode ELSE select Alphanumeric mode;
This is probably right for 99.99% of cases but there is at least this one counter example: The string "AAAAAAa"
encodes 2 bits smaller as ALPHANUMERIC(AAAAAA), BYTE(a) than by encoding it as BYTE(AAAAAAa).
Perhaps that is the only counter example but without having proof, it remains unclear.
ECI switching:
In multi language content the algorithm selects the most compact representation using ECI modes.
For example the most compact representation of the string "ŐŜ" (O-double-acute, S-circumflex) is
ECI(UTF-8), BYTE(ŐŜ) while prepending one or more times the same leading character as in
"ŐŐŜ", the most compact representation uses two ECIs so that the string is encoded as
ECI(ISO-8859-2), BYTE(ŐŐ), ECI(ISO-8859-3), BYTE(Ŝ).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
(package private) final class
private static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ErrorCorrectionLevel
private final ECIEncoderSet
private final boolean
private final String
-
Constructor Summary
ConstructorsConstructorDescriptionMinimalEncoder
(String stringToEncode, Charset priorityCharset, boolean isGS1, ErrorCorrectionLevel ecLevel) Creates a MinimalEncoder -
Method Summary
Modifier and TypeMethodDescription(package private) void
addEdge
(MinimalEncoder.Edge[][][] edges, int position, MinimalEncoder.Edge edge) (package private) void
addEdges
(Version version, MinimalEncoder.Edge[][][] edges, int from, MinimalEncoder.Edge previous) (package private) boolean
(package private) MinimalEncoder.ResultList
(package private) static MinimalEncoder.ResultList
encode
(String stringToEncode, Version version, Charset priorityCharset, boolean isGS1, ErrorCorrectionLevel ecLevel) Encodes the string minimally(package private) MinimalEncoder.ResultList
encodeSpecificVersion
(Version version) (package private) static int
getCompactedOrdinal
(Mode mode) (package private) static Version
getVersion
(MinimalEncoder.VersionSize versionSize) (package private) static MinimalEncoder.VersionSize
getVersionSize
(Version version) (package private) static boolean
isAlphanumeric
(char c) (package private) static boolean
isDoubleByteKanji
(char c) (package private) static boolean
isNumeric
(char c)
-
Field Details
-
stringToEncode
-
isGS1
private final boolean isGS1 -
encoders
-
ecLevel
-
-
Constructor Details
-
MinimalEncoder
MinimalEncoder(String stringToEncode, Charset priorityCharset, boolean isGS1, ErrorCorrectionLevel ecLevel) Creates a MinimalEncoder- Parameters:
stringToEncode
- 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.isGS1
-true
if a FNC1 is to be prepended;false
otherwiseecLevel
- The error correction level.- See Also:
-
-
Method Details
-
encode
static MinimalEncoder.ResultList encode(String stringToEncode, Version version, Charset priorityCharset, boolean isGS1, ErrorCorrectionLevel ecLevel) throws WriterException Encodes the string minimally- Parameters:
stringToEncode
- The string to encodeversion
- The preferredVersion
. A minimal version is computed (seemethod
when the value of the argument is nullpriorityCharset
- 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.isGS1
-true
if a FNC1 is to be prepended;false
otherwiseecLevel
- The error correction level.- Returns:
- An instance of
ResultList
representing the minimal solution. - Throws:
WriterException
- See Also:
-
encode
- Throws:
WriterException
-
getVersionSize
-
getVersion
-
isNumeric
static boolean isNumeric(char c) -
isDoubleByteKanji
static boolean isDoubleByteKanji(char c) -
isAlphanumeric
static boolean isAlphanumeric(char c) -
canEncode
-
getCompactedOrdinal
-
addEdge
-
addEdges
void addEdges(Version version, MinimalEncoder.Edge[][][] edges, int from, MinimalEncoder.Edge previous) -
encodeSpecificVersion
- Throws:
WriterException
-