File indexing completed on 2024-05-12 15:49:08
0001 /* 0002 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: MIT 0004 */ 0005 0006 #ifndef PRISON_ZXINGONEDBARCODE_H 0007 #define PRISON_ZXINGONEDBARCODE_H 0008 0009 #include "abstractbarcode.h" 0010 #include "zxingutil_p.h" 0011 0012 #include <QVariant> 0013 0014 #include <ZXing/BitMatrix.h> 0015 #include <ZXing/MultiFormatWriter.h> 0016 0017 #include <stdexcept> 0018 0019 namespace Prison 0020 { 0021 /** Generic support for ZXing 1D barcodes. */ 0022 template<ZXing::BarcodeFormat Format> 0023 class ZXingOneDBarcode : public AbstractBarcode 0024 { 0025 public: 0026 explicit inline ZXingOneDBarcode() 0027 : AbstractBarcode(AbstractBarcode::OneDimension) 0028 { 0029 } 0030 0031 protected: 0032 inline QImage paintImage(const QSizeF &) override 0033 { 0034 try { 0035 ZXing::MultiFormatWriter writer(Format); 0036 const auto matrix = writer.encode(ZXingUtil::toStdWString(data().isEmpty() ? QVariant(byteArrayData()) : QVariant(data())), 1, 1); 0037 return ZXingUtil::toImage(matrix, foregroundColor(), backgroundColor()); 0038 } catch (const std::invalid_argument &e) { 0039 }; // input too large or incompatible 0040 return {}; 0041 } 0042 }; 0043 0044 } 0045 0046 #endif // PRISON_PDF417BARCODE_H