You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
3.2 KiB
92 lines
3.2 KiB
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: I26813ca12967a52a30b0032965cf707dbee4b59a
|
|
---
|
|
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 b3aa9d6cb566..5895bfc26af2 100644
|
|
--- a/configure.ac
|
|
+++ b/configure.ac
|
|
@@ -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/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 28bbfabcf845..7db4bc74da16 100644
|
|
--- a/cui/source/dialogs/QrCodeGenDialog.cxx
|
|
+++ b/cui/source/dialogs/QrCodeGenDialog.cxx
|
|
@@ -19,7 +19,7 @@
|
|
|
|
#if ENABLE_QRCODEGEN
|
|
#if defined(SYSTEM_QRCODEGEN)
|
|
-#include <qrcodegen/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.31.1
|
|
|