Commit 710768f7 authored by Volker Krause's avatar Volker Krause
Browse files

Change how we expand image nodes

This contains two parts:
* We explicitly need to handle text barcode contents here, due to how the
existing barcode decoder API works. This can possibly be changed later, as
that separation is far less relevant with the new system.
* Inject raw data documnent nodes for the barcode contents. This is allows
extractor scripts to recover the exact content e.g. for barcodes containing
JSON, which would otherwise be captures by the JSON-LD document processor.
parent 61b47296
......@@ -16,9 +16,33 @@ using namespace KItinerary;
void ImageDocumentProcessor::expandNode(ExtractorDocumentNode &node, const ExtractorEngine *engine) const
{
const auto s = engine->barcodeDecoder()->decodeBinary(node.content<QImage>());
// in case the barcode raw data (string or bytearray) gets detected as a type we handle,
// we nevertheless inject a raw data node inbetween. This is useful in cases where the
// content is parsable but that is actually not desired (e.g. JSON content in ticket barcodes).
const auto b = engine->barcodeDecoder()->decodeBinary(node.content<QImage>());
if (!b.isEmpty()) {
auto c = engine->documentNodeFactory()->createNode(b);
if (c.isA<QByteArray>() || c.isA<QString>()) {
node.appendChild(c);
return;
}
auto rawNode = engine->documentNodeFactory()->createNode(QVariant::fromValue(b), u"application/octet-stream");
rawNode.appendChild(c);
node.appendChild(rawNode);
return;
}
const auto s = engine->barcodeDecoder()->decodeString(node.content<QImage>());
if (!s.isEmpty()) {
auto c = engine->documentNodeFactory()->createNode(s);
node.appendChild(c);
auto c = engine->documentNodeFactory()->createNode(s.toUtf8());
if (c.isA<QByteArray>() || c.isA<QString>()) {
node.appendChild(c);
return;
}
auto rawNode = engine->documentNodeFactory()->createNode(QVariant::fromValue(s), u"text/plain");
rawNode.appendChild(c);
node.appendChild(rawNode);
return;
}
}
Markdown is supported
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