Package com.google.zxing.qrcode.encoder
Class MinimalEncoder
- java.lang.Object
-
- com.google.zxing.qrcode.encoder.MinimalEncoder
-
final class MinimalEncoder extends java.lang.Object
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 Classes Modifier and Type Class Description private class
MinimalEncoder.Edge
(package private) class
MinimalEncoder.ResultList
private static class
MinimalEncoder.VersionSize
-
Field Summary
Fields Modifier and Type Field Description private ErrorCorrectionLevel
ecLevel
private ECIEncoderSet
encoders
private boolean
isGS1
private java.lang.String
stringToEncode
-
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) 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
canEncode(Mode mode, char c)
(package private) MinimalEncoder.ResultList
encode(Version version)
(package private) static MinimalEncoder.ResultList
encode(java.lang.String stringToEncode, Version version, java.nio.charset.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 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
-true
if a FNC1 is to be prepended;false
otherwiseecLevel
- 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 (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:
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
-
-