adapt to qr-code-generator 1.7.0
This commit is contained in:
parent
cff972b3db
commit
83acf4a028
@ -1,29 +1,29 @@
|
||||
From 2f11e4247b6332b06a5b23c33207fa10767244a6 Mon Sep 17 00:00:00 2001
|
||||
From: Thierry Vignaud <thierry.vignaud@gmail.com>
|
||||
Date: Thu, 30 Jan 2020 11:19:20 +0000
|
||||
From 83bf31d8befdcf006323966fb6a6d4a1f32c64da Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
|
||||
Date: Tue, 10 Aug 2021 09:19:04 +0100
|
||||
Subject: [PATCH] fix detecting qrcodegen
|
||||
|
||||
Change-Id: Ib945b57420083489273cefc5655eb50932b5a3f8
|
||||
Change-Id: I26813ca12967a52a30b0032965cf707dbee4b59a
|
||||
---
|
||||
configure.ac | 2 +-
|
||||
cui/source/dialogs/QrCodeGenDialog.cxx | 2 +-
|
||||
2 files changed, 2 insertions(+), 2 deletions(-)
|
||||
configure.ac | 2 +-
|
||||
cui/source/dialogs/QrCodeGenDialog.cxx | 39 ++++++++++++++++++++++++--
|
||||
2 files changed, 38 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/configure.ac b/configure.ac
|
||||
index 5a14369..ebd1b55 100644
|
||||
index b3aa9d6cb566..5895bfc26af2 100644
|
||||
--- a/configure.ac
|
||||
+++ b/configure.ac
|
||||
@@ -10250,7 +10250,7 @@ else
|
||||
@@ -10812,7 +10812,7 @@ else
|
||||
AC_MSG_RESULT([external])
|
||||
SYSTEM_QRCODEGEN=TRUE
|
||||
AC_LANG_PUSH([C++])
|
||||
- AC_CHECK_HEADER(qrcodegen/QrCode.hpp, [],
|
||||
+ AC_CHECK_HEADER(qrcodegencpp/QrCode.hpp, [],
|
||||
+ AC_CHECK_HEADER(qrcodegencpp/qrcodegen.hpp, [],
|
||||
[AC_MSG_ERROR(qrcodegen headers not found.)], [#include <stdexcept>])
|
||||
AC_CHECK_LIB([qrcodegencpp], [main], [:],
|
||||
[ AC_MSG_ERROR(qrcodegen C++ library not found.) ], [])
|
||||
diff --git a/cui/source/dialogs/QrCodeGenDialog.cxx b/cui/source/dialogs/QrCodeGenDialog.cxx
|
||||
index 7f3f6a8..b79a356 100644
|
||||
index 28bbfabcf845..7db4bc74da16 100644
|
||||
--- a/cui/source/dialogs/QrCodeGenDialog.cxx
|
||||
+++ b/cui/source/dialogs/QrCodeGenDialog.cxx
|
||||
@@ -19,7 +19,7 @@
|
||||
@ -31,10 +31,61 @@ index 7f3f6a8..b79a356 100644
|
||||
#if ENABLE_QRCODEGEN
|
||||
#if defined(SYSTEM_QRCODEGEN)
|
||||
-#include <qrcodegen/QrCode.hpp>
|
||||
+#include <qrcodegencpp/QrCode.hpp>
|
||||
+#include <qrcodegencpp/qrcodegen.hpp>
|
||||
#else
|
||||
#include <QrCode.hpp>
|
||||
#endif
|
||||
@@ -263,6 +263,41 @@ void QrCodeGenDialog::Apply()
|
||||
#endif
|
||||
}
|
||||
|
||||
+#if ENABLE_QRCODEGEN
|
||||
+static std::string toSvgString(const QrCode& qr, int border)
|
||||
+{
|
||||
+ if (border < 0)
|
||||
+ throw std::domain_error("Border must be non-negative");
|
||||
+ if (border > INT_MAX / 2 || border * 2 > INT_MAX - qr.getSize())
|
||||
+ throw std::overflow_error("Border too large");
|
||||
+
|
||||
+ std::ostringstream sb;
|
||||
+ sb << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
+ sb << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
|
||||
+ "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
||||
+ sb << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 ";
|
||||
+ sb << (qr.getSize() + border * 2) << " " << (qr.getSize() + border * 2)
|
||||
+ << "\" stroke=\"none\">\n";
|
||||
+ sb << "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
|
||||
+ sb << "\t<path d=\"";
|
||||
+ for (int y = 0; y < qr.getSize(); y++)
|
||||
+ {
|
||||
+ for (int x = 0; x < qr.getSize(); x++)
|
||||
+ {
|
||||
+ if (qr.getModule(x, y))
|
||||
+ {
|
||||
+ if (x != 0 || y != 0)
|
||||
+ sb << " ";
|
||||
+ sb << "M" << (x + border) << "," << (y + border) << "h1v1h-1z";
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ sb << "\" fill=\"#000000\"/>\n";
|
||||
+ sb << "</svg>\n";
|
||||
+ return sb.str();
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
OUString QrCodeGenDialog::GenerateQRCode(OUString aQRText, tools::Long aQRECC, int aQRBorder)
|
||||
{
|
||||
#if ENABLE_QRCODEGEN
|
||||
@@ -299,7 +334,7 @@ OUString QrCodeGenDialog::GenerateQRCode(OUString aQRText, tools::Long aQRECC, i
|
||||
|
||||
// From QR Code library
|
||||
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(qrtext, bqrEcc);
|
||||
- std::string svg = qr0.toSvgString(aQRBorder);
|
||||
+ std::string svg = toSvgString(qr0, aQRBorder);
|
||||
//cstring to OUString
|
||||
return OUString::createFromAscii(svg.c_str());
|
||||
#else
|
||||
--
|
||||
2.26.2
|
||||
2.31.1
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user