Commit f410d52b authored by Volker Krause's avatar Volker Krause
Browse files

Consistently use JS ArrayBuffers in the ERA SSB script API

parent a94b7dc3
......@@ -11,6 +11,10 @@
#include <KItinerary/PdfDocument>
#include <QImage>
#include <QQmlEngine>
#include <private/qv4arraybuffer_p.h>
#include <private/qv4engine_p.h>
using namespace KItinerary;
......@@ -29,7 +33,7 @@ QString JsApi::Barcode::decodeAztec(const QVariant &img) const
return decodeBarcode(img, BarcodeDecoder::Aztec);
}
QVariant JsApi::Barcode::decodeAztecBinary(const QVariant &img) const
QJSValue JsApi::Barcode::decodeAztecBinary(const QVariant &img) const
{
if (img.userType() == qMetaTypeId<PdfImage>()) {
const auto pdfImg = img.value<PdfImage>();
......@@ -40,7 +44,8 @@ QVariant JsApi::Barcode::decodeAztecBinary(const QVariant &img) const
if (content.isEmpty()) {
return {};
}
return content;
const auto engine = qjsEngine(this);
return QJSValue(engine->handle(), engine->handle()->newArrayBuffer(content)->asReturnedValue());
}
return {};
}
......@@ -76,9 +81,9 @@ QString JsApi::Barcode::decodeBarcode(const QVariant &img, BarcodeDecoder::Barco
return {};
}
QVariant JsApi::Barcode::decodeEraSsbTicket(const QVariant &s, int versionOverride) const
QVariant JsApi::Barcode::decodeEraSsbTicket(const QByteArray &s, int versionOverride) const
{
return SSBTicketReader::read(s.toByteArray(), versionOverride);
return SSBTicketReader::read(s, versionOverride);
}
#include "moc_barcode.cpp"
......@@ -9,6 +9,7 @@
#include <KItinerary/BarcodeDecoder>
#include <QDateTime>
#include <QJSValue>
#include <QObject>
namespace KItinerary {
......@@ -32,9 +33,9 @@ public:
Q_INVOKABLE QString decodeAztec(const QVariant &img) const;
/** Decode a Aztec barcode image containing binary data.
* @param img An image containing the barcode, e.g. a PdfImage instance.
* @return a QByteArray, which from the JS perspective is essentially an opque handle.
* @return a JS ArrayBuffer
*/
Q_INVOKABLE QVariant decodeAztecBinary(const QVariant &img) const;
Q_INVOKABLE QJSValue decodeAztecBinary(const QVariant &img) const;
/** Decode as QR barcode image.
* @param img An image containing the barcode, e.g. a PdfImage instance.
*/
......@@ -56,7 +57,7 @@ public:
* fill their version field incorrectly.
* @returns An instance of SSBTicket.
*/
Q_INVOKABLE QVariant decodeEraSsbTicket(const QVariant &s, int versionOverride = 0) const;
Q_INVOKABLE QVariant decodeEraSsbTicket(const QByteArray &s, int versionOverride = 0) const;
///@cond internal
void setDecoder(BarcodeDecoder *decoder);
......
......@@ -37,7 +37,7 @@ function parsePdf(pdf) {
var offset = 0;
for (var j = 0; j < images.length; ++j) {
var barcode = Barcode.decodeAztecBinary(images[j]);
var barcodeB64 = ByteArray.toBase64(barcode);
var barcodeB64 = barcode ? ByteArray.toBase64(barcode) : undefined;
if (!barcodeB64)
continue;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment