API Docs for: undefined
Show:

QrCode.GeneratorBase Class

Extends Base

This class provides utility methods for generating QR Codes.

Constructor

QrCode.GeneratorBase

(
  • config
)

Parameters:

  • config Object

    Configuration object.

Methods

applyMask

(
  • matrix
  • dataMatrix
  • maskFunction
  • quietZoneSize
  • size
  • callbackFunction
)
chainable

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 Function

    A 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 Number

    The size of the quiet zone region.

  • size Number

    The square root of the length of matrix. (dataMatrix and matrix should be the same size.)

  • callbackFunction Function

    This 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
)
chainable

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 Number

    The x coordinate of the center of the alignment pattern.

  • centerY Number

    The y coordinate of the center of the alignment pattern.

  • size Number

    The square root of the length of matrix.

  • overwrite Boolean

    When set to true, the alignment pattern will replace any existing data in the matrix at that location.

drawFinderPattern

(
  • matrix
  • centerX
  • centerY
  • size
  • overwrite
)
chainable

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 Number

    The x coordinate of the center of the finder pattern.

  • centerY Number

    The y coordinate of the center of the finder pattern.

  • size Number

    The square root of the length of matrix.

  • overwrite Boolean

    When set to true, the finder pattern will replace any existing data in the matrix at that location.

drawFormatInformation

(
  • matrix
  • binaryString
  • micro
  • quietZoneSize
  • size
  • overwrite
)
chainable

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 String

    A string conatining 15 '1' or '0' characters.

  • micro Boolean

    Set this to true for a Micro QR Code or false for a QR Code.

  • quietZoneSize Number

    The size of the quiet zone region.

  • size Number

    The square root of the length of matrix.

  • overwrite Boolean

    When set to true, the format information will replace any existing data in the matrix at that location.

drawQuietZone

(
  • matrix
  • quietZoneSize
  • size
  • overwrite
)
chainable

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.

Parameters:

  • matrix [Boolean]

    The array to write to.

  • quietZoneSize Number

    The size of the quiet zone region.

  • size Number

    The square root of the length of matrix.

  • overwrite Boolean

    When set to true, the quiet zone region will replace any existing data in the matrix at that location.

drawTimingPattern

(
  • matrix
  • coordinate
  • size
  • overwrite
)
chainable

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.

Parameters:

  • matrix [Boolean]

    The array to write to.

  • coordinate Number

    The row and column index to write to.

  • size Number

    The square root of the length of matrix.

  • overwrite Boolean

    When set to true, the timing patter will replace any existing data in the matrix at that location.

drawVersionInformation

(
  • matrix
  • binaryString
  • quietZoneSize
  • size
  • overwrite
)
chainable

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 String

    A string conatining 18 '1' or '0' characters.

  • quietZoneSize Number

    The size of the quiet zone region.

  • size Number

    The square root of the length of matrix.

  • overwrite Boolean

    When set to true, the version information will replace any existing data in the matrix at that location.

evaluateMatrix

(
  • matrix
  • quietZoneSize
  • size
  • callbackFunction
)
chainable

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 Number

    The size of the quiet zone region.

  • size Number

    The square root of the length of matrix.

  • callbackFunction Function

    This 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
)
chainable

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 Number

    The size of the quiet zone region.

  • size Number

    The square root of the length of matrix.

  • callbackFunction Function

    This 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
)
chainable

This method formats the given data into the final binary string used to create a data matrix.

Parameters:

  • binaryString String

    A string of '1' and '0' characters.

  • callbackFunction Function

    This 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
)
chainable

Generate a QR Code matrix.

Parameters:

  • callbackFunction Function

    This 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
)
chainable

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 String

    A string of '1' and '0' characters.

  • coordinate Number

    The coordinate of the vertical timing pattern.

  • quietZoneSize Number

    The size of the quiet zone region.

  • size Number

    The square root of the length of matrix.

  • callbackFunction Function

    This 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
)
chainable

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 Number

    The number of 8 bit codewords to generate in the error correction block.

  • callbackFunction Function

    This 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
)
chainable

Generates a matrix which represents the given data.

Parameters:

  • binaryString String

    A string of '1' and '0' characters.

  • callbackFunction Function

    This 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
)
[x, y]

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 Number

    The size of the quiet zone region.

Returns:

[x, y]:

getBinaryString

(
  • callbackFunction
)
chainable

Converts the value of the data attribute to a string of '1' and '0' characters.

Parameters:

  • callbackFunction Function

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

getSize

() Number

Returns the proper size of a matrix for this version.

Returns:

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 EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.

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 EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.

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 EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.

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 EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.