QR code improvement – LibreOffice EasyHack

A QR code is a type of 2D barcode that is useful for encoding data, such as a URL, contact information and many other data types. One can scan the code via applications on mobile phones to capture a URL or import contact information.

For example, the code below encodes the address of the LibreOffice website:

Encoding LibreOffice website URL with QR code

Encoding LibreOffice website’s URL in a QR code

Generating QR Codes in LibreOffice

In LibreOffice, it is possible to create different barcodes, either 1D or 2D, via extensions, or LibreOffice’s internal functionality.

QR code dialog

QR code dialog

For QR codes, it is possible to use the internal functionality via Insert > OLE Object > QR and Barcode:

The implementation in LibreOffice is using ZXing QR code library:

If you take a look at the source code in cui/source/dialogs/QrCodeGenDialog.cxx, there is ConvertToSVGFormat() function which creates the SVG output. In the recent versions of ZXing library (we use v1.4 right now), there is a function that does that, ZXing::ToSVG(). The task here is to replace the our function with the one from ZXing library.

Handling Different Library Versions

Unfortunately, only recent versions of ZXing provide ZXing::ToSVG() functions. It is not available in 1.3, but is added in 1.4. Looking into the packaging of the library in different distributions, it becomes obvious that this package version is not available yet in many distributions:

Therefore, a solution should check the ZXing library version, and use the new function if the library version is >= 1.4. In other words, limiting the change to where the new version of the library is present is necessary. This is possible using compiler conditionals. It is important where one configures the LibreOffice compilation to use system provided ZXing library, using --with-system-zxing while invoking autogen.sh.

Final Notes

EasyHacks are good starting points for someone who wants to get started in LibreOffice development. This specific issue for improving QR code is filed as tdf#153328 in TDF’s Bugzilla. To understand how to get started with LibreOffice development, you can refer to our getting involved page in the TDF Wiki, or our video tutorial for getting started with LibreOffice development.

  1. 2 months ago
    • 2 months ago