config_host/config_zxing.h.in          |    2 ++
 configure.ac                           |   21 +++++++++++++++++++++
 cui/source/dialogs/QrCodeGenDialog.cxx |   10 ++++++++++
 3 files changed, 33 insertions(+)

New commits:
commit 8dbbeadbc7eabe76736d37fe3bcafe3e537f0bc0
Author:     TRaXIn <raghav.29.kha...@gmail.com>
AuthorDate: Sat Feb 25 17:03:27 2023 +0530
Commit:     Hossein <hoss...@libreoffice.org>
CommitDate: Wed Jul 5 15:33:08 2023 +0200

    tdf#153328 ZXing::ToSVG() Conditional usage
    
    Change-Id: I8874f596be808d5d255139654a19b25f71299179
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147677
    Tested-by: Jenkins
    Tested-by: Hossein <hoss...@libreoffice.org>
    Reviewed-by: Hossein <hoss...@libreoffice.org>

diff --git a/config_host/config_zxing.h.in b/config_host/config_zxing.h.in
index 6463cb6b4fd1..01b5400c686d 100644
--- a/config_host/config_zxing.h.in
+++ b/config_host/config_zxing.h.in
@@ -12,6 +12,8 @@
 
 #define ENABLE_ZXING 0
 
+#define HAVE_ZXING_TOSVG 0
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/configure.ac b/configure.ac
index 59703a6932e3..80f2e5aa54f9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11223,10 +11223,31 @@ else
         AC_MSG_RESULT([internal])
         SYSTEM_ZXING=
         BUILD_TYPE="$BUILD_TYPE ZXING"
+        ZXING_CFLAGS="-I${WORKDIR}/UnpackedTarball/zxing/core/src"
     fi
     if test "$ENABLE_ZXING" = TRUE; then
         AC_DEFINE(ENABLE_ZXING)
     fi
+    AC_MSG_CHECKING([whether zxing::tosvg function is available])
+    AC_LANG_PUSH([C++])
+    save_CXXFLAGS=$CXXFLAGS
+    CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11 $ZXING_CFLAGS"
+    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
+            #include <BitMatrix.h>
+            #include <BitMatrixIO.h>
+            int main(){
+                ZXing::BitMatrix matrix(1, 1);
+                matrix.set(0, 0, true);
+                ZXing::ToSVG(matrix);
+                return 0;
+            }
+        ])], [
+            AC_DEFINE([HAVE_ZXING_TOSVG],[1])
+            AC_MSG_RESULT([yes])
+        ], [AC_MSG_RESULT([no])])
+    CXXFLAGS=$save_CXXFLAGS
+    AC_LANG_POP([C++])
+    AC_SUBST(HAVE_ZXING_TOSVG)
 fi
 AC_SUBST(SYSTEM_ZXING)
 AC_SUBST(ENABLE_ZXING)
diff --git a/cui/source/dialogs/QrCodeGenDialog.cxx 
b/cui/source/dialogs/QrCodeGenDialog.cxx
index 6982ca7f8e69..887ccaf44de4 100644
--- a/cui/source/dialogs/QrCodeGenDialog.cxx
+++ b/cui/source/dialogs/QrCodeGenDialog.cxx
@@ -35,6 +35,10 @@
 #pragma GCC diagnostic pop
 #endif
 
+#if HAVE_ZXING_TOSVG
+#include <BitMatrixIO.h>
+#endif
+
 #endif // ENABLE_ZXING
 
 #include <com/sun/star/beans/XPropertySet.hpp>
@@ -73,6 +77,7 @@ namespace
 {
 #if ENABLE_ZXING
 // Implementation adapted from the answer: 
https://stackoverflow.com/questions/10789059/create-qr-code-in-vector-image/60638350#60638350
+#if !HAVE_ZXING_TOSVG
 OString ConvertToSVGFormat(const ZXing::BitMatrix& bitmatrix)
 {
     OStringBuffer sb;
@@ -96,6 +101,7 @@ OString ConvertToSVGFormat(const ZXing::BitMatrix& bitmatrix)
     sb.append("\"/>\n</svg>");
     return sb.toString();
 }
+#endif
 
 std::string GetBarCodeType(int type)
 {
@@ -143,7 +149,11 @@ OString GenerateQRCode(std::u16string_view aQRText, 
tools::Long aQRECC, int aQRB
     auto writer = 
ZXing::MultiFormatWriter(format).setMargin(aQRBorder).setEccLevel(bqrEcc);
     writer.setEncoding(ZXing::CharacterSet::UTF8);
     ZXing::BitMatrix bitmatrix = 
writer.encode(ZXing::TextUtfEncoding::FromUtf8(QRText), 0, 0);
+#if HAVE_ZXING_TOSVG
+    return OString(ZXing::ToSVG(bitmatrix));
+#else
     return ConvertToSVGFormat(bitmatrix);
+#endif
 }
 #endif
 

Reply via email to