Class Encoder
java.lang.Object
com.google.zxing.qrcode.encoder.Encoder
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[](package private) static final Charset -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static voidappend8BitBytes(String content, BitArray bits, Charset encoding) (package private) static voidappendAlphanumericBytes(CharSequence content, BitArray bits) (package private) static voidappendBytes(String content, Mode mode, BitArray bits, Charset encoding) Append "bytes" in "mode" mode (encoding) into "bits".private static voidappendECI(CharacterSetECI eci, BitArray bits) (package private) static voidappendKanjiBytes(String content, BitArray bits) (package private) static voidappendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) Append length info.(package private) static voidappendModeInfo(Mode mode, BitArray bits) Append mode info.(package private) static voidappendNumericBytes(CharSequence content, BitArray bits) private static intcalculateBitsNeeded(Mode mode, BitArray headerBits, BitArray dataBits, Version version) private static intcalculateMaskPenalty(ByteMatrix matrix) private static intchooseMaskPattern(BitArray bits, ErrorCorrectionLevel ecLevel, Version version, ByteMatrix matrix) static ModechooseMode(String content) private static ModechooseMode(String content, Charset encoding) Choose the best mode by examining the content.private static VersionchooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) static QRCodeencode(String content, ErrorCorrectionLevel ecLevel) static QRCodeencode(String content, ErrorCorrectionLevel ecLevel, Map<EncodeHintType, ?> hints) (package private) static byte[]generateECBytes(byte[] dataBytes, int numEcBytesInBlock) (package private) static intgetAlphanumericCode(int code) (package private) static voidgetNumDataBytesAndNumECBytesForBlockID(int numTotalBytes, int numDataBytes, int numRSBlocks, int blockID, int[] numDataBytesInBlock, int[] numECBytesInBlock) Get number of data bytes and number of error correction bytes for block id "blockID".(package private) static BitArrayinterleaveWithECBytes(BitArray bits, int numTotalBytes, int numDataBytes, int numRSBlocks) Interleave "bits" with corresponding error correction bytes.(package private) static booleanisOnlyDoubleByteKanji(String content) private static VersionrecommendVersion(ErrorCorrectionLevel ecLevel, Mode mode, BitArray headerBits, BitArray dataBits) Decides the smallest version of QR code that will contain all of the provided data.(package private) static voidterminateBits(int numDataBytes, BitArray bits) Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).(package private) static booleanwillFit(int numInputBits, Version version, ErrorCorrectionLevel ecLevel)
-
Field Details
-
ALPHANUMERIC_TABLE
private static final int[] ALPHANUMERIC_TABLE -
DEFAULT_BYTE_MODE_ENCODING
-
-
Constructor Details
-
Encoder
private Encoder()
-
-
Method Details
-
calculateMaskPenalty
-
encode
- Parameters:
content- text to encodeecLevel- error correction level to use- Returns:
QRCoderepresenting the encoded QR code- Throws:
WriterException- if encoding can't succeed, because of for example invalid content or configuration
-
encode
public static QRCode encode(String content, ErrorCorrectionLevel ecLevel, Map<EncodeHintType, ?> hints) throws WriterException - Throws:
WriterException
-
recommendVersion
private static Version recommendVersion(ErrorCorrectionLevel ecLevel, Mode mode, BitArray headerBits, BitArray dataBits) throws WriterException Decides the smallest version of QR code that will contain all of the provided data.- Throws:
WriterException- if the data cannot fit in any version
-
calculateBitsNeeded
-
getAlphanumericCode
static int getAlphanumericCode(int code) - Returns:
- the code point of the table used in alphanumeric mode or -1 if there is no corresponding code in the table.
-
chooseMode
-
chooseMode
Choose the best mode by examining the content. Note that 'encoding' is used as a hint; if it is Shift_JIS, and the input is only double-byte Kanji, then we returnMode.KANJI. -
isOnlyDoubleByteKanji
-
chooseMaskPattern
private static int chooseMaskPattern(BitArray bits, ErrorCorrectionLevel ecLevel, Version version, ByteMatrix matrix) throws WriterException - Throws:
WriterException
-
chooseVersion
private static Version chooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) throws WriterException - Throws:
WriterException
-
willFit
- Returns:
- true if the number of input bits will fit in a code with the specified version and error correction level.
-
terminateBits
Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).- Throws:
WriterException
-
getNumDataBytesAndNumECBytesForBlockID
static void getNumDataBytesAndNumECBytesForBlockID(int numTotalBytes, int numDataBytes, int numRSBlocks, int blockID, int[] numDataBytesInBlock, int[] numECBytesInBlock) throws WriterException Get number of data bytes and number of error correction bytes for block id "blockID". Store the result in "numDataBytesInBlock", and "numECBytesInBlock". See table 12 in 8.5.1 of JISX0510:2004 (p.30)- Throws:
WriterException
-
interleaveWithECBytes
static BitArray interleaveWithECBytes(BitArray bits, int numTotalBytes, int numDataBytes, int numRSBlocks) throws WriterException Interleave "bits" with corresponding error correction bytes. On success, store the result in "result". The interleave rule is complicated. See 8.6 of JISX0510:2004 (p.37) for details.- Throws:
WriterException
-
generateECBytes
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) -
appendModeInfo
-
appendLengthInfo
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException Append length info. On success, store the result in "bits".- Throws:
WriterException
-
appendBytes
static void appendBytes(String content, Mode mode, BitArray bits, Charset encoding) throws WriterException Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".- Throws:
WriterException
-
appendNumericBytes
-
appendAlphanumericBytes
- Throws:
WriterException
-
append8BitBytes
-
appendKanjiBytes
- Throws:
WriterException
-
appendECI
-