Constants

DEFAULT_BYTE_MODE_ECODING

DEFAULT_BYTE_MODE_ECODING = 'ISO-8859-1'

Default byte encoding.

ALPHANUMERIC_TABLE

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).

Properties

$codecs

$codecs : array

Codec cache.

Type

array

Methods

encode()

encode(string  $content, \BaconQrCode\Common\ErrorCorrectionLevel  $ecLevel, string  $encoding = self::DEFAULT_BYTE_MODE_ECODING) : \BaconQrCode\Encoder\QrCode

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

Parameters

string $content
\BaconQrCode\Common\ErrorCorrectionLevel $ecLevel
string $encoding

Returns

\BaconQrCode\Encoder\QrCode —

getAlphanumericCode()

getAlphanumericCode(int  $code) : int

Gets the alphanumeric code for a byte.

Parameters

int $code

Returns

int —

chooseMode()

chooseMode(string  $content, string  $encoding = null) : \BaconQrCode\Common\Mode

Chooses the best mode for a given content.

Parameters

string $content
string $encoding

Returns

\BaconQrCode\Common\Mode —

calculateMaskPenalty()

calculateMaskPenalty(\BaconQrCode\Encoder\ByteMatrix  $matrix) : int

Calculates the mask penalty for a matrix.

Parameters

\BaconQrCode\Encoder\ByteMatrix $matrix

Returns

int —

isOnlyDoubleByteKanji()

isOnlyDoubleByteKanji(string  $content) : bool

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

Parameters

string $content

Returns

bool —

chooseMaskPattern()

chooseMaskPattern(\BaconQrCode\Common\BitArray  $bits, \BaconQrCode\Common\ErrorCorrectionLevel  $ecLevel, \BaconQrCode\Common\Version  $version, \BaconQrCode\Encoder\ByteMatrix  $matrix) : int

Chooses the best mask pattern for a matrix.

Parameters

\BaconQrCode\Common\BitArray $bits
\BaconQrCode\Common\ErrorCorrectionLevel $ecLevel
\BaconQrCode\Common\Version $version
\BaconQrCode\Encoder\ByteMatrix $matrix

Returns

int —

chooseVersion()

chooseVersion(int  $numInputBits, \BaconQrCode\Common\ErrorCorrectionLevel  $ecLevel) : \BaconQrCode\Common\Version

Chooses the best version for the input.

Parameters

int $numInputBits
\BaconQrCode\Common\ErrorCorrectionLevel $ecLevel

Throws

\BaconQrCode\Exception\WriterException

if data is too big

Returns

\BaconQrCode\Common\Version —

terminateBits()

terminateBits(int  $numDataBytes, \BaconQrCode\Common\BitArray  $bits) : void

Terminates the bits in a bit array.

Parameters

int $numDataBytes
\BaconQrCode\Common\BitArray $bits

Throws

\BaconQrCode\Exception\WriterException

if data bits cannot fit in the QR code

\BaconQrCode\Exception\WriterException

if bits size does not equal the capacity

getNumDataBytesAndNumEcBytesForBlockId()

getNumDataBytesAndNumEcBytesForBlockId(int  $numTotalBytes, int  $numDataBytes, int  $numRsBlocks, int  $blockId) : int[]

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

Parameters

int $numTotalBytes
int $numDataBytes
int $numRsBlocks
int $blockId

Throws

\BaconQrCode\Exception\WriterException

if block ID is too large

\BaconQrCode\Exception\WriterException

if EC bytes mismatch

\BaconQrCode\Exception\WriterException

if RS blocks mismatch

\BaconQrCode\Exception\WriterException

if total bytes mismatch

Returns

int[] —

interleaveWithEcBytes()

interleaveWithEcBytes(\BaconQrCode\Common\BitArray  $bits, int  $numTotalBytes, int  $numDataBytes, int  $numRsBlocks) : \BaconQrCode\Common\BitArray

Interleaves data with EC bytes.

Parameters

