diff options
Diffstat (limited to 'cui/source/dialogs/QrCodeGenDialog.cxx')
-rw-r--r-- | cui/source/dialogs/QrCodeGenDialog.cxx | 63 |
1 files changed, 55 insertions, 8 deletions
diff --git a/cui/source/dialogs/QrCodeGenDialog.cxx b/cui/source/dialogs/QrCodeGenDialog.cxx index 0e24ded70cd1..d99290404629 100644 --- a/cui/source/dialogs/QrCodeGenDialog.cxx +++ b/cui/source/dialogs/QrCodeGenDialog.cxx @@ -19,6 +19,7 @@ #include <vcl/svapp.hxx> #if ENABLE_ZXING +#include <ZXVersion.h> #include <rtl/strbuf.hxx> #ifdef __GNUC__ @@ -27,15 +28,21 @@ #endif #include <BarcodeFormat.h> -#include <BitArray.h> #include <BitMatrix.h> #include <MultiFormatWriter.h> -#include <TextUtfEncoding.h> #ifdef __GNUC__ #pragma GCC diagnostic pop #endif +#if HAVE_ZXING_TOSVG +#include <BitMatrixIO.h> +#endif + +#if ZXING_VERSION_MAJOR < 2 +#include <TextUtfEncoding.h> +#endif + #endif // ENABLE_ZXING #include <com/sun/star/beans/XPropertySet.hpp> @@ -74,12 +81,12 @@ 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; const int width = bitmatrix.width(); const int height = bitmatrix.height(); - ZXing::BitArray row(width); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 " + OString::number(width) + " " + OString::number(height) @@ -87,10 +94,9 @@ OString ConvertToSVGFormat(const ZXing::BitMatrix& bitmatrix) "<path d=\""); for (int i = 0; i < height; ++i) { - bitmatrix.getRow(i, row); for (int j = 0; j < width; ++j) { - if (row.get(j)) + if (bitmatrix.get(j, i)) { sb.append("M" + OString::number(j) + "," + OString::number(i) + "h1v1h-1z"); } @@ -99,8 +105,9 @@ OString ConvertToSVGFormat(const ZXing::BitMatrix& bitmatrix) sb.append("\"/>\n</svg>"); return sb.toString(); } +#endif -std::string GetBarCodeType(const int& type) +std::string GetBarCodeType(int type) { switch (type) { @@ -141,12 +148,20 @@ OString GenerateQRCode(std::u16string_view aQRText, tools::Long aQRECC, int aQRB } OString o = OUStringToOString(aQRText, RTL_TEXTENCODING_UTF8); - std::string QRText(o.getStr(), o.getLength()); + std::string QRText(o); ZXing::BarcodeFormat format = ZXing::BarcodeFormatFromString(GetBarCodeType(aQRType)); auto writer = ZXing::MultiFormatWriter(format).setMargin(aQRBorder).setEccLevel(bqrEcc); writer.setEncoding(ZXing::CharacterSet::UTF8); +#if ZXING_VERSION_MAJOR >= 2 + ZXing::BitMatrix bitmatrix = writer.encode(QRText, 0, 0); +#else ZXing::BitMatrix bitmatrix = writer.encode(ZXing::TextUtfEncoding::FromUtf8(QRText), 0, 0); +#endif +#if HAVE_ZXING_TOSVG + return OString(ZXing::ToSVG(bitmatrix)); +#else return ConvertToSVGFormat(bitmatrix); +#endif } #endif @@ -156,7 +171,7 @@ QrCodeGenDialog::QrCodeGenDialog(weld::Widget* pParent, Reference<XModel> xModel bool bEditExisting) : GenericDialogController(pParent, "cui/ui/qrcodegen.ui", "QrCodeGenDialog") , m_xModel(std::move(xModel)) - , m_xEdittext(m_xBuilder->weld_entry("edit_text")) + , m_xEdittext(m_xBuilder->weld_text_view("edit_text")) , m_xECC{ m_xBuilder->weld_radio_button("button_low"), m_xBuilder->weld_radio_button("button_medium"), m_xBuilder->weld_radio_button("button_quartile"), @@ -167,6 +182,8 @@ QrCodeGenDialog::QrCodeGenDialog(weld::Widget* pParent, Reference<XModel> xModel , mpParent(pParent) #endif { + m_xEdittext->set_size_request(m_xEdittext->get_approximate_digit_width() * 28, + m_xEdittext->get_height_rows(6)); if (!bEditExisting) { // TODO: This only works in Writer doc. Should also work in shapes @@ -232,6 +249,36 @@ short QrCodeGenDialog::run() #endif } +bool QrCodeGenDialog::runAsync(const std::shared_ptr<QrCodeGenDialog>& rController, + const std::function<void(sal_Int32)>& rFunc) +{ +#if ENABLE_ZXING + + weld::GenericDialogController::runAsync(rController, [rController, rFunc](sal_Int32 nResult) { + if (nResult == RET_OK) + { + try + { + rController->Apply(); + } + catch (const std::exception&) + { + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( + rController->GetParent(), VclMessageType::Warning, VclButtonsType::Ok, + CuiResId(RID_CUISTR_QRCODEDATALONG))); + xBox->run(); + } + } + + rFunc(nResult); + }); +#else + (void)rController; + (void)rFunc; +#endif + return true; +} + void QrCodeGenDialog::Apply() { #if ENABLE_ZXING |