QR Code

Advanced encoding and limits

QrSegmentAdvanced.makeSegmentsOptimally() searches numeric, alphanumeric, UTF-8 byte, and Kanji modes to minimize encoded bits within a requested ECL and version range. It is helpful for long mixed Japanese/ASCII data.

import com.ajaxjs.qr_code.QrSegmentAdvanced;
import java.util.List;

List<QrSegment> segments = QrSegmentAdvanced.makeSegmentsOptimally(
        "A-2026 漢字 12345", Ecc.MEDIUM, 1, 20);
QrCode qr = QrCode.encodeSegments(segments, Ecc.MEDIUM, 1, 20, -1, true);
encodeSegments() parameter Meaning
minVersion, maxVersion Allowed versions within 1–40; the smallest fitting version is chosen.
mask -1 evaluates all eight masks and selects the lowest penalty; 07 forces reproducible output.
boostEcl Raises ECL only if this does not require a larger version.

Manual masks and low-level codewords are specialized interoperability/testing features. Prefer automatic masks and high-level methods unless an external format requires otherwise.

Fast encoder

com.ajaxjs.qr_code.fast has parallel classes such as QrCodeFast. They store module/template data compactly and memoize templates and Reed–Solomon generators for repeated workloads. Use the regular API by default: Utils.toImage() and Utils.toSvgString() accept QrCode, not QrCodeFast. Profile before adopting the fast package, render its getModule(x, y) data yourself, and never mix normal and fast segment types.

Failure and security boundaries