From 83bf31d8befdcf006323966fb6a6d4a1f32c64da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= 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 ]) 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 +#include #else #include #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 << "\n"; + sb << "\n"; + sb << "\n"; + sb << "\t\n"; + sb << "\t\n"; + sb << "\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