Updated up to 8 comments in all language versions, but somewhat differently in each language.

pull/39/merge
Project Nayuki 6 years ago
parent b9f69cf7bd
commit 3ead3dbb84

@ -494,8 +494,8 @@ static void drawCodewords(const uint8_t data[], int dataLen, uint8_t qrcode[]) {
setModule(qrcode, x, y, black); setModule(qrcode, x, y, black);
i++; i++;
} }
// If there are any remainder bits (0 to 7), they are already // If this QR Code has any remainder bits (0 to 7), they were assigned as
// set to 0/false/white when the grid of modules was initialized // 0/false/white by the constructor and are left unchanged by this method
} }
} }
} }

@ -73,10 +73,8 @@ enum qrcodegen_Mode {
/* /*
* A segment of user/application data that a QR Code symbol can convey. * Represents a segment of character data, binary data, or control data. The maximum allowed
* Each segment has a mode, a character count, and character/general data that is * bit length is 32767, because even the largest QR Code (version 40) has only 31329 modules.
* already encoded as a sequence of bits. The maximum allowed bit length is 32767,
* because even the largest QR Code (version 40) has only 31329 modules.
*/ */
struct qrcodegen_Segment { struct qrcodegen_Segment {
// The mode indicator for this segment. // The mode indicator for this segment.
@ -219,9 +217,10 @@ struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]);
/* /*
* Renders a QR Code symbol representing the given data segments at the given error correction * Renders a QR Code symbol representing the given segments at the given error correction level.
* level or higher. The smallest possible QR Code version is automatically chosen for the output. * The smallest possible QR Code version is automatically chosen for the output. Returns true if
* Returns true if QR Code creation succeeded, or false if the data is too long to fit in any version. * QR Code creation succeeded, or false if the data is too long to fit in any version. The ECC level
* of the result may be higher than the ecl argument if it can be done without increasing the version.
* This function allows the user to create a custom sequence of segments that switches * This function allows the user to create a custom sequence of segments that switches
* between modes (such as alphanumeric and binary) to encode text more efficiently. * between modes (such as alphanumeric and binary) to encode text more efficiently.
* This function is considered to be lower level than simply encoding text or binary data. * This function is considered to be lower level than simply encoding text or binary data.
@ -234,7 +233,7 @@ bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len,
/* /*
* Renders a QR Code symbol representing the given data segments with the given encoding parameters. * Renders a QR Code symbol representing the given segments with the given encoding parameters.
* Returns true if QR Code creation succeeded, or false if the data is too long to fit in the range of versions. * Returns true if QR Code creation succeeded, or false if the data is too long to fit in the range of versions.
* The smallest possible QR Code version within the given range is automatically chosen for the output. * The smallest possible QR Code version within the given range is automatically chosen for the output.
* This function allows the user to create a custom sequence of segments that switches * This function allows the user to create a custom sequence of segments that switches

@ -360,8 +360,8 @@ void QrCode::drawCodewords(const vector<uint8_t> &data) {
modules.at(y).at(x) = getBit(data.at(i >> 3), 7 - static_cast<int>(i & 7)); modules.at(y).at(x) = getBit(data.at(i >> 3), 7 - static_cast<int>(i & 7));
i++; i++;
} }
// If there are any remainder bits (0 to 7), they are already // If this QR Code has any remainder bits (0 to 7), they were assigned as
// set to 0/false/white when the grid of modules was initialized // 0/false/white by the constructor and are left unchanged by this method
} }
} }
} }

@ -77,7 +77,7 @@ class QrCode final {
/* /*
* Returns a QR Code symbol representing the given data segments with the given encoding parameters. * Returns a QR Code symbol representing the given segments with the given encoding parameters.
* The smallest possible QR Code version within the given range is automatically chosen for the output. * The smallest possible QR Code version within the given range is automatically chosen for the output.
* This function allows the user to create a custom sequence of segments that switches * This function allows the user to create a custom sequence of segments that switches
* between modes (such as alphanumeric and binary) to encode text more efficiently. * between modes (such as alphanumeric and binary) to encode text more efficiently.
@ -154,9 +154,8 @@ class QrCode final {
/* /*
* Based on the given number of border modules to add as padding, this returns a * Returns a string of SVG XML code representing an image of this QR Code symbol with the given
* string whose contents represents an SVG XML file that depicts this QR Code symbol. * number of border modules. Note that Unix newlines (\n) are always used, regardless of the platform.
* Note that Unix newlines (\n) are always used, regardless of the platform.
*/ */
public: std::string toSvgString(int border) const; public: std::string toSvgString(int border) const;

@ -31,9 +31,8 @@
namespace qrcodegen { namespace qrcodegen {
/* /*
* Represents a character string to be encoded in a QR Code symbol. Each segment has * Represents a segment of character data, binary data, or control data
* a mode, and a sequence of characters that is already encoded as a sequence of bits. * to be put into a QR Code symbol. Instances of this class are immutable.
* Instances of this class are immutable.
* This segment class imposes no length restrictions, but QR Codes have restrictions. * This segment class imposes no length restrictions, but QR Codes have restrictions.
* Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
* Any segment longer than this is meaningless for the purpose of generating QR Codes. * Any segment longer than this is meaningless for the purpose of generating QR Codes.
@ -58,8 +57,10 @@ class QrSegment final {
/*-- Fields --*/ /*-- Fields --*/
// The mode indicator bits, which is a uint4 value (range 0 to 15).
private: int modeBits; private: int modeBits;
// Three values for different version ranges.
private: int numBitsCharCount[3]; private: int numBitsCharCount[3];
@ -150,7 +151,7 @@ class QrSegment final {
/*---- Constructors ----*/ /*---- Constructors ----*/
/* /*
* Creates a new QR Code data segment with the given parameters and data. * Creates a new QR Code segment with the given parameters and data.
*/ */
public: QrSegment(Mode md, int numCh, const std::vector<bool> &dt); public: QrSegment(Mode md, int numCh, const std::vector<bool> &dt);

@ -81,8 +81,9 @@ public final class QrCode {
/** /**
* Returns a QR Code symbol representing the specified data segments at the specified error correction * Returns a QR Code symbol representing the specified segments at the specified error correction
* level or higher. The smallest possible QR Code version is automatically chosen for the output. * level. The smallest possible QR Code version is automatically chosen for the output. The ECC level
* of the result may be higher than the ecl argument if it can be done without increasing the version.
* <p>This function allows the user to create a custom sequence of segments that switches * <p>This function allows the user to create a custom sequence of segments that switches
* between modes (such as alphanumeric and binary) to encode text more efficiently. * between modes (such as alphanumeric and binary) to encode text more efficiently.
* This function is considered to be lower level than simply encoding text or binary data.</p> * This function is considered to be lower level than simply encoding text or binary data.</p>
@ -99,7 +100,7 @@ public final class QrCode {
/** /**
* Returns a QR Code symbol representing the specified data segments with the specified encoding parameters. * Returns a QR Code symbol representing the specified segments with the specified encoding parameters.
* The smallest possible QR Code version within the specified range is automatically chosen for the output. * The smallest possible QR Code version within the specified range is automatically chosen for the output.
* <p>This function allows the user to create a custom sequence of segments that switches * <p>This function allows the user to create a custom sequence of segments that switches
* between modes (such as alphanumeric and binary) to encode text more efficiently. * between modes (such as alphanumeric and binary) to encode text more efficiently.
@ -279,9 +280,8 @@ public final class QrCode {
/** /**
* Based on the specified number of border modules to add as padding, this returns a * Returns a string of SVG XML code representing an image of this QR Code symbol with the specified
* string whose contents represents an SVG XML file that depicts this QR Code symbol. * number of border modules. Note that Unix newlines (\n) are always used, regardless of the platform.
* Note that Unix newlines (\n) are always used, regardless of the platform.
* @param border the number of border modules to add, which must be non-negative * @param border the number of border modules to add, which must be non-negative
* @return a string representing this QR Code as an SVG document * @return a string representing this QR Code as an SVG document
* @throws IllegalArgumentException if the border is negative * @throws IllegalArgumentException if the border is negative
@ -495,8 +495,8 @@ public final class QrCode {
modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7)); modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
i++; i++;
} }
// If there are any remainder bits (0 to 7), they are already // If this QR Code has any remainder bits (0 to 7), they were assigned as
// set to 0/false/white when the grid of modules was initialized // 0/false/white by the constructor and are left unchanged by this method
} }
} }
} }

@ -31,9 +31,8 @@ import java.util.regex.Pattern;
/** /**
* Represents a character string to be encoded in a QR Code symbol. Each segment has * Represents a segment of character data, binary data, or control data
* a mode, and a sequence of characters that is already encoded as a sequence of bits. * to be put into a QR Code symbol. Instances of this class are immutable.
* Instances of this class are immutable.
* <p>This segment class imposes no length restrictions, but QR Codes have restrictions. * <p>This segment class imposes no length restrictions, but QR Codes have restrictions.
* Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
* Any segment longer than this is meaningless for the purpose of generating QR Codes.</p> * Any segment longer than this is meaningless for the purpose of generating QR Codes.</p>
@ -169,7 +168,7 @@ public final class QrSegment {
/*---- Constructor ----*/ /*---- Constructor ----*/
/** /**
* Constructs a QR Code data segment with the specified parameters and data. * Constructs a QR Code segment with the specified parameters and data.
* @param md the mode, which is not {@code null} * @param md the mode, which is not {@code null}
* @param numCh the data length in characters, which is non-negative * @param numCh the data length in characters, which is non-negative
* @param data the data bits of this segment, which is not {@code null} * @param data the data bits of this segment, which is not {@code null}
@ -247,9 +246,10 @@ public final class QrSegment {
/*-- Fields --*/ /*-- Fields --*/
/** An unsigned 4-bit integer value (range 0 to 15) representing the mode indicator bits for this mode object. */ /** The mode indicator bits, which is a uint4 value (range 0 to 15). */
final int modeBits; final int modeBits;
/** Three values for different version ranges. */
private final int[] numBitsCharCount; private final int[] numBitsCharCount;

@ -164,9 +164,8 @@ var qrcodegen = new function() {
} }
}; };
// Based on the given number of border modules to add as padding, this returns a // Returns a string of SVG XML code representing an image of this QR Code symbol with the given
// string whose contents represents an SVG XML file that depicts this QR Code symbol. // number of border modules. Note that Unix newlines (\n) are always used, regardless of the platform.
// Note that Unix newlines (\n) are always used, regardless of the platform.
this.toSvgString = function(border) { this.toSvgString = function(border) {
if (border < 0) if (border < 0)
throw "Border must be non-negative"; throw "Border must be non-negative";
@ -370,8 +369,8 @@ var qrcodegen = new function() {
modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7)); modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
i++; i++;
} }
// If there are any remainder bits (0 to 7), they are already // If this QR Code has any remainder bits (0 to 7), they were assigned as
// set to 0/false/white when the grid of modules was initialized // 0/false/white by the constructor and are left unchanged by this method
} }
} }
} }
@ -541,7 +540,7 @@ var qrcodegen = new function() {
/* /*
* Returns a QR Code symbol representing the given data segments with the given encoding parameters. * Returns a QR Code symbol representing the given segments with the given encoding parameters.
* The smallest possible QR Code version within the given range is automatically chosen for the output. * The smallest possible QR Code version within the given range is automatically chosen for the output.
* This function allows the user to create a custom sequence of segments that switches * This function allows the user to create a custom sequence of segments that switches
* between modes (such as alphanumeric and binary) to encode text more efficiently. * between modes (such as alphanumeric and binary) to encode text more efficiently.
@ -697,9 +696,8 @@ var qrcodegen = new function() {
/*---- Data segment class ----*/ /*---- Data segment class ----*/
/* /*
* A public class that represents a character string to be encoded in a QR Code symbol. * Represents a segment of character data, binary data, or control data
* Each segment has a mode, and a sequence of characters that is already encoded as * to be put into a QR Code symbol. Instances of this class are immutable.
* a sequence of bits. Instances of this class are immutable.
* This segment class imposes no length restrictions, but QR Codes have restrictions. * This segment class imposes no length restrictions, but QR Codes have restrictions.
* Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
* Any segment longer than this is meaningless for the purpose of generating QR Codes. * Any segment longer than this is meaningless for the purpose of generating QR Codes.
@ -856,7 +854,7 @@ var qrcodegen = new function() {
// Private constructor. // Private constructor.
function Mode(mode, ccbits) { function Mode(mode, ccbits) {
// (Package-private) An unsigned 4-bit integer value (range 0 to 15) representing the mode indicator bits for this mode object. // (Package-private) The mode indicator bits, which is a uint4 value (range 0 to 15).
Object.defineProperty(this, "modeBits", {value:mode}); Object.defineProperty(this, "modeBits", {value:mode});
// (Package-private) Returns the bit width of the segment character count field for this mode object at the given version number. // (Package-private) Returns the bit width of the segment character count field for this mode object at the given version number.

@ -90,7 +90,7 @@ class QrCode(object):
@staticmethod @staticmethod
def encode_segments(segs, ecl, minversion=1, maxversion=40, mask=-1, boostecl=True): def encode_segments(segs, ecl, minversion=1, maxversion=40, mask=-1, boostecl=True):
"""Returns a QR Code symbol representing the given data segments with the given encoding parameters. """Returns a QR Code symbol representing the given segments with the given encoding parameters.
The smallest possible QR Code version within the given range is automatically chosen for the output. The smallest possible QR Code version within the given range is automatically chosen for the output.
This function allows the user to create a custom sequence of segments that switches This function allows the user to create a custom sequence of segments that switches
between modes (such as alphanumeric and binary) to encode text more efficiently. between modes (such as alphanumeric and binary) to encode text more efficiently.
@ -223,8 +223,8 @@ class QrCode(object):
# ---- Public instance methods ---- # ---- Public instance methods ----
def to_svg_str(self, border): def to_svg_str(self, border):
"""Based on the given number of border modules to add as padding, this returns a """Returns a string of SVG XML code representing an image of this QR Code symbol with the given
string whose contents represents an SVG XML file that depicts this QR Code symbol.""" number of border modules. Note that Unix newlines (\n) are always used, regardless of the platform."""
if border < 0: if border < 0:
raise ValueError("Border must be non-negative") raise ValueError("Border must be non-negative")
parts = [] parts = []
@ -403,8 +403,8 @@ class QrCode(object):
if not self._isfunction[y][x] and i < len(data) * 8: if not self._isfunction[y][x] and i < len(data) * 8:
self._modules[y][x] = _get_bit(data[i >> 3], 7 - (i & 7)) self._modules[y][x] = _get_bit(data[i >> 3], 7 - (i & 7))
i += 1 i += 1
# If there are any remainder bits (0 to 7), they are already # If this QR Code has any remainder bits (0 to 7), they were assigned as
# set to 0/false/white when the grid of modules was initialized # 0/false/white by the constructor and are left unchanged by this method
assert i == len(data) * 8 assert i == len(data) * 8
@ -583,9 +583,8 @@ class QrCode(object):
# ---- Data segment class ---- # ---- Data segment class ----
class QrSegment(object): class QrSegment(object):
"""Represents a character string to be encoded in a QR Code symbol. Each segment has """Represents a segment of character data, binary data, or control data
a mode, and a sequence of characters that is already encoded as a sequence of bits. to be put into a QR Code symbol. Instances of this class are immutable.
Instances of this class are immutable.
This segment class imposes no length restrictions, but QR Codes have restrictions. This segment class imposes no length restrictions, but QR Codes have restrictions.
Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
Any segment longer than this is meaningless for the purpose of generating QR Codes.""" Any segment longer than this is meaningless for the purpose of generating QR Codes."""
@ -676,6 +675,7 @@ class QrSegment(object):
# ---- Constructor ---- # ---- Constructor ----
def __init__(self, mode, numch, bitdata): def __init__(self, mode, numch, bitdata):
"""Creates a new QR Code segment with the given parameters and data."""
if numch < 0 or not isinstance(mode, QrSegment.Mode): if numch < 0 or not isinstance(mode, QrSegment.Mode):
raise ValueError() raise ValueError()
self._mode = mode self._mode = mode
@ -729,8 +729,8 @@ class QrSegment(object):
# Private constructor # Private constructor
def __init__(self, modebits, charcounts): def __init__(self, modebits, charcounts):
self._modebits = modebits self._modebits = modebits # The mode indicator bits, which is a uint4 value (range 0 to 15)
self._charcounts = charcounts self._charcounts = charcounts # Three values for different version ranges
# Package-private method # Package-private method
def get_mode_bits(self): def get_mode_bits(self):

@ -82,8 +82,9 @@ impl QrCode {
} }
// Returns a QR Code symbol representing the given data segments at the given error correction // Returns a QR Code symbol representing the given segments at the given error correction level.
// level or higher. The smallest possible QR Code version is automatically chosen for the output. // The smallest possible QR Code version is automatically chosen for the output. The ECC level
// of the result may be higher than the ecl argument if it can be done without increasing the version.
// This function allows the user to create a custom sequence of segments that switches // This function allows the user to create a custom sequence of segments that switches
// between modes (such as alphanumeric and binary) to encode text more efficiently. // between modes (such as alphanumeric and binary) to encode text more efficiently.
// This function is considered to be lower level than simply encoding text or binary data. // This function is considered to be lower level than simply encoding text or binary data.
@ -93,7 +94,7 @@ impl QrCode {
} }
// Returns a QR Code symbol representing the given data segments with the given encoding parameters. // Returns a QR Code symbol representing the given segments with the given encoding parameters.
// The smallest possible QR Code version within the given range is automatically chosen for the output. // The smallest possible QR Code version within the given range is automatically chosen for the output.
// This function allows the user to create a custom sequence of segments that switches // This function allows the user to create a custom sequence of segments that switches
// between modes (such as alphanumeric and binary) to encode text more efficiently. // between modes (such as alphanumeric and binary) to encode text more efficiently.
@ -239,9 +240,8 @@ impl QrCode {
} }
// Based on the given number of border modules to add as padding, this returns a // Returns a string of SVG XML code representing an image of this QR Code symbol with the given
// string whose contents represents an SVG XML file that depicts this QR Code symbol. // number of border modules. Note that Unix newlines (\n) are always used, regardless of the platform.
// Note that Unix newlines (\n) are always used, regardless of the platform.
pub fn to_svg_string(&self, border: i32) -> String { pub fn to_svg_string(&self, border: i32) -> String {
assert!(border >= 0, "Border must be non-negative"); assert!(border >= 0, "Border must be non-negative");
let mut result = String::new(); let mut result = String::new();
@ -468,8 +468,8 @@ impl QrCode {
*self.module_mut(x, y) = get_bit(data[i >> 3] as u32, 7 - ((i & 7) as i32)); *self.module_mut(x, y) = get_bit(data[i >> 3] as u32, 7 - ((i & 7) as i32));
i += 1; i += 1;
} }
// If there are any remainder bits (0 to 7), they are already // If this QR Code has any remainder bits (0 to 7), they were assigned as
// set to 0/false/white when the grid of modules was initialized // 0/false/white by the constructor and are left unchanged by this method
} }
} }
right -= 2; right -= 2;
@ -826,9 +826,8 @@ impl ReedSolomonGenerator {
/*---- QrSegment functionality ----*/ /*---- QrSegment functionality ----*/
// Represents a character string to be encoded in a QR Code symbol. // Represents a segment of character data, binary data, or control data
// Each segment has a mode, and a sequence of characters that is already // to be put into a QR Code symbol. Instances of this class are immutable.
// encoded as a sequence of bits. Instances of this struct are immutable.
pub struct QrSegment { pub struct QrSegment {
// The mode indicator for this segment. // The mode indicator for this segment.
@ -942,7 +941,7 @@ impl QrSegment {
} }
// Creates a new QR Code data segment with the given parameters and data. // Creates a new QR Code segment with the given parameters and data.
pub fn new(mode: QrSegmentMode, numchars: usize, data: Vec<bool>) -> Self { pub fn new(mode: QrSegmentMode, numchars: usize, data: Vec<bool>) -> Self {
Self { Self {
mode: mode, mode: mode,

@ -67,7 +67,7 @@ namespace qrcodegen {
} }
// Returns a QR Code symbol representing the given data segments with the given encoding parameters. // Returns a QR Code symbol representing the given segments with the given encoding parameters.
// The smallest possible QR Code version within the given range is automatically chosen for the output. // The smallest possible QR Code version within the given range is automatically chosen for the output.
// This function allows the user to create a custom sequence of segments that switches // This function allows the user to create a custom sequence of segments that switches
// between modes (such as alphanumeric and binary) to encode text more efficiently. // between modes (such as alphanumeric and binary) to encode text more efficiently.
@ -231,9 +231,8 @@ namespace qrcodegen {
} }
// Based on the given number of border modules to add as padding, this returns a // Returns a string of SVG XML code representing an image of this QR Code symbol with the given
// string whose contents represents an SVG XML file that depicts this QR Code symbol. // number of border modules. Note that Unix newlines (\n) are always used, regardless of the platform.
// Note that Unix newlines (\n) are always used, regardless of the platform.
public toSvgString(border: int): string { public toSvgString(border: int): string {
if (border < 0) if (border < 0)
throw "Border must be non-negative"; throw "Border must be non-negative";
@ -439,8 +438,8 @@ namespace qrcodegen {
this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7)); this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
i++; i++;
} }
// If there are any remainder bits (0 to 7), they are already // If this QR Code has any remainder bits (0 to 7), they were assigned as
// set to 0/false/white when the grid of modules was initialized // 0/false/white by the constructor and are left unchanged by this method
} }
} }
} }
@ -650,9 +649,8 @@ namespace qrcodegen {
/*---- Data segment class ----*/ /*---- Data segment class ----*/
/* /*
* A public class that represents a character string to be encoded in a QR Code symbol. * Represents a segment of character data, binary data, or control data
* Each segment has a mode, and a sequence of characters that is already encoded as * to be put into a QR Code symbol. Instances of this class are immutable.
* a sequence of bits. Instances of this class are immutable.
* This segment class imposes no length restrictions, but QR Codes have restrictions. * This segment class imposes no length restrictions, but QR Codes have restrictions.
* Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
* Any segment longer than this is meaningless for the purpose of generating QR Codes. * Any segment longer than this is meaningless for the purpose of generating QR Codes.
@ -750,6 +748,7 @@ namespace qrcodegen {
/*-- Constructor --*/ /*-- Constructor --*/
// Creates a new QR Code segment with the given parameters and data.
public constructor(mode: QrSegment.Mode, numChars: int, bitData: Array<bit>) { public constructor(mode: QrSegment.Mode, numChars: int, bitData: Array<bit>) {
if (numChars < 0) if (numChars < 0)
throw "Invalid argument"; throw "Invalid argument";
@ -987,9 +986,10 @@ namespace qrcodegen.QrSegment {
/*-- Fields --*/ /*-- Fields --*/
// An unsigned 4-bit integer value (range 0 to 15) representing the mode indicator bits for this mode object. // The mode indicator bits, which is a uint4 value (range 0 to 15).
public readonly modeBits: int; public readonly modeBits: int;
// Three values for different version ranges.
private readonly numBitsCharCount: [int,int,int]; private readonly numBitsCharCount: [int,int,int];

Loading…
Cancel
Save