Skip to content

Commit

Permalink
net-im/kaidan: prepare for textproc/zxing-cpp 2.0.0
Browse files Browse the repository at this point in the history
Backported from upstream.
  • Loading branch information
tcberner committed Jan 10, 2023
1 parent 49c02cd commit cd55d84
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
26 changes: 26 additions & 0 deletions net-im/kaidan/files/patch-src_QrCodeDecoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- src/QrCodeDecoder.cpp.orig 2023-01-10 10:30:39 UTC
+++ src/QrCodeDecoder.cpp
@@ -60,7 +60,11 @@ void QrCodeDecoder::decodeImage(const QImage &image)
{
// Advise the decoder to check for QR codes and to try decoding rotated versions of the image.
#if ZXING_VERSION >= QT_VERSION_CHECK(1, 1, 0)
+# if ZXING_VERSION >= QT_VERSION_CHECK(1, 1, 1)
+ const auto decodeHints = DecodeHints().setFormats(BarcodeFormat::QRCode);
+# else
const auto decodeHints = DecodeHints().setFormats(BarcodeFormat::QR_CODE);
+# endif
const auto result = ReadBarcode({image.bits(), image.width(), image.height(), ZXing::ImageFormat::Lum, image.bytesPerLine()}, decodeHints);
#else
const auto decodeHints =
@@ -77,7 +81,11 @@ void QrCodeDecoder::decodeImage(const QImage &image)
// If a QR code could be found and decoded, emit a signal with the decoded string.
// Otherwise, emit a signal for failed decoding.
if (result.isValid())
+#if ZXING_VERSION < QT_VERSION_CHECK(2, 0, 0)
emit decodingSucceeded(QString::fromStdString(TextUtfEncoding::ToUtf8(result.text())));
+#else
+ emit decodingSucceeded(QString::fromStdString(result.text()));
+#endif
else
emit decodingFailed();
}
25 changes: 25 additions & 0 deletions net-im/kaidan/files/patch-src_QrCodeGenerator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- src/QrCodeGenerator.cpp.orig 2023-01-10 10:34:19 UTC
+++ src/QrCodeGenerator.cpp
@@ -33,6 +33,10 @@
#include <QImage>
#include <QRgb>

+#include <ZXing/ZXVersion.h>
+#define ZXING_VERSION \
+ QT_VERSION_CHECK(ZXING_VERSION_MAJOR, ZXING_VERSION_MINOR, ZXING_VERSION_PATCH)
+
#include <ZXing/BarcodeFormat.h>
#include <ZXing/MultiFormatWriter.h>

@@ -74,7 +78,11 @@ QImage QrCodeGenerator::generateQrCode(int edgePixelCo
QImage QrCodeGenerator::generateQrCode(int edgePixelCount, const QString &text)
{
try {
+#if ZXING_VERSION >= QT_VERSION_CHECK(1, 1, 1)
+ ZXing::MultiFormatWriter writer(ZXing::BarcodeFormat::QRCode);
+#else
ZXing::MultiFormatWriter writer(ZXing::BarcodeFormat::QR_CODE);
+#endif
const ZXing::BitMatrix &bitMatrix = writer.encode(text.toStdWString(), edgePixelCount, edgePixelCount);
return toImage(bitMatrix);
} catch (const std::invalid_argument &e) {

0 comments on commit cd55d84

Please sign in to comment.