Documentation

Encoder
in package

Encoder.

Table of Contents

DEFAULT_BYTE_MODE_ECODING  = 'ISO-8859-1'
Default byte encoding.
ALPHANUMERIC_TABLE  = [ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00-0x0f -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10-0x1f 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, // 0x20-0x2f 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // 0x30-0x3f -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // 0x40-0x4f 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, ]
The original table is defined in the table 5 of JISX0510:2004 (p.19).
$codecs  : array<string|int, mixed>
Codec cache.
encode()  : QrCode
Encodes "content" with the error correction level "ecLevel".
append8BitBytes()  : void
Appends regular 8-bit bytes to a bit array.
appendAlphanumericBytes()  : void
Appends alpha-numeric bytes to a bit array.
appendBytes()  : void
Appends bytes to a bit array in a specific mode.
appendEci()  : void
Appends ECI information to a bit array.
appendKanjiBytes()  : void
Appends KANJI bytes to a bit array.
appendLengthInfo()  : void
Appends length information to a bit array.
appendModeInfo()  : void
Appends mode information to a bit array.
appendNumericBytes()  : void
Appends numeric bytes to a bit array.
calculateMaskPenalty()  : int
Calculates the mask penalty for a matrix.
chooseMaskPattern()  : int
Chooses the best mask pattern for a matrix.
chooseMode()  : Mode
Chooses the best mode for a given content.
chooseVersion()  : Version
Chooses the best version for the input.
generateEcBytes()  : SplFixedArray<string|int, int>
Generates EC bytes for given data.
getAlphanumericCode()  : int
Gets the alphanumeric code for a byte.
getCodec()  : ReedSolomonCodec
Gets an RS codec and caches it.
getNumDataBytesAndNumEcBytesForBlockId()  : array<string|int, int>
Gets number of data- and EC bytes for a block ID.
interleaveWithEcBytes()  : BitArray
Interleaves data with EC bytes.
isOnlyDoubleByteKanji()  : bool
Checks if content only consists of double-byte kanji characters.
terminateBits()  : void
Terminates the bits in a bit array.

Constants

DEFAULT_BYTE_MODE_ECODING

Default byte encoding.

public mixed DEFAULT_BYTE_MODE_ECODING = 'ISO-8859-1'

ALPHANUMERIC_TABLE

The original table is defined in the table 5 of JISX0510:2004 (p.19).

private mixed ALPHANUMERIC_TABLE = [ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00-0x0f -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10-0x1f 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, // 0x20-0x2f 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // 0x30-0x3f -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // 0x40-0x4f 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, ]

Properties

$codecs

Codec cache.

private static array<string|int, mixed> $codecs = []

Methods

encode()

Encodes "content" with the error correction level "ecLevel".

public static encode(string $content, ErrorCorrectionLevel $ecLevel[, string $encoding = self::DEFAULT_BYTE_MODE_ECODING ][, Version|null $forcedVersion = null ]) : QrCode
Parameters
$content : string
$ecLevel : ErrorCorrectionLevel
$encoding : string = self::DEFAULT_BYTE_MODE_ECODING
$forcedVersion : Version|null = null
Return values
QrCode

append8BitBytes()

Appends regular 8-bit bytes to a bit array.

private static append8BitBytes(string $content, BitArray $bits, string $encoding) : void
Parameters
$content : string
$bits : BitArray
$encoding : string
Tags
throws
WriterException

if content cannot be encoded to target encoding

Return values
void

appendAlphanumericBytes()

Appends alpha-numeric bytes to a bit array.

private static appendAlphanumericBytes(string $content, BitArray $bits) : void
Parameters
$content : string
$bits : BitArray
Tags
throws
WriterException

if an invalid alphanumeric code was found

Return values
void

appendBytes()

Appends bytes to a bit array in a specific mode.

private static appendBytes(string $content, Mode $mode, BitArray $bits, string $encoding) : void
Parameters
$content : string
$mode : Mode
$bits : BitArray
$encoding : string
Tags
throws
WriterException

if an invalid mode was supplied

Return values
void

appendKanjiBytes()

Appends KANJI bytes to a bit array.

private static appendKanjiBytes(string $content, BitArray $bits) : void
Parameters
$content : string
$bits : BitArray
Tags
throws
WriterException

if content does not seem to be encoded in SHIFT-JIS

throws
WriterException

if an invalid byte sequence occurs

Return values
void

appendLengthInfo()

Appends length information to a bit array.

private static appendLengthInfo(int $numLetters, Version $version, Mode $mode, BitArray $bits) : void
Parameters
$numLetters : int
$version : Version
$mode : Mode
$bits : BitArray
Tags
throws
WriterException

if num letters is bigger than expected

Return values
void

appendModeInfo()

Appends mode information to a bit array.

private static appendModeInfo(Mode $mode, BitArray $bits) : void
Parameters
$mode : Mode
$bits : BitArray
Return values
void

appendNumericBytes()

Appends numeric bytes to a bit array.

private static appendNumericBytes(string $content, BitArray $bits) : void
Parameters
$content : string
$bits : BitArray
Return values
void

calculateMaskPenalty()

Calculates the mask penalty for a matrix.

private static calculateMaskPenalty(ByteMatrix $matrix) : int
Parameters
$matrix : ByteMatrix
Return values
int

chooseMode()

Chooses the best mode for a given content.

private static chooseMode(string $content[, string $encoding = null ]) : Mode
Parameters
$content : string
$encoding : string = null
Return values
Mode

generateEcBytes()

Generates EC bytes for given data.

private static generateEcBytes(SplFixedArray<string|int, int> $dataBytes, int $numEcBytesInBlock) : SplFixedArray<string|int, int>
Parameters
$dataBytes : SplFixedArray<string|int, int>
$numEcBytesInBlock : int
Return values
SplFixedArray<string|int, int>

getAlphanumericCode()

Gets the alphanumeric code for a byte.

private static getAlphanumericCode(int $code) : int
Parameters
$code : int
Return values
int

getCodec()

Gets an RS codec and caches it.

private static getCodec(int $numDataBytes, int $numEcBytesInBlock) : ReedSolomonCodec
Parameters
$numDataBytes : int
$numEcBytesInBlock : int
Return values
ReedSolomonCodec

getNumDataBytesAndNumEcBytesForBlockId()

Gets number of data- and EC bytes for a block ID.

private static getNumDataBytesAndNumEcBytesForBlockId(int $numTotalBytes, int $numDataBytes, int $numRsBlocks, int $blockId) : array<string|int, int>
Parameters
$numTotalBytes : int
$numDataBytes : int
$numRsBlocks : int
$blockId : int
Tags
throws
WriterException

if block ID is too large

throws
WriterException

if EC bytes mismatch

throws
WriterException

if RS blocks mismatch

throws
WriterException

if total bytes mismatch

Return values
array<string|int, int>

interleaveWithEcBytes()

Interleaves data with EC bytes.

private static interleaveWithEcBytes(BitArray $bits, int $numTotalBytes, int $numDataBytes, int $numRsBlocks) : BitArray
Parameters
$bits : BitArray
$numTotalBytes : int
$numDataBytes : int
$numRsBlocks : int
Tags
throws
WriterException

if number of bits and data bytes does not match

throws
WriterException

if data bytes does not match offset

throws
WriterException

if an interleaving error occurs

Return values
BitArray

isOnlyDoubleByteKanji()

Checks if content only consists of double-byte kanji characters.

private static isOnlyDoubleByteKanji(string $content) : bool
Parameters
$content : string
Return values
bool

terminateBits()

Terminates the bits in a bit array.

private static terminateBits(int $numDataBytes, BitArray $bits) : void
Parameters
$numDataBytes : int
$bits : BitArray
Tags
throws
WriterException

if data bits cannot fit in the QR code

throws
WriterException

if bits size does not equal the capacity

Return values
void

Search results