xref: /third_party/qrcodegen/Readme.markdown (revision 5317bbaf)
15317bbafSopenharmony_ciQR Code generator library
25317bbafSopenharmony_ci=========================
35317bbafSopenharmony_ci
45317bbafSopenharmony_ci
55317bbafSopenharmony_ciIntroduction
65317bbafSopenharmony_ci------------
75317bbafSopenharmony_ci
85317bbafSopenharmony_ciThis project aims to be the best, clearest QR Code generator library in multiple languages. The primary goals are flexible options and absolute correctness. Secondary goals are compact implementation size and good documentation comments.
95317bbafSopenharmony_ci
105317bbafSopenharmony_ciHome page with live JavaScript demo, extensive descriptions, and competitor comparisons: [https://www.nayuki.io/page/qr-code-generator-library](https://www.nayuki.io/page/qr-code-generator-library)
115317bbafSopenharmony_ci
125317bbafSopenharmony_ci
135317bbafSopenharmony_ciFeatures
145317bbafSopenharmony_ci--------
155317bbafSopenharmony_ci
165317bbafSopenharmony_ciCore features:
175317bbafSopenharmony_ci
185317bbafSopenharmony_ci* Available in 6 programming languages, all with nearly equal functionality: Java, TypeScript/JavaScript, Python, Rust, C++, C
195317bbafSopenharmony_ci* Significantly shorter code but more documentation comments compared to competing libraries
205317bbafSopenharmony_ci* Supports encoding all 40 versions (sizes) and all 4 error correction levels, as per the QR Code Model 2 standard
215317bbafSopenharmony_ci* Output format: Raw modules/pixels of the QR symbol
225317bbafSopenharmony_ci* Detects finder-like penalty patterns more accurately than other implementations
235317bbafSopenharmony_ci* Encodes numeric and special-alphanumeric text in less space than general text
245317bbafSopenharmony_ci* Open-source code under the permissive MIT License
255317bbafSopenharmony_ci
265317bbafSopenharmony_ciManual parameters:
275317bbafSopenharmony_ci
285317bbafSopenharmony_ci* User can specify minimum and maximum version numbers allowed, then library will automatically choose smallest version in the range that fits the data
295317bbafSopenharmony_ci* User can specify mask pattern manually, otherwise library will automatically evaluate all 8 masks and select the optimal one
305317bbafSopenharmony_ci* User can specify absolute error correction level, or allow the library to boost it if it doesn't increase the version number
315317bbafSopenharmony_ci* User can create a list of data segments manually and add ECI segments
325317bbafSopenharmony_ci
335317bbafSopenharmony_ciOptional advanced features (Java only):
345317bbafSopenharmony_ci
355317bbafSopenharmony_ci* Encodes Japanese Unicode text in kanji mode to save a lot of space compared to UTF-8 bytes
365317bbafSopenharmony_ci* Computes optimal segment mode switching for text with mixed numeric/alphanumeric/general/kanji parts
375317bbafSopenharmony_ci
385317bbafSopenharmony_ciMore information about QR Code technology and this library's design can be found on the project home page.
395317bbafSopenharmony_ci
405317bbafSopenharmony_ci
415317bbafSopenharmony_ciExamples
425317bbafSopenharmony_ci--------
435317bbafSopenharmony_ci
445317bbafSopenharmony_ciThe code below is in Java, but the other language ports are designed with essentially the same API naming and behavior.
455317bbafSopenharmony_ci
465317bbafSopenharmony_ci```java
475317bbafSopenharmony_ciimport java.awt.image.BufferedImage;
485317bbafSopenharmony_ciimport java.io.File;
495317bbafSopenharmony_ciimport java.util.List;
505317bbafSopenharmony_ciimport javax.imageio.ImageIO;
515317bbafSopenharmony_ciimport io.nayuki.qrcodegen.*;
525317bbafSopenharmony_ci
535317bbafSopenharmony_ci// Simple operation
545317bbafSopenharmony_ciQrCode qr0 = QrCode.encodeText("Hello, world!", QrCode.Ecc.MEDIUM);
555317bbafSopenharmony_ciBufferedImage img = toImage(qr0, 4, 10);  // See QrCodeGeneratorDemo
565317bbafSopenharmony_ciImageIO.write(img, "png", new File("qr-code.png"));
575317bbafSopenharmony_ci
585317bbafSopenharmony_ci// Manual operation
595317bbafSopenharmony_ciList<QrSegment> segs = QrSegment.makeSegments("3141592653589793238462643383");
605317bbafSopenharmony_ciQrCode qr1 = QrCode.encodeSegments(segs, QrCode.Ecc.HIGH, 5, 5, 2, false);
615317bbafSopenharmony_cifor (int y = 0; y < qr1.size; y++) {
625317bbafSopenharmony_ci    for (int x = 0; x < qr1.size; x++) {
635317bbafSopenharmony_ci        (... paint qr1.getModule(x, y) ...)
645317bbafSopenharmony_ci    }
655317bbafSopenharmony_ci}
665317bbafSopenharmony_ci```
675317bbafSopenharmony_ci
685317bbafSopenharmony_ci
695317bbafSopenharmony_ciLicense
705317bbafSopenharmony_ci-------
715317bbafSopenharmony_ci
725317bbafSopenharmony_ciCopyright © 2022 Project Nayuki. (MIT License)  
735317bbafSopenharmony_ci[https://www.nayuki.io/page/qr-code-generator-library](https://www.nayuki.io/page/qr-code-generator-library)
745317bbafSopenharmony_ci
755317bbafSopenharmony_ciPermission is hereby granted, free of charge, to any person obtaining a copy of
765317bbafSopenharmony_cithis software and associated documentation files (the "Software"), to deal in
775317bbafSopenharmony_cithe Software without restriction, including without limitation the rights to
785317bbafSopenharmony_ciuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
795317bbafSopenharmony_cithe Software, and to permit persons to whom the Software is furnished to do so,
805317bbafSopenharmony_cisubject to the following conditions:
815317bbafSopenharmony_ci
825317bbafSopenharmony_ci* The above copyright notice and this permission notice shall be included in
835317bbafSopenharmony_ci  all copies or substantial portions of the Software.
845317bbafSopenharmony_ci
855317bbafSopenharmony_ci* The Software is provided "as is", without warranty of any kind, express or
865317bbafSopenharmony_ci  implied, including but not limited to the warranties of merchantability,
875317bbafSopenharmony_ci  fitness for a particular purpose and noninfringement. In no event shall the
885317bbafSopenharmony_ci  authors or copyright holders be liable for any claim, damages or other
895317bbafSopenharmony_ci  liability, whether in an action of contract, tort or otherwise, arising from,
905317bbafSopenharmony_ci  out of or in connection with the Software or the use or other dealings in the
915317bbafSopenharmony_ci  Software.
92