Class Encoder
- java.lang.Object
-
- com.itextpdf.barcodes.qrcode.Encoder
-
final class Encoder extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static int[]ALPHANUMERIC_TABLE(package private) static java.lang.StringDEFAULT_BYTE_MODE_ENCODING
-
Constructor Summary
Constructors Modifier Constructor Description privateEncoder()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static voidappend8BitBytes(java.lang.String content, BitVector bits, java.lang.String encoding)(package private) static voidappendAlphanumericBytes(java.lang.String content, BitVector bits)(package private) static voidappendBytes(java.lang.String content, Mode mode, BitVector bits, java.lang.String encoding)Append "bytes" in "mode" mode (encoding) into "bits".private static voidappendECI(CharacterSetECI eci, BitVector bits)(package private) static voidappendKanjiBytes(java.lang.String content, BitVector bits)(package private) static voidappendLengthInfo(int numLetters, int version, Mode mode, BitVector bits)Append length info.(package private) static voidappendModeInfo(Mode mode, BitVector bits)Append mode info.(package private) static voidappendNumericBytes(java.lang.String content, BitVector bits)private static intcalculateMaskPenalty(ByteMatrix matrix)private static intchooseMaskPattern(BitVector bits, ErrorCorrectionLevel ecLevel, int version, ByteMatrix matrix)static ModechooseMode(java.lang.String content)Choose the best mode by examining the content.static ModechooseMode(java.lang.String content, java.lang.String encoding)Choose the best mode by examining the content.static voidencode(java.lang.String content, ErrorCorrectionLevel ecLevel, QRCode qrCode)Encode "bytes" with the error correction level "ecLevel".static voidencode(java.lang.String content, ErrorCorrectionLevel ecLevel, java.util.Map<EncodeHintType,java.lang.Object> hints, QRCode qrCode)Encode "bytes" with the error correction level "ecLevel".(package private) static ByteArraygenerateECBytes(ByteArray 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".private static voidinitQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, int desiredMinVersion, Mode mode, QRCode qrCode)Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode".(package private) static voidinterleaveWithECBytes(BitVector bits, int numTotalBytes, int numDataBytes, int numRSBlocks, BitVector result)Interleave "bits" with corresponding error correction bytes.private static booleanisOnlyDoubleByteKanji(java.lang.String content)(package private) static voidterminateBits(int numDataBytes, BitVector bits)Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).
-
-
-
Field Detail
-
ALPHANUMERIC_TABLE
private static final int[] ALPHANUMERIC_TABLE
-
DEFAULT_BYTE_MODE_ENCODING
static final java.lang.String DEFAULT_BYTE_MODE_ENCODING
- See Also:
- Constant Field Values
-
-
Method Detail
-
calculateMaskPenalty
private static int calculateMaskPenalty(ByteMatrix matrix)
-
encode
public static void encode(java.lang.String content, ErrorCorrectionLevel ecLevel, QRCode qrCode) throws WriterExceptionEncode "bytes" with the error correction level "ecLevel". The encoding mode will be chosen internally by chooseMode(). On success, store the result in "qrCode".We recommend you to use QRCode.EC_LEVEL_L (the lowest level) for "getECLevel" since our primary use is to show QR code on desktop screens. We don't need very strong error correction for this purpose.
Note that there is no way to encode bytes in MODE_KANJI. We might want to add EncodeWithMode() with which clients can specify the encoding mode. For now, we don't need the functionality.
- Parameters:
content- String to encodeecLevel- Error-correction level to useqrCode- QR code to store the result in- Throws:
WriterException
-
encode
public static void encode(java.lang.String content, ErrorCorrectionLevel ecLevel, java.util.Map<EncodeHintType,java.lang.Object> hints, QRCode qrCode) throws WriterExceptionEncode "bytes" with the error correction level "ecLevel". The encoding mode will be chosen internally by chooseMode(). On success, store the result in "qrCode".We recommend you to use QRCode.EC_LEVEL_L (the lowest level) for "getECLevel" since our primary use is to show QR code on desktop screens. We don't need very strong error correction for this purpose.
Note that there is no way to encode bytes in MODE_KANJI. We might want to add EncodeWithMode() with which clients can specify the encoding mode. For now, we don't need the functionality.
- Parameters:
content- String to encodeecLevel- Error-correction level to usehints- Optional Map containing encoding and suggested minimum version to useqrCode- QR code to store the result in- Throws:
WriterException
-
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
public static Mode chooseMode(java.lang.String content)
Choose the best mode by examining the content.- Parameters:
content- content to examine- Returns:
- mode to use
-
chooseMode
public static Mode chooseMode(java.lang.String content, java.lang.String encoding)
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- Parameters:
content- content to examineencoding- hint for the encoding to use- Returns:
- mode to use
-
isOnlyDoubleByteKanji
private static boolean isOnlyDoubleByteKanji(java.lang.String content)
-
chooseMaskPattern
private static int chooseMaskPattern(BitVector bits, ErrorCorrectionLevel ecLevel, int version, ByteMatrix matrix) throws WriterException
- Throws:
WriterException
-
initQRCode
private static void initQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, int desiredMinVersion, Mode mode, QRCode qrCode) throws WriterExceptionInitialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success, modify "qrCode".- Throws:
WriterException
-
terminateBits
static void terminateBits(int numDataBytes, BitVector bits) throws WriterExceptionTerminate 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 WriterExceptionGet 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 void interleaveWithECBytes(BitVector bits, int numTotalBytes, int numDataBytes, int numRSBlocks, BitVector result) 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
-
appendModeInfo
static void appendModeInfo(Mode mode, BitVector bits)
Append mode info. On success, store the result in "bits".
-
appendLengthInfo
static void appendLengthInfo(int numLetters, int version, Mode mode, BitVector bits) throws WriterExceptionAppend length info. On success, store the result in "bits".- Throws:
WriterException
-
appendBytes
static void appendBytes(java.lang.String content, Mode mode, BitVector bits, java.lang.String encoding) throws WriterExceptionAppend "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".- Throws:
WriterException
-
appendNumericBytes
static void appendNumericBytes(java.lang.String content, BitVector bits)
-
appendAlphanumericBytes
static void appendAlphanumericBytes(java.lang.String content, BitVector bits) throws WriterException- Throws:
WriterException
-
append8BitBytes
static void append8BitBytes(java.lang.String content, BitVector bits, java.lang.String encoding) throws WriterException- Throws:
WriterException
-
appendKanjiBytes
static void appendKanjiBytes(java.lang.String content, BitVector bits) throws WriterException- Throws:
WriterException
-
appendECI
private static void appendECI(CharacterSetECI eci, BitVector bits)
-
-