* Represents an immutable square grid of black and white cells for a QR Code symbol, and * provides static functions to create a QR Code from user-supplied textual or binary data. * This class covers the QR Code model 2 specification, supporting all versions (sizes) * from 1 to 40, all 4 error correction levels, and only 3 character encoding modes. */
| 39 | * from 1 to 40, all 4 error correction levels, and only 3 character encoding modes. |
| 40 | */ |
| 41 | class QrCode { |
| 42 | |
| 43 | /*---- Public helper enumeration ----*/ |
| 44 | public: |
| 45 | |
| 46 | /* |
| 47 | * Represents the error correction level used in a QR Code symbol. |
| 48 | */ |
| 49 | class Ecc { |
| 50 | // Constants declared in ascending order of error protection. |
| 51 | public: |
| 52 | const static Ecc LOW, MEDIUM, QUARTILE, HIGH; |
| 53 | |
| 54 | // Fields. |
| 55 | public: |
| 56 | const int ordinal; // (Public) In the range 0 to 3 (unsigned 2-bit integer). |
| 57 | const int formatBits; // (Package-private) In the range 0 to 3 (unsigned 2-bit integer). |
| 58 | |
| 59 | // Constructor. |
| 60 | private: |
| 61 | Ecc(int ord, int fb); |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | |
| 66 | /*---- Public static factory functions ----*/ |
| 67 | public: |
| 68 | |
| 69 | /* |
| 70 | * Returns a QR Code symbol representing the given Unicode text string at the given error correction level. |
| 71 | * As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer Unicode |
| 72 | * code points (not UTF-16 code units). The smallest possible QR Code version is automatically chosen for the output. |
| 73 | * The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version. |
| 74 | */ |
| 75 | static QrCode encodeText(const char *text, int version, const Ecc &ecl); |
| 76 | |
| 77 | |
| 78 | /* |
| 79 | * Returns a QR Code symbol representing the given binary data string at the given error correction level. |
| 80 | * This function always encodes using the binary segment mode, not any text mode. The maximum number of |
| 81 | * bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output. |
| 82 | * The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version. |
| 83 | */ |
| 84 | static QrCode encodeBinary(const std::vector<uint8_t> &data, const Ecc &ecl); |
| 85 | |
| 86 | |
| 87 | /* |
| 88 | * Returns a QR Code symbol representing the given data segments with the given encoding parameters. |
| 89 | * The smallest possible QR Code version within the given range is automatically chosen for the output. |
| 90 | * This function allows the user to create a custom sequence of segments that switches |
| 91 | * between modes (such as alphanumeric and binary) to encode text more efficiently. |
| 92 | * This function is considered to be lower level than simply encoding text or binary data. |
| 93 | */ |
| 94 | static QrCode encodeSegments(const std::vector<QrSegment> &segs, const Ecc &ecl, |
| 95 | int minVersion=1, int maxVersion=40, int mask=-1, bool boostEcl=true); // All optional parameters |
| 96 | |
| 97 | |
| 98 |