QrCode.GeneratorBase Class
This class provides utility methods for generating QR Codes.
Constructor
Item Index
Methods
- applyMask
- drawAlignmentPattern
- drawFinderPattern
- drawFormatInformation
- drawQuietZone
- drawTimingPattern
- drawVersionInformation
- evaluateMatrix
- evaluateMicroMatrix
- formatBinaryString
- generate
- generateDataMatrix
- generateErrorCorrectionBlock
- generateMatrix
- getAlignmentPatternCoordinates
- getBinaryString
- getSize
Attributes
Methods
applyMask
-
matrix
-
dataMatrix
-
maskFunction
-
quietZoneSize
-
size
-
callbackFunction
Performs a mask operation that inverts some data bits. QR Codes apply one of eight possible masks to the raw data matrix. Decoders benefit when a mask is used to reduce the occurence of ambiguous patterns within the data matrix.
Parameters:
-
matrix
[Boolean]The array to write the results to. Existing data will be overwritten.
-
dataMatrix
[Boolean]An array with the source data. Non-data elements should be undefined.
-
maskFunction
FunctionA function that accepts x and y coordinates and returns true or false. The x and y coordinates passed to the mask function do not account for the quiet zone region. When the mask function returns true, the data at that position is inverted.
-
quietZoneSize
NumberThe size of the quiet zone region.
-
size
NumberThe square root of the length of matrix. (dataMatrix and matrix should be the same size.)
-
callbackFunction
FunctionThis function will be called once the mask has been applied. It is guaranteed to be called in a future turn of the event loop. The modified matrix will be passed as the only argument.
drawAlignmentPattern
-
matrix
-
centerX
-
centerY
-
size
-
overwrite
Alignment patterns are distinct patterns used to help decoders overcome distortion and perspective when viewing a QR Code. They are made up of a 5x5 square of dark values surrounding a 3x3 square of light values surrounding a single dark value.
Parameters:
-
matrix
[Boolean]The array to write to.
-
centerX
NumberThe x coordinate of the center of the alignment pattern.
-
centerY
NumberThe y coordinate of the center of the alignment pattern.
-
size
NumberThe square root of the length of matrix.
-
overwrite
BooleanWhen set to true, the alignment pattern will replace any existing data in the matrix at that location.
drawFinderPattern
-
matrix
-
centerX
-
centerY
-
size
-
overwrite
Finder patterns are distinct patterns placed in three corners of a QR code. Finder patterns help decoders determine position, scale, and orientation. They are made up of a 9x9 square of light values surrounding a 7x7 square of dark values surrounding a 5x5 square of light values surrounding a 3x3 square filled with dark values.
Parameters:
-
matrix
[Boolean]The array to write to.
-
centerX
NumberThe x coordinate of the center of the finder pattern.
-
centerY
NumberThe y coordinate of the center of the finder pattern.
-
size
NumberThe square root of the length of matrix.
-
overwrite
BooleanWhen set to true, the finder pattern will replace any existing data in the matrix at that location.
drawFormatInformation
-
matrix
-
binaryString
-
micro
-
quietZoneSize
-
size
-
overwrite
The error correction level and the id of the mask that has been applied to the data matrix are encoded together as a 5 bit value. This value gets 10 error correction bits appended to it, created by a (15, 5) BCH code. The final 15 bit format information codeword has specific locations reserved for it within the matrix. QR Codes contain the format information twice for additional redundancy.
Parameters:
-
matrix
[Boolean]The array to write to.
-
binaryString
StringA string conatining 15 '1' or '0' characters.
-
micro
BooleanSet this to true for a Micro QR Code or false for a QR Code.
-
quietZoneSize
NumberThe size of the quiet zone region.
-
size
NumberThe square root of the length of matrix.
-
overwrite
BooleanWhen set to true, the format information will replace any existing data in the matrix at that location.
drawQuietZone
-
matrix
-
quietZoneSize
-
size
-
overwrite
The quiet zone region is a padding of light values around the outside of a QR Code. It helps separate the QR Code from other visual elements.
drawTimingPattern
-
matrix
-
coordinate
-
size
-
overwrite
The timing pattern is a row and column of alternating dark and light values. The timing pattern allows decoders to determine the version of the QR Code as well as the pixel density and coordinate system.
drawVersionInformation
-
matrix
-
binaryString
-
quietZoneSize
-
size
-
overwrite
QR Codes version 7 and higher contain the version number as a 6 bit value. This value gets 12 error correction bits appended to it, created by an (18, 6) Golay code. The final 18 bit version information codeword has specific locations reserved for it within the matrix. QR Codes contain the version information twice for additional redundancy.
Parameters:
-
matrix
[Boolean]The array to write to.
-
binaryString
StringA string conatining 18 '1' or '0' characters.
-
quietZoneSize
NumberThe size of the quiet zone region.
-
size
NumberThe square root of the length of matrix.
-
overwrite
BooleanWhen set to true, the version information will replace any existing data in the matrix at that location.
evaluateMatrix
-
matrix
-
quietZoneSize
-
size
-
callbackFunction
Several potential matrices are generated during the masking process. This method searches a matrix for negative features and generates a penalty score. This score is used to determine which matrix to keep.
Parameters:
-
matrix
[Boolean]The array to examine.
-
quietZoneSize
NumberThe size of the quiet zone region.
-
size
NumberThe square root of the length of matrix.
-
callbackFunction
FunctionThis function will be called once the matrix has been evaluated. It is guaranteed to be called in a future turn of the event loop. The score will be passed as the only argument.
evaluateMicroMatrix
-
matrix
-
quietZoneSize
-
size
-
callbackFunction
Several potential matrices are generated during the masking process. This method searches for dark values along the non timing pattern edges. Dark values along these edges make it easier for decoders to determine the difference between data and the quiet zone region. The matrix is given a score used to determine which matrix to keep.
Parameters:
-
matrix
[Boolean]The array to examine.
-
quietZoneSize
NumberThe size of the quiet zone region.
-
size
NumberThe square root of the length of matrix.
-
callbackFunction
FunctionThis function will be called once the matrix has been evaluated. It is guaranteed to be called in a future turn of the event loop. The score will be passed as the only argument.
formatBinaryString
-
binaryString
-
callbackFunction
This method formats the given data into the final binary string used to create a data matrix.
Parameters:
-
binaryString
StringA string of '1' and '0' characters.
-
callbackFunction
FunctionThis function will be called once the binary string has been formated. It is guaranteed to be called in a future turn of the event loop. If an error occurs, the error message will be passed as the first argument. The formatted binary string is passed as the second argument.
generate
-
callbackFunction
Generate a QR Code matrix.
Parameters:
-
callbackFunction
FunctionThis function will be called once the matrix has been generated. It is guaranteed to be called in a future turn of the event loop. If an error occurs, the error message will be passed as the first argument. The matrix is passed as the second argument. The square root of the length of the matrix is passed as the third argument.
generateDataMatrix
-
matrix
-
binaryString
-
coordinate
-
quietZoneSize
-
size
-
callbackFunction
This method creates a new matrix containing only raw data bits.
Parameters:
-
matrix
[Boolean]An array without any data bits defined. This matrix is only used to position data bits around other features that are already present. This matrix is not modified.
-
binaryString
StringA string of '1' and '0' characters.
-
coordinate
NumberThe coordinate of the vertical timing pattern.
-
quietZoneSize
NumberThe size of the quiet zone region.
-
size
NumberThe square root of the length of matrix.
-
callbackFunction
FunctionThis function will be called once the dataMatrix has been generated. It is guaranteed to be called in a future turn of the event loop. The dataMatrix is passed as the only argument.
generateErrorCorrectionBlock
-
dataBlock
-
errorCorrectionBlockLength
-
callbackFunction
Generates a block of error correction codewords based on a block of data codewords.
Parameters:
-
dataBlock
[String]Array of strings of '1' and '0' characters, 8 characters long each.
-
errorCorrectionBlockLength
NumberThe number of 8 bit codewords to generate in the error correction block.
-
callbackFunction
FunctionThis function will be called once the error correction block has been generated. It is guaranteed to be called in a future turn of the event loop. The error correction block is passed as the only argument.
generateMatrix
-
binaryString
-
callbackFunction
Generates a matrix which represents the given data.
Parameters:
-
binaryString
StringA string of '1' and '0' characters.
-
callbackFunction
FunctionThis function will be called once the matrix has been generated. It is guaranteed to be called in a future turn of the event loop. The matrix is passed as the first argument. The square root of the length of the matrix is passed as the second argument.
getAlignmentPatternCoordinates
-
quietZoneSize
Each QR Code version has specific requirements for the position of alignment patterns. This method returns the center position of each required alignment pattern.
Parameters:
-
quietZoneSize
NumberThe size of the quiet zone region.
Returns:
getBinaryString
-
callbackFunction
Converts the value of the data attribute to a string of '1' and '0' characters.
Parameters:
-
callbackFunction
FunctionThis function will be called once the binary string has been created. It is guaranteed to be called in a future turn of the event loop. The binary string is passed as the only argument.
Attributes
data
Array
Input data must be wrapped up in data objects. A single data object or an array is acceptable. Data objects are responsible for encoding raw values into one of the data encoding modes supported by QR codes.
Default: []
Fires event dataChange
Fires when the value for the configuration attribute data
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
errorCorrection
String
QR Codes use error correction when encoding data. Error correction allows a code to be successfully scanned even if part of the code is damaged, missing, or scanned incorrectly. There are four different error correction modes. Mode H can recover from 30% data loss. Mode L can recover from 7% data loss. Mode M can recover from 15% data loss. Mode Q can recover from 25% data loss. The more error correction added, the less data the QR Code can hold.
Default: 'M',
Fires event errorCorrectionChange
Fires when the value for the configuration attribute errorCorrection
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
mask
Number
QR Codes apply one of eight possible masks to the raw data matrix. Decoders benefit when a mask is used to reduce the occurence of ambiguous patterns within the data matrix. When this attribute is set to null, the data matrix will be have all 8 masks applied to it. Each one will be evaluated and the one with the fewest ambiguous patterns will be used. When this attribute is set to a value from 0 to 7, only that specific mask will be applied and used. This improves the performace of the encoding process by cutting out a complex step but manually selecting a mask is not recommended because it can negatively affect decoder performance and/or accuracy. Using different masks on the same data can result in QR Codes that appear very different, so some choose to select a mask for aesthetic reasons.
Default: null
Fires event maskChange
Fires when the value for the configuration attribute mask
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
version
String
There are 40 different versions of QR Codes. A QR Code's version is just a confusing way to specify how big it is. A version 1 QR Code is a 25x25 grid. That size increases by 4 up to the 181x181 grid of a version 40 QR code. The larger the grid, the more data the QR Code can hold.
Default: '1'
Fires event versionChange
Fires when the value for the configuration attribute version
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added: