Package com.itextpdf.text.pdf.qrcode
Class Encoder
java.lang.Object
com.itextpdf.text.pdf.qrcode.Encoder
- Since:
- 5.0.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]
(package private) static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static void
append8BitBytes
(String content, BitVector bits, String encoding) (package private) static void
appendAlphanumericBytes
(String content, BitVector bits) (package private) static void
appendBytes
(String content, Mode mode, BitVector bits, String encoding) Append "bytes" in "mode" mode (encoding) into "bits".private static void
appendECI
(CharacterSetECI eci, BitVector bits) (package private) static void
appendKanjiBytes
(String content, BitVector bits) (package private) static void
appendLengthInfo
(int numLetters, int version, Mode mode, BitVector bits) Append length info.(package private) static void
appendModeInfo
(Mode mode, BitVector bits) Append mode info.(package private) static void
appendNumericBytes
(String content, BitVector bits) private static int
calculateMaskPenalty
(ByteMatrix matrix) private static int
chooseMaskPattern
(BitVector bits, ErrorCorrectionLevel ecLevel, int version, ByteMatrix matrix) static Mode
chooseMode
(String content) static Mode
chooseMode
(String content, String encoding) Choose the best mode by examining the content.static void
encode
(String content, ErrorCorrectionLevel ecLevel, QRCode qrCode) Encode "bytes" with the error correction level "ecLevel".static void
encode
(String content, ErrorCorrectionLevel ecLevel, Map<EncodeHintType, Object> hints, QRCode qrCode) (package private) static ByteArray
generateECBytes
(ByteArray dataBytes, int numEcBytesInBlock) (package private) static int
getAlphanumericCode
(int code) (package private) static void
getNumDataBytesAndNumECBytesForBlockID
(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 void
initQRCode
(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode, QRCode qrCode) Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode".(package private) static void
interleaveWithECBytes
(BitVector bits, int numTotalBytes, int numDataBytes, int numRSBlocks, BitVector result) Interleave "bits" with corresponding error correction bytes.private static boolean
isOnlyDoubleByteKanji
(String content) (package private) static void
terminateBits
(int numDataBytes, BitVector bits) Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).
-
Field Details
-
ALPHANUMERIC_TABLE
private static final int[] ALPHANUMERIC_TABLE -
DEFAULT_BYTE_MODE_ENCODING
- See Also:
-
-
Constructor Details
-
Encoder
private Encoder()
-
-
Method Details
-
calculateMaskPenalty
-
encode
public static void encode(String content, ErrorCorrectionLevel ecLevel, QRCode qrCode) throws WriterException Encode "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.- Throws:
WriterException
-
encode
public static void encode(String content, ErrorCorrectionLevel ecLevel, Map<EncodeHintType, Object> hints, QRCode qrCode) throws WriterException- 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
-
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(BitVector bits, ErrorCorrectionLevel ecLevel, int version, ByteMatrix matrix) throws WriterException - Throws:
WriterException
-
initQRCode
private static void initQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode, QRCode qrCode) throws WriterException Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success, modify "qrCode".- Throws:
WriterException
-
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 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
-
generateECBytes
-
appendModeInfo
Append mode info. On success, store the result in "bits". -
appendLengthInfo
static void appendLengthInfo(int numLetters, int version, Mode mode, BitVector bits) throws WriterException Append length info. On success, store the result in "bits".- Throws:
WriterException
-
appendBytes
static void appendBytes(String content, Mode mode, BitVector bits, String 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
- Throws:
WriterException
-
appendKanjiBytes
- Throws:
WriterException
-
appendECI
-