\BaconQrCode\Common\BitArray $bits
int $numTotalBytes
int $numDataBytes
int $numRsBlocks

Throws

\BaconQrCode\Exception\WriterException

if number of bits and data bytes does not match

\BaconQrCode\Exception\WriterException

if data bytes does not match offset

\BaconQrCode\Exception\WriterException

if an interleaving error occurs

Returns

\BaconQrCode\Common\BitArray —

generateEcBytes()

generateEcBytes(\SplFixedArray<int>  $dataBytes, int  $numEcBytesInBlock) : \SplFixedArray<int>

Generates EC bytes for given data.

Parameters

\SplFixedArray $dataBytes
int $numEcBytesInBlock

Returns

\SplFixedArray

getCodec()

getCodec(int  $numDataBytes, int  $numEcBytesInBlock) : \BaconQrCode\Common\ReedSolomonCodec

Gets an RS codec and caches it.

Parameters

int $numDataBytes
int $numEcBytesInBlock

Returns

\BaconQrCode\Common\ReedSolomonCodec —

appendModeInfo()

appendModeInfo(\BaconQrCode\Common\Mode  $mode, \BaconQrCode\Common\BitArray  $bits) : void

Appends mode information to a bit array.

Parameters

\BaconQrCode\Common\Mode $mode
\BaconQrCode\Common\BitArray $bits

appendLengthInfo()

appendLengthInfo(int  $numLetters, \BaconQrCode\Common\Version  $version, \BaconQrCode\Common\Mode  $mode, \BaconQrCode\Common\BitArray  $bits) : void

Appends length information to a bit array.

Parameters

int $numLetters
\BaconQrCode\Common\Version $version
\BaconQrCode\Common\Mode $mode
\BaconQrCode\Common\BitArray $bits

Throws

\BaconQrCode\Exception\WriterException

if num letters is bigger than expected

appendBytes()

appendBytes(string  $content, \BaconQrCode\Common\Mode  $mode, \BaconQrCode\Common\BitArray  $bits, string  $encoding) : void

Appends bytes to a bit array in a specific mode.

Parameters

string $content
\BaconQrCode\Common\Mode $mode
\BaconQrCode\Common\BitArray $bits
string $encoding

Throws

\BaconQrCode\Exception\WriterException

if an invalid mode was supplied

appendNumericBytes()

appendNumericBytes(string  $content, \BaconQrCode\Common\BitArray  $bits) : void

Appends numeric bytes to a bit array.

Parameters

string $content
\BaconQrCode\Common\BitArray $bits

appendAlphanumericBytes()

appendAlphanumericBytes(string  $content, \BaconQrCode\Common\BitArray  $bits) : void

Appends alpha-numeric bytes to a bit array.

Parameters

string $content
\BaconQrCode\Common\BitArray $bits

Throws

\BaconQrCode\Exception\WriterException

if an invalid alphanumeric code was found

append8BitBytes()

append8BitBytes(string  $content, \BaconQrCode\Common\BitArray  $bits, string  $encoding) : void

Appends regular 8-bit bytes to a bit array.

Parameters

string $content
\BaconQrCode\Common\BitArray $bits
string $encoding

Throws

\BaconQrCode\Exception\WriterException

if content cannot be encoded to target encoding

appendKanjiBytes()

appendKanjiBytes(string  $content, \BaconQrCode\Common\BitArray  $bits) : void

Appends KANJI bytes to a bit array.

Parameters

string $content
\BaconQrCode\Common\BitArray $bits

Throws

\BaconQrCode\Exception\WriterException

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

\BaconQrCode\Exception\WriterException

if an invalid byte sequence occurs

appendEci()

appendEci(\BaconQrCode\Common\CharacterSetEci  $eci, \BaconQrCode\Common\BitArray  $bits) : void

Appends ECI information to a bit array.

Parameters

\BaconQrCode\Common\CharacterSetEci $eci
\BaconQrCode\Common\BitArray $bits