react-native-nitro-zxing 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/VisionCameraZxing.podspec +48 -0
- package/android/CMakeLists.txt +43 -0
- package/android/build.gradle +150 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/cpp/cpp-adapter.cpp +7 -0
- package/android/src/main/java/com/margelo/nitro/camera/zxing/VisionCameraZxingPackage.kt +21 -0
- package/cpp/BarcodeValueTypeClassifier.cpp +70 -0
- package/cpp/BarcodeValueTypeClassifier.hpp +14 -0
- package/cpp/FrameImageView.cpp +75 -0
- package/cpp/FrameImageView.hpp +34 -0
- package/cpp/HybridBarcode.cpp +59 -0
- package/cpp/HybridBarcode.hpp +26 -0
- package/cpp/HybridBarcodeScanner.cpp +121 -0
- package/cpp/HybridBarcodeScanner.hpp +26 -0
- package/cpp/HybridBarcodeScannerFactory.cpp +11 -0
- package/cpp/HybridBarcodeScannerFactory.hpp +14 -0
- package/cpp/ImageDownscaler.cpp +34 -0
- package/cpp/ImageDownscaler.hpp +21 -0
- package/cpp/ZXingDecoder.cpp +189 -0
- package/cpp/ZXingDecoder.hpp +72 -0
- package/cpp/zxing-core/LICENSE +202 -0
- package/cpp/zxing-core/README.md +156 -0
- package/cpp/zxing-core/core/CMakeLists.txt +784 -0
- package/cpp/zxing-core/core/Version.h.in +28 -0
- package/cpp/zxing-core/core/ZXingConfig.cmake.in +9 -0
- package/cpp/zxing-core/core/src/Barcode.cpp +255 -0
- package/cpp/zxing-core/core/src/Barcode.h +191 -0
- package/cpp/zxing-core/core/src/BarcodeData.h +100 -0
- package/cpp/zxing-core/core/src/BarcodeFormat.cpp +286 -0
- package/cpp/zxing-core/core/src/BarcodeFormat.h +272 -0
- package/cpp/zxing-core/core/src/BinaryBitmap.cpp +111 -0
- package/cpp/zxing-core/core/src/BinaryBitmap.h +66 -0
- package/cpp/zxing-core/core/src/BitArray.cpp +38 -0
- package/cpp/zxing-core/core/src/BitArray.h +181 -0
- package/cpp/zxing-core/core/src/BitMatrix.cpp +175 -0
- package/cpp/zxing-core/core/src/BitMatrix.h +199 -0
- package/cpp/zxing-core/core/src/BitMatrixCursor.h +253 -0
- package/cpp/zxing-core/core/src/BitMatrixIO.cpp +101 -0
- package/cpp/zxing-core/core/src/BitMatrixIO.h +21 -0
- package/cpp/zxing-core/core/src/BitSource.cpp +77 -0
- package/cpp/zxing-core/core/src/BitSource.h +72 -0
- package/cpp/zxing-core/core/src/ByteArray.h +42 -0
- package/cpp/zxing-core/core/src/CharacterSet.cpp +78 -0
- package/cpp/zxing-core/core/src/CharacterSet.h +58 -0
- package/cpp/zxing-core/core/src/ConcentricFinder.cpp +312 -0
- package/cpp/zxing-core/core/src/ConcentricFinder.h +156 -0
- package/cpp/zxing-core/core/src/Content.cpp +471 -0
- package/cpp/zxing-core/core/src/Content.h +82 -0
- package/cpp/zxing-core/core/src/ContentType.h +19 -0
- package/cpp/zxing-core/core/src/CreateBarcode.cpp +490 -0
- package/cpp/zxing-core/core/src/CreateBarcode.h +132 -0
- package/cpp/zxing-core/core/src/DecoderResult.h +92 -0
- package/cpp/zxing-core/core/src/DetectorResult.h +44 -0
- package/cpp/zxing-core/core/src/ECI.cpp +81 -0
- package/cpp/zxing-core/core/src/ECI.h +78 -0
- package/cpp/zxing-core/core/src/Error.cpp +29 -0
- package/cpp/zxing-core/core/src/Error.h +79 -0
- package/cpp/zxing-core/core/src/Flags.h +165 -0
- package/cpp/zxing-core/core/src/GTIN.cpp +253 -0
- package/cpp/zxing-core/core/src/GTIN.h +58 -0
- package/cpp/zxing-core/core/src/GlobalHistogramBinarizer.cpp +197 -0
- package/cpp/zxing-core/core/src/GlobalHistogramBinarizer.h +34 -0
- package/cpp/zxing-core/core/src/GridSampler.cpp +124 -0
- package/cpp/zxing-core/core/src/GridSampler.h +59 -0
- package/cpp/zxing-core/core/src/HRI.cpp +343 -0
- package/cpp/zxing-core/core/src/HRI.h +16 -0
- package/cpp/zxing-core/core/src/HybridBinarizer.cpp +315 -0
- package/cpp/zxing-core/core/src/HybridBinarizer.h +40 -0
- package/cpp/zxing-core/core/src/ImageView.h +168 -0
- package/cpp/zxing-core/core/src/JSON.cpp +154 -0
- package/cpp/zxing-core/core/src/JSON.h +66 -0
- package/cpp/zxing-core/core/src/LocalGrid.cpp +242 -0
- package/cpp/zxing-core/core/src/LocalGrid.h +91 -0
- package/cpp/zxing-core/core/src/LogMatrix.h +105 -0
- package/cpp/zxing-core/core/src/Matrix.h +125 -0
- package/cpp/zxing-core/core/src/MultiFormatReader.cpp +107 -0
- package/cpp/zxing-core/core/src/MultiFormatReader.h +34 -0
- package/cpp/zxing-core/core/src/MultiFormatWriter.cpp +111 -0
- package/cpp/zxing-core/core/src/MultiFormatWriter.h +62 -0
- package/cpp/zxing-core/core/src/Pattern.h +472 -0
- package/cpp/zxing-core/core/src/PerspectiveTransform.cpp +81 -0
- package/cpp/zxing-core/core/src/PerspectiveTransform.h +47 -0
- package/cpp/zxing-core/core/src/Point.h +185 -0
- package/cpp/zxing-core/core/src/Quadrilateral.h +215 -0
- package/cpp/zxing-core/core/src/Range.h +112 -0
- package/cpp/zxing-core/core/src/ReadBarcode.cpp +335 -0
- package/cpp/zxing-core/core/src/ReadBarcode.h +33 -0
- package/cpp/zxing-core/core/src/Reader.h +32 -0
- package/cpp/zxing-core/core/src/ReaderOptions.h +210 -0
- package/cpp/zxing-core/core/src/ReedSolomon.cpp +100 -0
- package/cpp/zxing-core/core/src/ReedSolomon.h +66 -0
- package/cpp/zxing-core/core/src/RegressionLine.h +161 -0
- package/cpp/zxing-core/core/src/ResultPoint.cpp +20 -0
- package/cpp/zxing-core/core/src/ResultPoint.h +35 -0
- package/cpp/zxing-core/core/src/StdGenerator.h +121 -0
- package/cpp/zxing-core/core/src/StdPrint.h +38 -0
- package/cpp/zxing-core/core/src/StdScope.h +55 -0
- package/cpp/zxing-core/core/src/StructuredAppend.h +19 -0
- package/cpp/zxing-core/core/src/SymbologyIdentifier.h +29 -0
- package/cpp/zxing-core/core/src/TextDecoder.cpp +59 -0
- package/cpp/zxing-core/core/src/TextDecoder.h +23 -0
- package/cpp/zxing-core/core/src/TextEncoder.cpp +75 -0
- package/cpp/zxing-core/core/src/TextEncoder.h +31 -0
- package/cpp/zxing-core/core/src/ThresholdBinarizer.h +58 -0
- package/cpp/zxing-core/core/src/TritMatrix.h +29 -0
- package/cpp/zxing-core/core/src/Utf.cpp +276 -0
- package/cpp/zxing-core/core/src/Utf.h +26 -0
- package/cpp/zxing-core/core/src/WhiteRectDetector.cpp +276 -0
- package/cpp/zxing-core/core/src/WhiteRectDetector.h +36 -0
- package/cpp/zxing-core/core/src/WriteBarcode.cpp +213 -0
- package/cpp/zxing-core/core/src/WriteBarcode.h +72 -0
- package/cpp/zxing-core/core/src/ZXAlgorithms.h +353 -0
- package/cpp/zxing-core/core/src/ZXConfig.h +17 -0
- package/cpp/zxing-core/core/src/ZXTestSupport.h +9 -0
- package/cpp/zxing-core/core/src/ZXVersion.h +14 -0
- package/cpp/zxing-core/core/src/ZXingC.cpp +460 -0
- package/cpp/zxing-core/core/src/ZXingC.h +296 -0
- package/cpp/zxing-core/core/src/ZXingCpp.cpp +18 -0
- package/cpp/zxing-core/core/src/ZXingCpp.h +76 -0
- package/cpp/zxing-core/core/src/ZXingQt.h +606 -0
- package/cpp/zxing-core/core/src/aztec/AZDecoder.cpp +376 -0
- package/cpp/zxing-core/core/src/aztec/AZDecoder.h +20 -0
- package/cpp/zxing-core/core/src/aztec/AZDetector.cpp +508 -0
- package/cpp/zxing-core/core/src/aztec/AZDetector.h +25 -0
- package/cpp/zxing-core/core/src/aztec/AZDetectorResult.h +51 -0
- package/cpp/zxing-core/core/src/aztec/AZEncoder.cpp +318 -0
- package/cpp/zxing-core/core/src/aztec/AZEncoder.h +44 -0
- package/cpp/zxing-core/core/src/aztec/AZEncodingState.h +40 -0
- package/cpp/zxing-core/core/src/aztec/AZHighLevelEncoder.cpp +377 -0
- package/cpp/zxing-core/core/src/aztec/AZHighLevelEncoder.h +36 -0
- package/cpp/zxing-core/core/src/aztec/AZReader.cpp +45 -0
- package/cpp/zxing-core/core/src/aztec/AZReader.h +21 -0
- package/cpp/zxing-core/core/src/aztec/AZToken.cpp +44 -0
- package/cpp/zxing-core/core/src/aztec/AZToken.h +39 -0
- package/cpp/zxing-core/core/src/aztec/AZWriter.cpp +38 -0
- package/cpp/zxing-core/core/src/aztec/AZWriter.h +55 -0
- package/cpp/zxing-core/core/src/datamatrix/DMBitLayout.cpp +194 -0
- package/cpp/zxing-core/core/src/datamatrix/DMBitLayout.h +21 -0
- package/cpp/zxing-core/core/src/datamatrix/DMDataBlock.cpp +63 -0
- package/cpp/zxing-core/core/src/datamatrix/DMDataBlock.h +41 -0
- package/cpp/zxing-core/core/src/datamatrix/DMDecoder.cpp +457 -0
- package/cpp/zxing-core/core/src/datamatrix/DMDecoder.h +19 -0
- package/cpp/zxing-core/core/src/datamatrix/DMDetector.cpp +1230 -0
- package/cpp/zxing-core/core/src/datamatrix/DMDetector.h +23 -0
- package/cpp/zxing-core/core/src/datamatrix/DMECEncoder.cpp +137 -0
- package/cpp/zxing-core/core/src/datamatrix/DMECEncoder.h +26 -0
- package/cpp/zxing-core/core/src/datamatrix/DMEncoderContext.h +128 -0
- package/cpp/zxing-core/core/src/datamatrix/DMHighLevelEncoder.cpp +919 -0
- package/cpp/zxing-core/core/src/datamatrix/DMHighLevelEncoder.h +29 -0
- package/cpp/zxing-core/core/src/datamatrix/DMReader.cpp +40 -0
- package/cpp/zxing-core/core/src/datamatrix/DMReader.h +21 -0
- package/cpp/zxing-core/core/src/datamatrix/DMSymbolInfo.cpp +141 -0
- package/cpp/zxing-core/core/src/datamatrix/DMSymbolInfo.h +78 -0
- package/cpp/zxing-core/core/src/datamatrix/DMSymbolShape.h +17 -0
- package/cpp/zxing-core/core/src/datamatrix/DMVersion.cpp +82 -0
- package/cpp/zxing-core/core/src/datamatrix/DMVersion.h +76 -0
- package/cpp/zxing-core/core/src/datamatrix/DMWriter.cpp +114 -0
- package/cpp/zxing-core/core/src/datamatrix/DMWriter.h +62 -0
- package/cpp/zxing-core/core/src/librscpp/README.md +65 -0
- package/cpp/zxing-core/core/src/librscpp/decode.h +258 -0
- package/cpp/zxing-core/core/src/librscpp/encode.h +124 -0
- package/cpp/zxing-core/core/src/librscpp/field.h +158 -0
- package/cpp/zxing-core/core/src/librscpp/poly.h +194 -0
- package/cpp/zxing-core/core/src/libzint/2of5inter.c +1 -0
- package/cpp/zxing-core/core/src/libzint/2of5inter_based.c +1 -0
- package/cpp/zxing-core/core/src/libzint/aztec.c +1 -0
- package/cpp/zxing-core/core/src/libzint/aztec.h +1 -0
- package/cpp/zxing-core/core/src/libzint/big5.h +1 -0
- package/cpp/zxing-core/core/src/libzint/codabar.c +1 -0
- package/cpp/zxing-core/core/src/libzint/code.c +1 -0
- package/cpp/zxing-core/core/src/libzint/code128.c +1 -0
- package/cpp/zxing-core/core/src/libzint/code128.h +1 -0
- package/cpp/zxing-core/core/src/libzint/common.c +1 -0
- package/cpp/zxing-core/core/src/libzint/common.h +1 -0
- package/cpp/zxing-core/core/src/libzint/dmatrix.c +1 -0
- package/cpp/zxing-core/core/src/libzint/dmatrix.h +1 -0
- package/cpp/zxing-core/core/src/libzint/dxfilmedge.c +1 -0
- package/cpp/zxing-core/core/src/libzint/eci.c +1 -0
- package/cpp/zxing-core/core/src/libzint/eci.h +1 -0
- package/cpp/zxing-core/core/src/libzint/eci_sb.h +1 -0
- package/cpp/zxing-core/core/src/libzint/filemem.c +1 -0
- package/cpp/zxing-core/core/src/libzint/filemem.h +1 -0
- package/cpp/zxing-core/core/src/libzint/fonts/normal_woff2.h +1 -0
- package/cpp/zxing-core/core/src/libzint/fonts/upcean_woff2.h +1 -0
- package/cpp/zxing-core/core/src/libzint/gb18030.h +1 -0
- package/cpp/zxing-core/core/src/libzint/gb2312.h +1 -0
- package/cpp/zxing-core/core/src/libzint/gbk.h +1 -0
- package/cpp/zxing-core/core/src/libzint/general_field.c +1 -0
- package/cpp/zxing-core/core/src/libzint/general_field.h +1 -0
- package/cpp/zxing-core/core/src/libzint/gs1.c +1 -0
- package/cpp/zxing-core/core/src/libzint/gs1.h +1 -0
- package/cpp/zxing-core/core/src/libzint/gs1_lint.h +1 -0
- package/cpp/zxing-core/core/src/libzint/iso3166.h +1 -0
- package/cpp/zxing-core/core/src/libzint/iso4217.h +1 -0
- package/cpp/zxing-core/core/src/libzint/ksx1001.h +1 -0
- package/cpp/zxing-core/core/src/libzint/large.c +1 -0
- package/cpp/zxing-core/core/src/libzint/large.h +1 -0
- package/cpp/zxing-core/core/src/libzint/library.c +1 -0
- package/cpp/zxing-core/core/src/libzint/maxicode.c +1 -0
- package/cpp/zxing-core/core/src/libzint/maxicode.h +1 -0
- package/cpp/zxing-core/core/src/libzint/medical.c +1 -0
- package/cpp/zxing-core/core/src/libzint/output.c +1 -0
- package/cpp/zxing-core/core/src/libzint/output.h +1 -0
- package/cpp/zxing-core/core/src/libzint/pdf417.c +1 -0
- package/cpp/zxing-core/core/src/libzint/pdf417.h +1 -0
- package/cpp/zxing-core/core/src/libzint/pdf417_tabs.h +1 -0
- package/cpp/zxing-core/core/src/libzint/qr.c +1 -0
- package/cpp/zxing-core/core/src/libzint/qr.h +1 -0
- package/cpp/zxing-core/core/src/libzint/raster.c +1 -0
- package/cpp/zxing-core/core/src/libzint/raster_font.h +1 -0
- package/cpp/zxing-core/core/src/libzint/reedsol.c +1 -0
- package/cpp/zxing-core/core/src/libzint/reedsol.h +1 -0
- package/cpp/zxing-core/core/src/libzint/reedsol_logs.h +1 -0
- package/cpp/zxing-core/core/src/libzint/rss.c +1 -0
- package/cpp/zxing-core/core/src/libzint/rss.h +1 -0
- package/cpp/zxing-core/core/src/libzint/sjis.h +1 -0
- package/cpp/zxing-core/core/src/libzint/stubs.c +137 -0
- package/cpp/zxing-core/core/src/libzint/svg.c +1 -0
- package/cpp/zxing-core/core/src/libzint/telepen.c +1 -0
- package/cpp/zxing-core/core/src/libzint/upcean.c +1 -0
- package/cpp/zxing-core/core/src/libzint/vector.c +1 -0
- package/cpp/zxing-core/core/src/libzint/zfiletypes.h +1 -0
- package/cpp/zxing-core/core/src/libzint/zint.h +1 -0
- package/cpp/zxing-core/core/src/libzint/zintconfig.h +1 -0
- package/cpp/zxing-core/core/src/libzueci/README.md +11 -0
- package/cpp/zxing-core/core/src/libzueci/zueci.c +1718 -0
- package/cpp/zxing-core/core/src/libzueci/zueci.h +179 -0
- package/cpp/zxing-core/core/src/libzueci/zueci_big5.h +3884 -0
- package/cpp/zxing-core/core/src/libzueci/zueci_common.h +31 -0
- package/cpp/zxing-core/core/src/libzueci/zueci_gb18030.h +264 -0
- package/cpp/zxing-core/core/src/libzueci/zueci_gb2312.h +2381 -0
- package/cpp/zxing-core/core/src/libzueci/zueci_gbk.h +4047 -0
- package/cpp/zxing-core/core/src/libzueci/zueci_ksx1001.h +2932 -0
- package/cpp/zxing-core/core/src/libzueci/zueci_sb.h +1112 -0
- package/cpp/zxing-core/core/src/libzueci/zueci_sjis.h +2286 -0
- package/cpp/zxing-core/core/src/maxicode/MCBitMatrixParser.cpp +68 -0
- package/cpp/zxing-core/core/src/maxicode/MCBitMatrixParser.h +30 -0
- package/cpp/zxing-core/core/src/maxicode/MCDecoder.cpp +329 -0
- package/cpp/zxing-core/core/src/maxicode/MCDecoder.h +19 -0
- package/cpp/zxing-core/core/src/maxicode/MCReader.cpp +65 -0
- package/cpp/zxing-core/core/src/maxicode/MCReader.h +21 -0
- package/cpp/zxing-core/core/src/oned/ODCodabarReader.cpp +102 -0
- package/cpp/zxing-core/core/src/oned/ODCodabarReader.h +21 -0
- package/cpp/zxing-core/core/src/oned/ODCodabarWriter.cpp +136 -0
- package/cpp/zxing-core/core/src/oned/ODCodabarWriter.h +34 -0
- package/cpp/zxing-core/core/src/oned/ODCode128Patterns.h +130 -0
- package/cpp/zxing-core/core/src/oned/ODCode128Reader.cpp +236 -0
- package/cpp/zxing-core/core/src/oned/ODCode128Reader.h +21 -0
- package/cpp/zxing-core/core/src/oned/ODCode128Writer.cpp +261 -0
- package/cpp/zxing-core/core/src/oned/ODCode128Writer.h +34 -0
- package/cpp/zxing-core/core/src/oned/ODCode39Reader.cpp +213 -0
- package/cpp/zxing-core/core/src/oned/ODCode39Reader.h +26 -0
- package/cpp/zxing-core/core/src/oned/ODCode39Writer.cpp +176 -0
- package/cpp/zxing-core/core/src/oned/ODCode39Writer.h +34 -0
- package/cpp/zxing-core/core/src/oned/ODCode93Patterns.h +80 -0
- package/cpp/zxing-core/core/src/oned/ODCode93Reader.cpp +112 -0
- package/cpp/zxing-core/core/src/oned/ODCode93Reader.h +21 -0
- package/cpp/zxing-core/core/src/oned/ODCode93Writer.cpp +192 -0
- package/cpp/zxing-core/core/src/oned/ODCode93Writer.h +32 -0
- package/cpp/zxing-core/core/src/oned/ODDXFilmEdgeReader.cpp +246 -0
- package/cpp/zxing-core/core/src/oned/ODDXFilmEdgeReader.h +26 -0
- package/cpp/zxing-core/core/src/oned/ODDataBarCommon.cpp +172 -0
- package/cpp/zxing-core/core/src/oned/ODDataBarCommon.h +204 -0
- package/cpp/zxing-core/core/src/oned/ODDataBarExpandedBitDecoder.cpp +253 -0
- package/cpp/zxing-core/core/src/oned/ODDataBarExpandedBitDecoder.h +19 -0
- package/cpp/zxing-core/core/src/oned/ODDataBarExpandedReader.cpp +383 -0
- package/cpp/zxing-core/core/src/oned/ODDataBarExpandedReader.h +25 -0
- package/cpp/zxing-core/core/src/oned/ODDataBarLimitedReader.cpp +163 -0
- package/cpp/zxing-core/core/src/oned/ODDataBarLimitedReader.h +23 -0
- package/cpp/zxing-core/core/src/oned/ODDataBarReader.cpp +240 -0
- package/cpp/zxing-core/core/src/oned/ODDataBarReader.h +25 -0
- package/cpp/zxing-core/core/src/oned/ODEAN13Writer.cpp +62 -0
- package/cpp/zxing-core/core/src/oned/ODEAN13Writer.h +34 -0
- package/cpp/zxing-core/core/src/oned/ODEAN8Writer.cpp +51 -0
- package/cpp/zxing-core/core/src/oned/ODEAN8Writer.h +34 -0
- package/cpp/zxing-core/core/src/oned/ODITFReader.cpp +97 -0
- package/cpp/zxing-core/core/src/oned/ODITFReader.h +33 -0
- package/cpp/zxing-core/core/src/oned/ODITFWriter.cpp +78 -0
- package/cpp/zxing-core/core/src/oned/ODITFWriter.h +34 -0
- package/cpp/zxing-core/core/src/oned/ODMultiUPCEANReader.cpp +323 -0
- package/cpp/zxing-core/core/src/oned/ODMultiUPCEANReader.h +32 -0
- package/cpp/zxing-core/core/src/oned/ODReader.cpp +259 -0
- package/cpp/zxing-core/core/src/oned/ODReader.h +35 -0
- package/cpp/zxing-core/core/src/oned/ODRowReader.h +222 -0
- package/cpp/zxing-core/core/src/oned/ODTelepenReader.cpp +199 -0
- package/cpp/zxing-core/core/src/oned/ODTelepenReader.h +25 -0
- package/cpp/zxing-core/core/src/oned/ODUPCAWriter.cpp +33 -0
- package/cpp/zxing-core/core/src/oned/ODUPCAWriter.h +34 -0
- package/cpp/zxing-core/core/src/oned/ODUPCEANCommon.cpp +80 -0
- package/cpp/zxing-core/core/src/oned/ODUPCEANCommon.h +129 -0
- package/cpp/zxing-core/core/src/oned/ODUPCEWriter.cpp +56 -0
- package/cpp/zxing-core/core/src/oned/ODUPCEWriter.h +34 -0
- package/cpp/zxing-core/core/src/oned/ODWriterHelper.cpp +39 -0
- package/cpp/zxing-core/core/src/oned/ODWriterHelper.h +48 -0
- package/cpp/zxing-core/core/src/pdf417/MicroPDFReader.cpp +796 -0
- package/cpp/zxing-core/core/src/pdf417/MicroPDFReader.h +23 -0
- package/cpp/zxing-core/core/src/pdf417/PDF417.cpp +85 -0
- package/cpp/zxing-core/core/src/pdf417/PDF417.h +81 -0
- package/cpp/zxing-core/core/src/pdf417/PDFBarcodeMetadata.h +53 -0
- package/cpp/zxing-core/core/src/pdf417/PDFBarcodeValue.cpp +48 -0
- package/cpp/zxing-core/core/src/pdf417/PDFBarcodeValue.h +38 -0
- package/cpp/zxing-core/core/src/pdf417/PDFBoundingBox.cpp +116 -0
- package/cpp/zxing-core/core/src/pdf417/PDFBoundingBox.h +75 -0
- package/cpp/zxing-core/core/src/pdf417/PDFCodeword.h +71 -0
- package/cpp/zxing-core/core/src/pdf417/PDFCodewordDecoder.cpp +588 -0
- package/cpp/zxing-core/core/src/pdf417/PDFCodewordDecoder.h +41 -0
- package/cpp/zxing-core/core/src/pdf417/PDFCompaction.h +20 -0
- package/cpp/zxing-core/core/src/pdf417/PDFCustomData.h +32 -0
- package/cpp/zxing-core/core/src/pdf417/PDFDecoder.cpp +725 -0
- package/cpp/zxing-core/core/src/pdf417/PDFDecoder.h +20 -0
- package/cpp/zxing-core/core/src/pdf417/PDFDetectionResult.cpp +247 -0
- package/cpp/zxing-core/core/src/pdf417/PDFDetectionResult.h +74 -0
- package/cpp/zxing-core/core/src/pdf417/PDFDetectionResultColumn.cpp +321 -0
- package/cpp/zxing-core/core/src/pdf417/PDFDetectionResultColumn.h +83 -0
- package/cpp/zxing-core/core/src/pdf417/PDFDetector.cpp +371 -0
- package/cpp/zxing-core/core/src/pdf417/PDFDetector.h +45 -0
- package/cpp/zxing-core/core/src/pdf417/PDFEncoder.cpp +570 -0
- package/cpp/zxing-core/core/src/pdf417/PDFEncoder.h +182 -0
- package/cpp/zxing-core/core/src/pdf417/PDFHighLevelEncoder.cpp +570 -0
- package/cpp/zxing-core/core/src/pdf417/PDFHighLevelEncoder.h +32 -0
- package/cpp/zxing-core/core/src/pdf417/PDFReader.cpp +333 -0
- package/cpp/zxing-core/core/src/pdf417/PDFReader.h +28 -0
- package/cpp/zxing-core/core/src/pdf417/PDFScanningDecoder.cpp +559 -0
- package/cpp/zxing-core/core/src/pdf417/PDFScanningDecoder.h +41 -0
- package/cpp/zxing-core/core/src/pdf417/PDFWriter.cpp +170 -0
- package/cpp/zxing-core/core/src/pdf417/PDFWriter.h +74 -0
- package/cpp/zxing-core/core/src/pdf417/ZXBigInteger.cpp +623 -0
- package/cpp/zxing-core/core/src/pdf417/ZXBigInteger.h +81 -0
- package/cpp/zxing-core/core/src/pdf417/ZXNullable.h +105 -0
- package/cpp/zxing-core/core/src/qrcode/QRBitMatrixParser.cpp +294 -0
- package/cpp/zxing-core/core/src/qrcode/QRBitMatrixParser.h +41 -0
- package/cpp/zxing-core/core/src/qrcode/QRCodecMode.cpp +95 -0
- package/cpp/zxing-core/core/src/qrcode/QRCodecMode.h +59 -0
- package/cpp/zxing-core/core/src/qrcode/QRDataBlock.cpp +93 -0
- package/cpp/zxing-core/core/src/qrcode/QRDataBlock.h +52 -0
- package/cpp/zxing-core/core/src/qrcode/QRDataMask.h +50 -0
- package/cpp/zxing-core/core/src/qrcode/QRDecoder.cpp +359 -0
- package/cpp/zxing-core/core/src/qrcode/QRDecoder.h +19 -0
- package/cpp/zxing-core/core/src/qrcode/QRDetector.cpp +920 -0
- package/cpp/zxing-core/core/src/qrcode/QRDetector.h +45 -0
- package/cpp/zxing-core/core/src/qrcode/QRECB.h +52 -0
- package/cpp/zxing-core/core/src/qrcode/QREncodeResult.h +33 -0
- package/cpp/zxing-core/core/src/qrcode/QREncoder.cpp +568 -0
- package/cpp/zxing-core/core/src/qrcode/QREncoder.h +21 -0
- package/cpp/zxing-core/core/src/qrcode/QRErrorCorrectionLevel.cpp +51 -0
- package/cpp/zxing-core/core/src/qrcode/QRErrorCorrectionLevel.h +39 -0
- package/cpp/zxing-core/core/src/qrcode/QRFormatInformation.cpp +160 -0
- package/cpp/zxing-core/core/src/qrcode/QRFormatInformation.h +61 -0
- package/cpp/zxing-core/core/src/qrcode/QRMaskUtil.cpp +156 -0
- package/cpp/zxing-core/core/src/qrcode/QRMaskUtil.h +15 -0
- package/cpp/zxing-core/core/src/qrcode/QRMatrixUtil.cpp +318 -0
- package/cpp/zxing-core/core/src/qrcode/QRMatrixUtil.h +25 -0
- package/cpp/zxing-core/core/src/qrcode/QRReader.cpp +149 -0
- package/cpp/zxing-core/core/src/qrcode/QRReader.h +21 -0
- package/cpp/zxing-core/core/src/qrcode/QRVersion.cpp +754 -0
- package/cpp/zxing-core/core/src/qrcode/QRVersion.h +127 -0
- package/cpp/zxing-core/core/src/qrcode/QRWriter.cpp +51 -0
- package/cpp/zxing-core/core/src/qrcode/QRWriter.h +74 -0
- package/cpp/zxing-core/core/version.rc.in +34 -0
- package/cpp/zxing-core/core/zxing.pc.in +8 -0
- package/cpp/zxing-core/wrappers/ios/README.md +25 -0
- package/cpp/zxing-core/wrappers/ios/Sources/Wrapper/Version.h +29 -0
- package/cpp/zxing-core/zxing-cpp.podspec +45 -0
- package/lib/factory.d.ts +10 -0
- package/lib/factory.js +12 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +9 -0
- package/lib/specs/Barcode.nitro.d.ts +63 -0
- package/lib/specs/Barcode.nitro.js +1 -0
- package/lib/specs/BarcodeFormat.d.ts +11 -0
- package/lib/specs/BarcodeFormat.js +1 -0
- package/lib/specs/BarcodeScanner.nitro.d.ts +89 -0
- package/lib/specs/BarcodeScanner.nitro.js +1 -0
- package/lib/specs/BarcodeScannerFactory.nitro.d.ts +26 -0
- package/lib/specs/BarcodeScannerFactory.nitro.js +1 -0
- package/lib/specs/BarcodeValueType.d.ts +9 -0
- package/lib/specs/BarcodeValueType.js +1 -0
- package/lib/specs/Point.d.ts +14 -0
- package/lib/specs/Point.js +1 -0
- package/lib/specs/Rect.d.ts +22 -0
- package/lib/specs/Rect.js +1 -0
- package/lib/useBarcodeScanner.d.ts +23 -0
- package/lib/useBarcodeScanner.js +25 -0
- package/nitro.json +20 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/VisionCameraZxing+autolinking.cmake +83 -0
- package/nitrogen/generated/android/VisionCameraZxing+autolinking.gradle +27 -0
- package/nitrogen/generated/android/VisionCameraZxingOnLoad.cpp +49 -0
- package/nitrogen/generated/android/VisionCameraZxingOnLoad.hpp +34 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/zxing/VisionCameraZxingOnLoad.kt +35 -0
- package/nitrogen/generated/ios/VisionCameraZxing+autolinking.rb +62 -0
- package/nitrogen/generated/ios/VisionCameraZxing-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/VisionCameraZxing-Swift-Cxx-Bridge.hpp +27 -0
- package/nitrogen/generated/ios/VisionCameraZxing-Swift-Cxx-Umbrella.hpp +38 -0
- package/nitrogen/generated/ios/VisionCameraZxingAutolinking.mm +35 -0
- package/nitrogen/generated/ios/VisionCameraZxingAutolinking.swift +16 -0
- package/nitrogen/generated/shared/c++/BarcodeFormat.hpp +124 -0
- package/nitrogen/generated/shared/c++/BarcodeScannerOptions.hpp +85 -0
- package/nitrogen/generated/shared/c++/BarcodeValueType.hpp +120 -0
- package/nitrogen/generated/shared/c++/HybridBarcodeScannerSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridBarcodeScannerSpec.hpp +74 -0
- package/nitrogen/generated/shared/c++/HybridBarcodeSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridBarcodeSpec.hpp +82 -0
- package/nitrogen/generated/shared/c++/HybridZXingBarcodeScannerFactorySpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridZXingBarcodeScannerFactorySpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/Point.hpp +87 -0
- package/nitrogen/generated/shared/c++/Rect.hpp +95 -0
- package/nitrogen/generated/shared/c++/TargetBarcodeFormat.hpp +124 -0
- package/package.json +108 -0
- package/react-native.config.js +16 -0
- package/src/factory.ts +26 -0
- package/src/index.ts +9 -0
- package/src/specs/Barcode.nitro.ts +70 -0
- package/src/specs/BarcodeFormat.ts +31 -0
- package/src/specs/BarcodeScanner.nitro.ts +91 -0
- package/src/specs/BarcodeScannerFactory.nitro.ts +27 -0
- package/src/specs/BarcodeValueType.ts +25 -0
- package/src/specs/Point.ts +14 -0
- package/src/specs/Rect.ts +22 -0
- package/src/useBarcodeScanner.ts +36 -0
|
@@ -0,0 +1,919 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2016 Huy Cuong Nguyen
|
|
3
|
+
* Copyright 2016 ZXing authors
|
|
4
|
+
*/
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
|
|
7
|
+
#include "DMHighLevelEncoder.h"
|
|
8
|
+
|
|
9
|
+
#include "ByteArray.h"
|
|
10
|
+
#include "CharacterSet.h"
|
|
11
|
+
#include "DMEncoderContext.h"
|
|
12
|
+
#include "TextEncoder.h"
|
|
13
|
+
#include "ZXAlgorithms.h"
|
|
14
|
+
|
|
15
|
+
#include <algorithm>
|
|
16
|
+
#include <array>
|
|
17
|
+
#include <cmath>
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
#include <functional>
|
|
21
|
+
#include <limits>
|
|
22
|
+
#include <stdexcept>
|
|
23
|
+
#include <string>
|
|
24
|
+
|
|
25
|
+
namespace ZXing::DataMatrix {
|
|
26
|
+
|
|
27
|
+
static const uint8_t PAD = 129;
|
|
28
|
+
static const uint8_t UPPER_SHIFT = 235;
|
|
29
|
+
static const uint8_t MACRO_05 = 236;
|
|
30
|
+
static const uint8_t MACRO_06 = 237;
|
|
31
|
+
static const uint8_t C40_UNLATCH = 254;
|
|
32
|
+
static const uint8_t X12_UNLATCH = 254;
|
|
33
|
+
|
|
34
|
+
enum
|
|
35
|
+
{
|
|
36
|
+
ASCII_ENCODATION,
|
|
37
|
+
C40_ENCODATION,
|
|
38
|
+
TEXT_ENCODATION,
|
|
39
|
+
X12_ENCODATION,
|
|
40
|
+
EDIFACT_ENCODATION,
|
|
41
|
+
BASE256_ENCODATION,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
static const uint8_t LATCHES[] = {
|
|
45
|
+
0, // ASCII mode, no latch needed
|
|
46
|
+
230, // LATCH_TO_C40
|
|
47
|
+
239, // LATCH_TO_TEXT
|
|
48
|
+
238, // LATCH_TO_ANSIX12
|
|
49
|
+
240, // LATCH_TO_EDIFACT
|
|
50
|
+
231, // LATCH_TO_BASE256,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
static bool IsExtendedASCII(int ch)
|
|
54
|
+
{
|
|
55
|
+
return ch >= 128 && ch <= 255;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static bool IsNativeC40(int ch)
|
|
59
|
+
{
|
|
60
|
+
return (ch == ' ') || IsDigit(ch) || IsUpper(ch);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static bool IsNativeText(int ch)
|
|
64
|
+
{
|
|
65
|
+
return (ch == ' ') || IsDigit(ch) || IsLower(ch);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static bool IsX12TermSep(int ch)
|
|
69
|
+
{
|
|
70
|
+
return (ch == '\r') //CR
|
|
71
|
+
|| (ch == '*')
|
|
72
|
+
|| (ch == '>');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static bool IsNativeX12(int ch)
|
|
76
|
+
{
|
|
77
|
+
return IsX12TermSep(ch) || (ch == ' ') || IsDigit(ch) || IsUpper(ch);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static bool IsNativeEDIFACT(int ch)
|
|
81
|
+
{
|
|
82
|
+
return ch >= ' ' && ch <= '^';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static bool IsSpecialB256(int /*ch*/)
|
|
86
|
+
{
|
|
87
|
+
return false; //TODO NOT IMPLEMENTED YET!!!
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* Converts the message to a byte array using the default encoding (cp437) as defined by the
|
|
93
|
+
* specification
|
|
94
|
+
*
|
|
95
|
+
* @param msg the message
|
|
96
|
+
* @return the byte array of the message
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/*
|
|
100
|
+
public static byte[] getBytesForMessage(String msg) {
|
|
101
|
+
return msg.getBytes(Charset.forName("cp437")); //See 4.4.3 and annex B of ISO/IEC 15438:2001(E)
|
|
102
|
+
}
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
static uint8_t Randomize253State(uint8_t ch, int codewordPosition)
|
|
106
|
+
{
|
|
107
|
+
int pseudoRandom = ((149 * codewordPosition) % 253) + 1;
|
|
108
|
+
int tempVariable = ch + pseudoRandom;
|
|
109
|
+
return narrow_cast<uint8_t>(tempVariable <= 254 ? tempVariable : (tempVariable - 254));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static int FindMinimums(const std::array<int, 6>& intCharCounts, int min, std::array<int, 6>& mins)
|
|
113
|
+
{
|
|
114
|
+
mins.fill(0);
|
|
115
|
+
for (int i = 0; i < 6; i++) {
|
|
116
|
+
int current = intCharCounts[i];
|
|
117
|
+
if (min > current) {
|
|
118
|
+
min = current;
|
|
119
|
+
mins.fill(0);
|
|
120
|
+
}
|
|
121
|
+
if (min == current) {
|
|
122
|
+
mins[i]++;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return min;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
static int LookAheadTest(const std::string& msg, size_t startpos, int currentMode)
|
|
129
|
+
{
|
|
130
|
+
if (startpos >= msg.length()) {
|
|
131
|
+
return currentMode;
|
|
132
|
+
}
|
|
133
|
+
std::array<float, 6> charCounts;
|
|
134
|
+
//step J
|
|
135
|
+
if (currentMode == ASCII_ENCODATION) {
|
|
136
|
+
charCounts = { 0, 1, 1, 1, 1, 1.25f };
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
charCounts = { 1, 2, 2, 2, 2, 2.25f };
|
|
140
|
+
charCounts[currentMode] = 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
std::array<int, 6> mins;
|
|
144
|
+
std::array<int, 6> intCharCounts;
|
|
145
|
+
int charsProcessed = 0;
|
|
146
|
+
while (true) {
|
|
147
|
+
//step K
|
|
148
|
+
if ((startpos + charsProcessed) == msg.length()) {
|
|
149
|
+
int min = std::numeric_limits<int>::max();
|
|
150
|
+
std::transform(charCounts.begin(), charCounts.end(), intCharCounts.begin(),
|
|
151
|
+
[](float x) { return static_cast<int>(std::ceil(x)); });
|
|
152
|
+
min = FindMinimums(intCharCounts, min, mins);
|
|
153
|
+
int minCount = Reduce(mins);
|
|
154
|
+
|
|
155
|
+
if (intCharCounts[ASCII_ENCODATION] == min) {
|
|
156
|
+
return ASCII_ENCODATION;
|
|
157
|
+
}
|
|
158
|
+
if (minCount == 1 && mins[BASE256_ENCODATION] > 0) {
|
|
159
|
+
return BASE256_ENCODATION;
|
|
160
|
+
}
|
|
161
|
+
if (minCount == 1 && mins[EDIFACT_ENCODATION] > 0) {
|
|
162
|
+
return EDIFACT_ENCODATION;
|
|
163
|
+
}
|
|
164
|
+
if (minCount == 1 && mins[TEXT_ENCODATION] > 0) {
|
|
165
|
+
return TEXT_ENCODATION;
|
|
166
|
+
}
|
|
167
|
+
if (minCount == 1 && mins[X12_ENCODATION] > 0) {
|
|
168
|
+
return X12_ENCODATION;
|
|
169
|
+
}
|
|
170
|
+
return C40_ENCODATION;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
int c = (uint8_t)msg.at(startpos + charsProcessed);
|
|
174
|
+
charsProcessed++;
|
|
175
|
+
|
|
176
|
+
//step L
|
|
177
|
+
if (IsDigit(c)) {
|
|
178
|
+
charCounts[ASCII_ENCODATION] += 0.5f;
|
|
179
|
+
}
|
|
180
|
+
else if (IsExtendedASCII(c)) {
|
|
181
|
+
charCounts[ASCII_ENCODATION] = std::ceil(charCounts[ASCII_ENCODATION]);
|
|
182
|
+
charCounts[ASCII_ENCODATION] += 2.0f;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
charCounts[ASCII_ENCODATION] = std::ceil(charCounts[ASCII_ENCODATION]);
|
|
186
|
+
charCounts[ASCII_ENCODATION] += 1.0f;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
//step M
|
|
190
|
+
if (IsNativeC40(c)) {
|
|
191
|
+
charCounts[C40_ENCODATION] += 2.0f / 3.0f;
|
|
192
|
+
}
|
|
193
|
+
else if (IsExtendedASCII(c)) {
|
|
194
|
+
charCounts[C40_ENCODATION] += 8.0f / 3.0f;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
charCounts[C40_ENCODATION] += 4.0f / 3.0f;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//step N
|
|
201
|
+
if (IsNativeText(c)) {
|
|
202
|
+
charCounts[TEXT_ENCODATION] += 2.0f / 3.0f;
|
|
203
|
+
}
|
|
204
|
+
else if (IsExtendedASCII(c)) {
|
|
205
|
+
charCounts[TEXT_ENCODATION] += 8.0f / 3.0f;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
charCounts[TEXT_ENCODATION] += 4.0f / 3.0f;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
//step O
|
|
212
|
+
if (IsNativeX12(c)) {
|
|
213
|
+
charCounts[X12_ENCODATION] += 2.0f / 3.0f;
|
|
214
|
+
}
|
|
215
|
+
else if (IsExtendedASCII(c)) {
|
|
216
|
+
charCounts[X12_ENCODATION] += 13.0f / 3.0f;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
charCounts[X12_ENCODATION] += 10.0f / 3.0f;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
//step P
|
|
223
|
+
if (IsNativeEDIFACT(c)) {
|
|
224
|
+
charCounts[EDIFACT_ENCODATION] += 3.0f / 4.0f;
|
|
225
|
+
}
|
|
226
|
+
else if (IsExtendedASCII(c)) {
|
|
227
|
+
charCounts[EDIFACT_ENCODATION] += 17.0f / 4.0f;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
charCounts[EDIFACT_ENCODATION] += 13.0f / 4.0f;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// step Q
|
|
234
|
+
if (IsSpecialB256(c)) {
|
|
235
|
+
charCounts[BASE256_ENCODATION] += 4.0f;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
charCounts[BASE256_ENCODATION] += 1.0f;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
//step R
|
|
242
|
+
if (charsProcessed >= 4) {
|
|
243
|
+
std::transform(charCounts.begin(), charCounts.end(), intCharCounts.begin(),
|
|
244
|
+
[](float x) { return static_cast<int>(std::ceil(x)); });
|
|
245
|
+
FindMinimums(intCharCounts, std::numeric_limits<int>::max(), mins);
|
|
246
|
+
int minCount = Reduce(mins);
|
|
247
|
+
|
|
248
|
+
if (intCharCounts[ASCII_ENCODATION] < intCharCounts[BASE256_ENCODATION]
|
|
249
|
+
&& intCharCounts[ASCII_ENCODATION] < intCharCounts[C40_ENCODATION]
|
|
250
|
+
&& intCharCounts[ASCII_ENCODATION] < intCharCounts[TEXT_ENCODATION]
|
|
251
|
+
&& intCharCounts[ASCII_ENCODATION] < intCharCounts[X12_ENCODATION]
|
|
252
|
+
&& intCharCounts[ASCII_ENCODATION] < intCharCounts[EDIFACT_ENCODATION]) {
|
|
253
|
+
return ASCII_ENCODATION;
|
|
254
|
+
}
|
|
255
|
+
if (intCharCounts[BASE256_ENCODATION] < intCharCounts[ASCII_ENCODATION]
|
|
256
|
+
|| (mins[C40_ENCODATION] + mins[TEXT_ENCODATION] + mins[X12_ENCODATION] + mins[EDIFACT_ENCODATION]) == 0) {
|
|
257
|
+
return BASE256_ENCODATION;
|
|
258
|
+
}
|
|
259
|
+
if (minCount == 1 && mins[EDIFACT_ENCODATION] > 0) {
|
|
260
|
+
return EDIFACT_ENCODATION;
|
|
261
|
+
}
|
|
262
|
+
if (minCount == 1 && mins[TEXT_ENCODATION] > 0) {
|
|
263
|
+
return TEXT_ENCODATION;
|
|
264
|
+
}
|
|
265
|
+
if (minCount == 1 && mins[X12_ENCODATION] > 0) {
|
|
266
|
+
return X12_ENCODATION;
|
|
267
|
+
}
|
|
268
|
+
if (intCharCounts[C40_ENCODATION] + 1 < intCharCounts[ASCII_ENCODATION]
|
|
269
|
+
&& intCharCounts[C40_ENCODATION] + 1 < intCharCounts[BASE256_ENCODATION]
|
|
270
|
+
&& intCharCounts[C40_ENCODATION] + 1 < intCharCounts[EDIFACT_ENCODATION]
|
|
271
|
+
&& intCharCounts[C40_ENCODATION] + 1 < intCharCounts[TEXT_ENCODATION]) {
|
|
272
|
+
if (intCharCounts[C40_ENCODATION] < intCharCounts[X12_ENCODATION]) {
|
|
273
|
+
return C40_ENCODATION;
|
|
274
|
+
}
|
|
275
|
+
if (intCharCounts[C40_ENCODATION] == intCharCounts[X12_ENCODATION]) {
|
|
276
|
+
size_t p = startpos + charsProcessed + 1;
|
|
277
|
+
while (p < msg.length()) {
|
|
278
|
+
int tc = msg.at(p);
|
|
279
|
+
if (IsX12TermSep(tc)) {
|
|
280
|
+
return X12_ENCODATION;
|
|
281
|
+
}
|
|
282
|
+
if (!IsNativeX12(tc)) {
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
p++;
|
|
286
|
+
}
|
|
287
|
+
return C40_ENCODATION;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
static std::string ToHexString(int c)
|
|
295
|
+
{
|
|
296
|
+
const char* digits = "0123456789abcdef";
|
|
297
|
+
std::string val(4, '0');
|
|
298
|
+
val[1] = 'x';
|
|
299
|
+
val[2] = digits[(c >> 4) & 0xf];
|
|
300
|
+
val[3] = digits[c & 0xf];
|
|
301
|
+
return val;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
namespace ASCIIEncoder {
|
|
305
|
+
/**
|
|
306
|
+
* Determines the number of consecutive characters that are encodable using numeric compaction.
|
|
307
|
+
*
|
|
308
|
+
* @param msg the message
|
|
309
|
+
* @param startpos the start position within the message
|
|
310
|
+
* @return the requested character count
|
|
311
|
+
*/
|
|
312
|
+
static int DetermineConsecutiveDigitCount(const std::string& msg, int startpos)
|
|
313
|
+
{
|
|
314
|
+
auto begin = msg.begin() + startpos;
|
|
315
|
+
return narrow_cast<int>(std::find_if_not(begin, msg.end(), IsDigit<char>) - begin);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
static uint8_t EncodeASCIIDigits(int digit1, int digit2)
|
|
319
|
+
{
|
|
320
|
+
if (IsDigit(digit1) && IsDigit(digit2)) {
|
|
321
|
+
int num = (digit1 - '0') * 10 + (digit2 - '0');
|
|
322
|
+
return static_cast<uint8_t>(num + 130);
|
|
323
|
+
}
|
|
324
|
+
return '?';
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
static void EncodeASCII(EncoderContext& context)
|
|
328
|
+
{
|
|
329
|
+
//step B
|
|
330
|
+
int n = DetermineConsecutiveDigitCount(context.message(), context.currentPos());
|
|
331
|
+
if (n >= 2) {
|
|
332
|
+
context.addCodeword(EncodeASCIIDigits(context.currentChar(), context.nextChar()));
|
|
333
|
+
context.setCurrentPos(context.currentPos() + 2);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
int c = context.currentChar();
|
|
337
|
+
int newMode = LookAheadTest(context.message(), context.currentPos(), ASCII_ENCODATION);
|
|
338
|
+
if (newMode != ASCII_ENCODATION)
|
|
339
|
+
{
|
|
340
|
+
// the order here is the same as ENCODATION;
|
|
341
|
+
context.addCodeword(LATCHES[newMode]);
|
|
342
|
+
context.setNewEncoding(newMode);
|
|
343
|
+
}
|
|
344
|
+
else if (IsExtendedASCII(c)) {
|
|
345
|
+
context.addCodeword(UPPER_SHIFT);
|
|
346
|
+
context.addCodeword(static_cast<uint8_t>(c - 128 + 1));
|
|
347
|
+
context.setCurrentPos(context.currentPos() + 1);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
context.addCodeword(static_cast<uint8_t>(c + 1));
|
|
351
|
+
context.setCurrentPos(context.currentPos() + 1);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
} // ASCIIEncoder
|
|
357
|
+
|
|
358
|
+
namespace C40Encoder {
|
|
359
|
+
|
|
360
|
+
static int EncodeChar(int c, std::string& sb)
|
|
361
|
+
{
|
|
362
|
+
if (c == ' ') {
|
|
363
|
+
sb.push_back('\3');
|
|
364
|
+
return 1;
|
|
365
|
+
}
|
|
366
|
+
if (IsDigit(c)) {
|
|
367
|
+
sb.push_back((char)(c - 48 + 4));
|
|
368
|
+
return 1;
|
|
369
|
+
}
|
|
370
|
+
if (IsUpper(c)) {
|
|
371
|
+
sb.push_back((char)(c - 65 + 14));
|
|
372
|
+
return 1;
|
|
373
|
+
}
|
|
374
|
+
if (c >= '\0' && c <= '\x1f') {
|
|
375
|
+
sb.push_back('\0'); //Shift 1 Set
|
|
376
|
+
sb.push_back(c);
|
|
377
|
+
return 2;
|
|
378
|
+
}
|
|
379
|
+
if (c <= '/') {
|
|
380
|
+
sb.push_back('\1'); //Shift 2 Set
|
|
381
|
+
sb.push_back((char)(c - 33));
|
|
382
|
+
return 2;
|
|
383
|
+
}
|
|
384
|
+
if (c <= '@') {
|
|
385
|
+
sb.push_back('\1'); //Shift 2 Set
|
|
386
|
+
sb.push_back((char)(c - 58 + 15));
|
|
387
|
+
return 2;
|
|
388
|
+
}
|
|
389
|
+
if (c <= '_') {
|
|
390
|
+
sb.push_back('\1'); //Shift 2 Set
|
|
391
|
+
sb.push_back((char)(c - 91 + 22));
|
|
392
|
+
return 2;
|
|
393
|
+
}
|
|
394
|
+
if (c <= '\x7f') {
|
|
395
|
+
sb.push_back('\2'); //Shift 3 Set
|
|
396
|
+
sb.push_back((char)(c - 96));
|
|
397
|
+
return 2;
|
|
398
|
+
}
|
|
399
|
+
sb.append("\1\x1e"); //Shift 2, Upper Shift
|
|
400
|
+
int len = 2;
|
|
401
|
+
len += EncodeChar((char)(c - 0x80), sb);
|
|
402
|
+
return len;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
static int BacktrackOneCharacter(EncoderContext& context, std::string& buffer, std::string& removed, int lastCharSize,
|
|
406
|
+
const std::function<int(int, std::string&)>& encodeChar)
|
|
407
|
+
{
|
|
408
|
+
buffer.resize(buffer.size() - lastCharSize);
|
|
409
|
+
context.setCurrentPos(context.currentPos() - 1);
|
|
410
|
+
int c = context.currentChar();
|
|
411
|
+
lastCharSize = encodeChar(c, removed);
|
|
412
|
+
context.resetSymbolInfo(); //Deal with possible reduction in symbol size
|
|
413
|
+
return lastCharSize;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
static void EncodeToCodewords(EncoderContext& context, const std::string& sb, int startPos) {
|
|
417
|
+
int c1 = sb.at(startPos);
|
|
418
|
+
int c2 = sb.at(startPos + 1);
|
|
419
|
+
int c3 = sb.at(startPos + 2);
|
|
420
|
+
int v = (1600 * c1) + (40 * c2) + c3 + 1;
|
|
421
|
+
context.addCodeword(narrow_cast<uint8_t>(v / 256));
|
|
422
|
+
context.addCodeword(narrow_cast<uint8_t>(v % 256));
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
static void WriteNextTriplet(EncoderContext& context, std::string& buffer)
|
|
426
|
+
{
|
|
427
|
+
EncodeToCodewords(context, buffer, 0);
|
|
428
|
+
buffer.erase(0, 3);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Handle "end of data" situations
|
|
433
|
+
*
|
|
434
|
+
* @param context the encoder context
|
|
435
|
+
* @param buffer the buffer with the remaining encoded characters
|
|
436
|
+
*/
|
|
437
|
+
static void HandleEOD(EncoderContext& context, std::string& buffer)
|
|
438
|
+
{
|
|
439
|
+
int unwritten = (Size(buffer) / 3) * 2;
|
|
440
|
+
int rest = Size(buffer) % 3;
|
|
441
|
+
|
|
442
|
+
int curCodewordCount = context.codewordCount() + unwritten;
|
|
443
|
+
auto symbolInfo = context.updateSymbolInfo(curCodewordCount);
|
|
444
|
+
int available = symbolInfo->dataCapacity() - curCodewordCount;
|
|
445
|
+
|
|
446
|
+
if (rest == 2) {
|
|
447
|
+
buffer.push_back('\0'); //Shift 1
|
|
448
|
+
while (buffer.length() >= 3) {
|
|
449
|
+
WriteNextTriplet(context, buffer);
|
|
450
|
+
}
|
|
451
|
+
if (context.hasMoreCharacters()) {
|
|
452
|
+
context.addCodeword(C40_UNLATCH);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
else if (available == 1 && rest == 1) {
|
|
456
|
+
while (buffer.length() >= 3) {
|
|
457
|
+
WriteNextTriplet(context, buffer);
|
|
458
|
+
}
|
|
459
|
+
if (context.hasMoreCharacters()) {
|
|
460
|
+
context.addCodeword(C40_UNLATCH);
|
|
461
|
+
}
|
|
462
|
+
// else no unlatch
|
|
463
|
+
context.setCurrentPos(context.currentPos() - 1);
|
|
464
|
+
}
|
|
465
|
+
else if (rest == 0) {
|
|
466
|
+
while (buffer.length() >= 3) {
|
|
467
|
+
WriteNextTriplet(context, buffer);
|
|
468
|
+
}
|
|
469
|
+
if (available > 0 || context.hasMoreCharacters()) {
|
|
470
|
+
context.addCodeword(C40_UNLATCH);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
throw std::logic_error("Unexpected case. Please report!");
|
|
475
|
+
}
|
|
476
|
+
context.setNewEncoding(ASCII_ENCODATION);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
static void EncodeC40(EncoderContext& context, const std::function<int (int, std::string&)>& encodeChar, int encodingMode)
|
|
480
|
+
{
|
|
481
|
+
//step C
|
|
482
|
+
std::string buffer;
|
|
483
|
+
while (context.hasMoreCharacters()) {
|
|
484
|
+
int c = context.currentChar();
|
|
485
|
+
context.setCurrentPos(context.currentPos() + 1);
|
|
486
|
+
int lastCharSize = encodeChar(c, buffer);
|
|
487
|
+
int unwritten = narrow_cast<int>(buffer.length() / 3) * 2;
|
|
488
|
+
int curCodewordCount = context.codewordCount() + unwritten;
|
|
489
|
+
auto symbolInfo = context.updateSymbolInfo(curCodewordCount);
|
|
490
|
+
int available = symbolInfo->dataCapacity() - curCodewordCount;
|
|
491
|
+
|
|
492
|
+
if (!context.hasMoreCharacters()) {
|
|
493
|
+
//Avoid having a single C40 value in the last triplet
|
|
494
|
+
std::string removed;
|
|
495
|
+
if ((buffer.length() % 3) == 2 && available != 2) {
|
|
496
|
+
lastCharSize = BacktrackOneCharacter(context, buffer, removed, lastCharSize, encodeChar);
|
|
497
|
+
}
|
|
498
|
+
while ((buffer.length() % 3) == 1 && ((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) {
|
|
499
|
+
lastCharSize = BacktrackOneCharacter(context, buffer, removed, lastCharSize, encodeChar);
|
|
500
|
+
}
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if ((buffer.length() % 3) == 0) {
|
|
505
|
+
int newMode = LookAheadTest(context.message(), context.currentPos(), encodingMode);
|
|
506
|
+
if (newMode != encodingMode) {
|
|
507
|
+
// Return to ASCII encodation, which will actually handle latch to new mode
|
|
508
|
+
context.setNewEncoding(ASCII_ENCODATION);
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return HandleEOD(context, buffer);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
static void EncodeC40(EncoderContext& context)
|
|
517
|
+
{
|
|
518
|
+
EncodeC40(context, EncodeChar, C40_ENCODATION);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
} // C40Encoder
|
|
522
|
+
|
|
523
|
+
namespace DMTextEncoder {
|
|
524
|
+
|
|
525
|
+
static int EncodeChar(int c, std::string& sb)
|
|
526
|
+
{
|
|
527
|
+
if (c == ' ') {
|
|
528
|
+
sb.push_back('\3');
|
|
529
|
+
return 1;
|
|
530
|
+
}
|
|
531
|
+
if (IsDigit(c)) {
|
|
532
|
+
sb.push_back((char)(c - 48 + 4));
|
|
533
|
+
return 1;
|
|
534
|
+
}
|
|
535
|
+
if (IsLower(c)) {
|
|
536
|
+
sb.push_back((char)(c - 97 + 14));
|
|
537
|
+
return 1;
|
|
538
|
+
}
|
|
539
|
+
if (c >= '\0' && c <= '\x1f') {
|
|
540
|
+
sb.push_back('\0'); //Shift 1 Set
|
|
541
|
+
sb.push_back(c);
|
|
542
|
+
return 2;
|
|
543
|
+
}
|
|
544
|
+
if (c <= '/') {
|
|
545
|
+
sb.push_back('\1'); //Shift 2 Set
|
|
546
|
+
sb.push_back((char)(c - 33));
|
|
547
|
+
return 2;
|
|
548
|
+
}
|
|
549
|
+
if (c <= '@') {
|
|
550
|
+
sb.push_back('\1'); //Shift 2 Set
|
|
551
|
+
sb.push_back((char)(c - 58 + 15));
|
|
552
|
+
return 2;
|
|
553
|
+
}
|
|
554
|
+
if (c >= '[' && c <= '_') {
|
|
555
|
+
sb.push_back('\1'); //Shift 2 Set
|
|
556
|
+
sb.push_back((char)(c - 91 + 22));
|
|
557
|
+
return 2;
|
|
558
|
+
}
|
|
559
|
+
if (c == '\x60') {
|
|
560
|
+
sb.push_back('\2'); //Shift 3 Set
|
|
561
|
+
sb.push_back((char)(c - 96));
|
|
562
|
+
return 2;
|
|
563
|
+
}
|
|
564
|
+
if (c <= 'Z') {
|
|
565
|
+
sb.push_back('\2'); //Shift 3 Set
|
|
566
|
+
sb.push_back((char)(c - 65 + 1));
|
|
567
|
+
return 2;
|
|
568
|
+
}
|
|
569
|
+
if (c <= '\x7f') {
|
|
570
|
+
sb.push_back('\2'); //Shift 3 Set
|
|
571
|
+
sb.push_back((char)(c - 123 + 27));
|
|
572
|
+
return 2;
|
|
573
|
+
}
|
|
574
|
+
sb.append("\1\x1e"); //Shift 2, Upper Shift
|
|
575
|
+
int len = 2;
|
|
576
|
+
len += EncodeChar(c - 128, sb);
|
|
577
|
+
return len;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
static void EncodeText(EncoderContext& context)
|
|
581
|
+
{
|
|
582
|
+
C40Encoder::EncodeC40(context, EncodeChar, TEXT_ENCODATION);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
} // DMTextEncoder
|
|
586
|
+
|
|
587
|
+
namespace X12Encoder {
|
|
588
|
+
|
|
589
|
+
static int EncodeChar(int c, std::string& sb)
|
|
590
|
+
{
|
|
591
|
+
switch (c) {
|
|
592
|
+
case '\r': sb.push_back('\0'); break;
|
|
593
|
+
case '*': sb.push_back('\1'); break;
|
|
594
|
+
case '>': sb.push_back('\2'); break;
|
|
595
|
+
case ' ': sb.push_back('\3'); break;
|
|
596
|
+
default:
|
|
597
|
+
if (IsDigit(c)) {
|
|
598
|
+
sb.push_back((char)(c - 48 + 4));
|
|
599
|
+
} else if (IsUpper(c)) {
|
|
600
|
+
sb.push_back((char)(c - 65 + 14));
|
|
601
|
+
} else {
|
|
602
|
+
throw std::invalid_argument("Illegal character: " + ToHexString(c));
|
|
603
|
+
}
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
return 1;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
static void HandleEOD(EncoderContext& context, std::string& buffer)
|
|
610
|
+
{
|
|
611
|
+
int codewordCount = context.codewordCount();
|
|
612
|
+
auto symbolInfo = context.updateSymbolInfo(codewordCount);
|
|
613
|
+
int available = symbolInfo->dataCapacity() - codewordCount;
|
|
614
|
+
context.setCurrentPos(context.currentPos() - Size(buffer));
|
|
615
|
+
if (context.remainingCharacters() > 1 || available > 1 || context.remainingCharacters() != available) {
|
|
616
|
+
context.addCodeword(X12_UNLATCH);
|
|
617
|
+
}
|
|
618
|
+
if (context.newEncoding() < 0) {
|
|
619
|
+
context.setNewEncoding(ASCII_ENCODATION);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
static void EncodeX12(EncoderContext& context)
|
|
624
|
+
{
|
|
625
|
+
//step C
|
|
626
|
+
std::string buffer;
|
|
627
|
+
while (context.hasMoreCharacters()) {
|
|
628
|
+
int c = context.currentChar();
|
|
629
|
+
context.setCurrentPos(context.currentPos() + 1);
|
|
630
|
+
EncodeChar(c, buffer);
|
|
631
|
+
size_t count = buffer.length();
|
|
632
|
+
if ((count % 3) == 0) {
|
|
633
|
+
C40Encoder::WriteNextTriplet(context, buffer);
|
|
634
|
+
|
|
635
|
+
int newMode = LookAheadTest(context.message(), context.currentPos(), X12_ENCODATION);
|
|
636
|
+
if (newMode != X12_ENCODATION) {
|
|
637
|
+
// Return to ASCII encodation, which will actually handle latch to new mode
|
|
638
|
+
context.setNewEncoding(ASCII_ENCODATION);
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
HandleEOD(context, buffer);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
} // X12Encoder
|
|
647
|
+
|
|
648
|
+
namespace EdifactEncoder {
|
|
649
|
+
|
|
650
|
+
static void EncodeChar(int c, std::string& sb)
|
|
651
|
+
{
|
|
652
|
+
if (c >= ' ' && c <= '?') {
|
|
653
|
+
sb.push_back(c);
|
|
654
|
+
}
|
|
655
|
+
else if (c >= '@' && c <= '^') {
|
|
656
|
+
sb.push_back((char)(c - 64));
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
throw std::invalid_argument("Illegal character: " + ToHexString(c));
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
static ByteArray EncodeToCodewords(const std::string& sb, int startPos)
|
|
664
|
+
{
|
|
665
|
+
int len = Size(sb) - startPos;
|
|
666
|
+
if (len == 0) {
|
|
667
|
+
throw std::invalid_argument("buffer must not be empty");
|
|
668
|
+
}
|
|
669
|
+
int c1 = sb.at(startPos);
|
|
670
|
+
int c2 = len >= 2 ? sb.at(startPos + 1) : 0;
|
|
671
|
+
int c3 = len >= 3 ? sb.at(startPos + 2) : 0;
|
|
672
|
+
int c4 = len >= 4 ? sb.at(startPos + 3) : 0;
|
|
673
|
+
|
|
674
|
+
int v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4;
|
|
675
|
+
uint8_t cw1 = (v >> 16) & 255;
|
|
676
|
+
uint8_t cw2 = (v >> 8) & 255;
|
|
677
|
+
uint8_t cw3 = v & 255;
|
|
678
|
+
ByteArray res;
|
|
679
|
+
res.reserve(3);
|
|
680
|
+
res.push_back(cw1);
|
|
681
|
+
if (len >= 2) {
|
|
682
|
+
res.push_back(cw2);
|
|
683
|
+
}
|
|
684
|
+
if (len >= 3) {
|
|
685
|
+
res.push_back(cw3);
|
|
686
|
+
}
|
|
687
|
+
return res;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Handle "end of data" situations
|
|
692
|
+
*
|
|
693
|
+
* @param context the encoder context
|
|
694
|
+
* @param buffer the buffer with the remaining encoded characters
|
|
695
|
+
*/
|
|
696
|
+
static void HandleEOD(EncoderContext& context, std::string& buffer)
|
|
697
|
+
{
|
|
698
|
+
try {
|
|
699
|
+
size_t count = buffer.length();
|
|
700
|
+
if (count == 0) {
|
|
701
|
+
return; //Already finished
|
|
702
|
+
}
|
|
703
|
+
if (count == 1) {
|
|
704
|
+
//Only an unlatch at the end
|
|
705
|
+
int codewordCount = context.codewordCount();
|
|
706
|
+
auto symbolInfo = context.updateSymbolInfo(codewordCount);
|
|
707
|
+
int available = symbolInfo->dataCapacity() - codewordCount;
|
|
708
|
+
int remaining = context.remainingCharacters();
|
|
709
|
+
// The following two lines are a hack inspired by the 'fix' from https://sourceforge.net/p/barcode4j/svn/221/
|
|
710
|
+
if (remaining > available)
|
|
711
|
+
available = context.updateSymbolInfo(codewordCount+1)->dataCapacity() - codewordCount;
|
|
712
|
+
if (remaining <= available && available <= 2) {
|
|
713
|
+
return; //No unlatch
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (count > 4) {
|
|
718
|
+
throw std::invalid_argument("Count must not exceed 4");
|
|
719
|
+
}
|
|
720
|
+
int restChars = static_cast<int>(count - 1);
|
|
721
|
+
auto encoded = EncodeToCodewords(buffer, 0);
|
|
722
|
+
bool endOfSymbolReached = !context.hasMoreCharacters();
|
|
723
|
+
bool restInAscii = endOfSymbolReached && restChars <= 2;
|
|
724
|
+
|
|
725
|
+
if (restChars <= 2) {
|
|
726
|
+
int codewordCount = context.codewordCount();
|
|
727
|
+
auto symbolInfo = context.updateSymbolInfo(codewordCount + restChars);
|
|
728
|
+
int available = symbolInfo->dataCapacity() - codewordCount;
|
|
729
|
+
if (available >= 3) {
|
|
730
|
+
restInAscii = false;
|
|
731
|
+
context.updateSymbolInfo(codewordCount + Size(encoded));
|
|
732
|
+
//available = context.symbolInfo.dataCapacity - context.getCodewordCount();
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
if (restInAscii) {
|
|
737
|
+
context.resetSymbolInfo();
|
|
738
|
+
context.setCurrentPos(context.currentPos() - restChars);
|
|
739
|
+
}
|
|
740
|
+
else {
|
|
741
|
+
for (uint8_t cw : encoded) {
|
|
742
|
+
context.addCodeword(cw);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
catch (...) {
|
|
747
|
+
context.setNewEncoding(ASCII_ENCODATION);
|
|
748
|
+
throw;
|
|
749
|
+
}
|
|
750
|
+
context.setNewEncoding(ASCII_ENCODATION);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
static void EncodeEdifact(EncoderContext& context)
|
|
754
|
+
{
|
|
755
|
+
//step F
|
|
756
|
+
std::string buffer;
|
|
757
|
+
while (context.hasMoreCharacters()) {
|
|
758
|
+
int c = context.currentChar();
|
|
759
|
+
EncodeChar(c, buffer);
|
|
760
|
+
context.setCurrentPos(context.currentPos() + 1);
|
|
761
|
+
|
|
762
|
+
if (buffer.length() >= 4) {
|
|
763
|
+
auto codewords = EncodeToCodewords(buffer, 0);
|
|
764
|
+
for (uint8_t cw : codewords) {
|
|
765
|
+
context.addCodeword(cw);
|
|
766
|
+
}
|
|
767
|
+
buffer.erase(0, 4);
|
|
768
|
+
|
|
769
|
+
int newMode = LookAheadTest(context.message(), context.currentPos(), EDIFACT_ENCODATION);
|
|
770
|
+
if (newMode != EDIFACT_ENCODATION) {
|
|
771
|
+
// Return to ASCII encodation, which will actually handle latch to new mode
|
|
772
|
+
context.setNewEncoding(ASCII_ENCODATION);
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
buffer.push_back(31); //Unlatch
|
|
778
|
+
HandleEOD(context, buffer);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
} // EdifactEncoder
|
|
782
|
+
|
|
783
|
+
namespace Base256Encoder {
|
|
784
|
+
|
|
785
|
+
static int Randomize255State(int ch, int codewordPosition)
|
|
786
|
+
{
|
|
787
|
+
int pseudoRandom = ((149 * codewordPosition) % 255) + 1;
|
|
788
|
+
int tempVariable = ch + pseudoRandom;
|
|
789
|
+
if (tempVariable <= 255) {
|
|
790
|
+
return tempVariable;
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
return tempVariable - 256;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
static void EncodeBase256(EncoderContext& context)
|
|
798
|
+
{
|
|
799
|
+
std::string buffer;
|
|
800
|
+
buffer.push_back('\0'); //Initialize length field
|
|
801
|
+
while (context.hasMoreCharacters()) {
|
|
802
|
+
int c = context.currentChar();
|
|
803
|
+
buffer.push_back(c);
|
|
804
|
+
|
|
805
|
+
context.setCurrentPos(context.currentPos() + 1);
|
|
806
|
+
|
|
807
|
+
int newMode = LookAheadTest(context.message(), context.currentPos(), BASE256_ENCODATION);
|
|
808
|
+
if (newMode != BASE256_ENCODATION) {
|
|
809
|
+
// Return to ASCII encodation, which will actually handle latch to new mode
|
|
810
|
+
context.setNewEncoding(ASCII_ENCODATION);
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
int dataCount = Size(buffer) - 1;
|
|
815
|
+
int lengthFieldSize = 1;
|
|
816
|
+
int currentSize = context.codewordCount() + dataCount + lengthFieldSize;
|
|
817
|
+
auto symbolInfo = context.updateSymbolInfo(currentSize);
|
|
818
|
+
bool mustPad = (symbolInfo->dataCapacity() - currentSize) > 0;
|
|
819
|
+
if (context.hasMoreCharacters() || mustPad) {
|
|
820
|
+
if (dataCount <= 249) {
|
|
821
|
+
buffer.at(0) = (char)dataCount;
|
|
822
|
+
}
|
|
823
|
+
else if (dataCount <= 1555) {
|
|
824
|
+
buffer.at(0) = (char)((dataCount / 250) + 249);
|
|
825
|
+
buffer.insert(1, 1, (char)(dataCount % 250));
|
|
826
|
+
}
|
|
827
|
+
else {
|
|
828
|
+
throw std::invalid_argument("Message length not in valid ranges: " + std::to_string(dataCount));
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
for (char c : buffer) {
|
|
832
|
+
context.addCodeword(Randomize255State(c, context.codewordCount() + 1));
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
} // Base256Encoder
|
|
837
|
+
|
|
838
|
+
ByteArray Encode(const std::wstring& msg)
|
|
839
|
+
{
|
|
840
|
+
return Encode(msg, CharacterSet::ISO8859_1, SymbolShape::NONE, -1, -1, -1, -1);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Performs message encoding of a DataMatrix message using the algorithm described in annex P
|
|
845
|
+
* of ISO/IEC 16022:2000(E).
|
|
846
|
+
*
|
|
847
|
+
* @param msg the message
|
|
848
|
+
* @param shape requested shape. May be {@code SymbolShapeHint.FORCE_NONE},
|
|
849
|
+
* {@code SymbolShapeHint.FORCE_SQUARE} or {@code SymbolShapeHint.FORCE_RECTANGLE}.
|
|
850
|
+
* @param minSize the minimum symbol size constraint or null for no constraint
|
|
851
|
+
* @param maxSize the maximum symbol size constraint or null for no constraint
|
|
852
|
+
* @return the encoded message (the char values range from 0 to 255)
|
|
853
|
+
*/
|
|
854
|
+
ByteArray Encode(const std::wstring& msg, CharacterSet charset, SymbolShape shape, int minWidth, int minHeight, int maxWidth, int maxHeight)
|
|
855
|
+
{
|
|
856
|
+
//the codewords 0..255 are encoded as Unicode characters
|
|
857
|
+
//Encoder[] encoders = {
|
|
858
|
+
// new ASCIIEncoder(), new C40Encoder(), new TextEncoder(),
|
|
859
|
+
// new X12Encoder(), new EdifactEncoder(), new Base256Encoder()
|
|
860
|
+
//};
|
|
861
|
+
|
|
862
|
+
if (charset == CharacterSet::Unknown) {
|
|
863
|
+
charset = CharacterSet::ISO8859_1;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
EncoderContext context(TextEncoder::FromUnicode(msg, charset));
|
|
867
|
+
context.setSymbolShape(shape);
|
|
868
|
+
context.setSizeConstraints(minWidth, minHeight, maxWidth, maxHeight);
|
|
869
|
+
|
|
870
|
+
constexpr std::wstring_view MACRO_05_HEADER = L"[)>\x1E""05\x1D";
|
|
871
|
+
constexpr std::wstring_view MACRO_06_HEADER = L"[)>\x1E""06\x1D";
|
|
872
|
+
constexpr std::wstring_view MACRO_TRAILER = L"\x1E\x04";
|
|
873
|
+
|
|
874
|
+
if (msg.starts_with(MACRO_05_HEADER) && msg.ends_with(MACRO_TRAILER)) {
|
|
875
|
+
context.addCodeword(MACRO_05);
|
|
876
|
+
context.setSkipAtEnd(2);
|
|
877
|
+
context.setCurrentPos(Size(MACRO_05_HEADER));
|
|
878
|
+
}
|
|
879
|
+
else if (msg.starts_with(MACRO_06_HEADER) && msg.ends_with(MACRO_TRAILER)) {
|
|
880
|
+
context.addCodeword(MACRO_06);
|
|
881
|
+
context.setSkipAtEnd(2);
|
|
882
|
+
context.setCurrentPos(Size(MACRO_06_HEADER));
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
int encodingMode = ASCII_ENCODATION; //Default mode
|
|
886
|
+
while (context.hasMoreCharacters()) {
|
|
887
|
+
switch (encodingMode) {
|
|
888
|
+
case ASCII_ENCODATION: ASCIIEncoder::EncodeASCII(context); break;
|
|
889
|
+
case C40_ENCODATION: C40Encoder::EncodeC40(context); break;
|
|
890
|
+
case TEXT_ENCODATION: DMTextEncoder::EncodeText(context); break;
|
|
891
|
+
case X12_ENCODATION: X12Encoder::EncodeX12(context); break;
|
|
892
|
+
case EDIFACT_ENCODATION: EdifactEncoder::EncodeEdifact(context); break;
|
|
893
|
+
case BASE256_ENCODATION: Base256Encoder::EncodeBase256(context); break;
|
|
894
|
+
}
|
|
895
|
+
if (context.newEncoding() >= 0) {
|
|
896
|
+
encodingMode = context.newEncoding();
|
|
897
|
+
context.clearNewEncoding();
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
int len = context.codewordCount();
|
|
901
|
+
auto symbolInfo = context.updateSymbolInfo(len);
|
|
902
|
+
int capacity = symbolInfo->dataCapacity();
|
|
903
|
+
if (len < capacity) {
|
|
904
|
+
if (encodingMode != ASCII_ENCODATION && encodingMode != BASE256_ENCODATION && encodingMode != EDIFACT_ENCODATION) {
|
|
905
|
+
context.addCodeword('\xfe'); //Unlatch (254)
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
//Padding
|
|
909
|
+
if (context.codewordCount() < capacity) {
|
|
910
|
+
context.addCodeword(PAD);
|
|
911
|
+
}
|
|
912
|
+
while (context.codewordCount() < capacity) {
|
|
913
|
+
context.addCodeword(Randomize253State(PAD, context.codewordCount() + 1));
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
return context.codewords();
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
} // namespace ZXing::DataMatrix
|