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

Perform barcode decoding of image child nodes in PDF processor directly

This is technically not the job of the PDF code, but we have more
information available at this point to make decisions about plausible
barcode formats.
parent ac1d46c2
......@@ -79,7 +79,7 @@ private Q_SLOTS:
QCOMPARE(c1.mimeType(), QLatin1String("internal/qimage"));
QVERIFY(!c1.parent().isNull());
QCOMPARE(c1.content().userType(), qMetaTypeId<QImage>());
QCOMPARE(c1.childNodes().size(), 0);
QCOMPARE(c1.childNodes().size(), 1); // barcode already expanded by the PDF processor
QCOMPARE(c1.location().toInt(), 0);
c1.processor()->expandNode(c1, &engine);
......
......@@ -29,9 +29,15 @@ ExtractorDocumentNode ImageDocumentProcessor::createNodeFromData(const QByteArra
void ImageDocumentProcessor::expandNode(ExtractorDocumentNode &node, const ExtractorEngine *engine) const
{
// check whether we possibly have a full PDF page raster image here
// skip barcode extraction if somebody else already did that (such as the PDF processor)
if (!node.childNodes().empty()) {
return;
}
const auto img = node.content<QImage>();
BarcodeDecoder::BarcodeTypes barcodeHints = BarcodeDecoder::Any2D;
// check whether we possibly have a full PDF page raster image here
if (engine->hints() & ExtractorEngine::ExtractFullPageRasterImages) {
barcodeHints |= BarcodeDecoder::IgnoreAspectRatio;
}
......
......@@ -5,6 +5,7 @@
*/
#include "pdfdocumentprocessor.h"
#include "barcodedocumentprocessorhelper.h"
#include "pdf/pdfbarcodeutil_p.h"
#include <KItinerary/BarcodeDecoder>
......@@ -90,7 +91,8 @@ void PdfDocumentProcessor::expandNode(ExtractorDocumentNode &node, const Extract
continue;
}
if (PdfBarcodeUtil::maybeBarcode(img, BarcodeDecoder::Any2D) == BarcodeDecoder::None) {
const auto barcodeHints = PdfBarcodeUtil::maybeBarcode(img, BarcodeDecoder::Any2D);
if (barcodeHints == BarcodeDecoder::None) {
continue;
}
......@@ -105,6 +107,10 @@ void PdfDocumentProcessor::expandNode(ExtractorDocumentNode &node, const Extract
if (img.hasObjectId()) {
m_imageIds.insert(img.objectId());
}
// technically not our job to do this here rather than letting the image node processor handle this
// but we have the output aspect ratio of the barcode only here, which gives better decoding hints
BarcodeDocumentProcessorHelper::expandNode(imgData, barcodeHints, childNode, engine);
}
// handle full page raster images
......
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