Package com.google.zxing.qrcode.encoder
Class MinimalEncoder
- java.lang.Object
-
- com.google.zxing.qrcode.encoder.MinimalEncoder
-
final class MinimalEncoder extends java.lang.ObjectEncoder 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 Classes Modifier and Type Class Description private classMinimalEncoder.Edge(package private) classMinimalEncoder.ResultListprivate static classMinimalEncoder.VersionSize
-
Field Summary
Fields Modifier and Type Field Description private ErrorCorrectionLevelecLevelprivate ECIEncoderSetencodersprivate booleanisGS1private java.lang.StringstringToEncode
-
Constructor Summary
Constructors Constructor Description MinimalEncoder(java.lang.String stringToEncode, java.nio.charset.Charset priorityCharset, boolean isGS1, ErrorCorrectionLevel ecLevel)Creates a MinimalEncoder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddEdge(MinimalEncoder.Edge[][][] edges, int position, MinimalEncoder.Edge edge)(package private) voidaddEdges(Version version, MinimalEncoder.Edge[][][] edges, int from, MinimalEncoder.Edge previous)(package private) booleancanEncode(Mode mode, char c)(package private) MinimalEncoder.ResultListencode(Version version)(package private) static MinimalEncoder.ResultListencode(java.lang.String stringToEncode, Version version, java.nio.charset.Charset priorityCharset, boolean isGS1, ErrorCorrectionLevel ecLevel)Encodes the string minimally(package private) MinimalEncoder.ResultListencodeSpecificVersion(Version version)(package private) static intgetCompactedOrdinal(Mode mode)(package private) static VersiongetVersion(MinimalEncoder.VersionSize versionSize)(package private) static MinimalEncoder.VersionSizegetVersionSize(Version version)(package private) static booleanisAlphanumeric(char c)(package private) static booleanisDoubleByteKanji(char c)(package private) static booleanisNumeric(char c)
-
-
-
Field Detail
-
stringToEncode
private final java.lang.String stringToEncode
-
isGS1
private final boolean isGS1
-
encoders
private final ECIEncoderSet encoders
-
ecLevel
private final ErrorCorrectionLevel ecLevel
-
-
Constructor Detail
-
MinimalEncoder
MinimalEncoder(java.lang.String stringToEncode, java.nio.charset.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-trueif a FNC1 is to be prepended;falseotherwiseecLevel- The error correction level.- See Also:
MinimalEncoder.ResultList.getVersion()
-
-
Method Detail
-
encode
static MinimalEncoder.ResultList encode(java.lang.String stringToEncode, Version version, java.nio.charset.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 (seemethodwhen 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-trueif a FNC1 is to be prepended;falseotherwiseecLevel- The error correction level.- Returns:
- An instance of
ResultListrepresenting the minimal solution. - Throws:
WriterException- See Also:
MinimalEncoder.ResultList.getBits(com.google.zxing.common.BitArray),MinimalEncoder.ResultList.getVersion(),MinimalEncoder.ResultList.getSize()
-
encode
MinimalEncoder.ResultList encode(Version version) throws WriterException
- Throws:
WriterException
-
getVersionSize
static MinimalEncoder.VersionSize getVersionSize(Version version)
-
getVersion
static Version getVersion(MinimalEncoder.VersionSize versionSize)
-
isNumeric
static boolean isNumeric(char c)
-
isDoubleByteKanji
static boolean isDoubleByteKanji(char c)
-
isAlphanumeric
static boolean isAlphanumeric(char c)
-
canEncode
boolean canEncode(Mode mode, char c)
-
getCompactedOrdinal
static int getCompactedOrdinal(Mode mode)
-
addEdge
void addEdge(MinimalEncoder.Edge[][][] edges, int position, MinimalEncoder.Edge edge)
-
addEdges
void addEdges(Version version, MinimalEncoder.Edge[][][] edges, int from, MinimalEncoder.Edge previous)
-
encodeSpecificVersion
MinimalEncoder.ResultList encodeSpecificVersion(Version version) throws WriterException
- Throws:
WriterException
-
-