Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KItinerary
Commits
ac1d46c2
Commit
ac1d46c2
authored
Jul 18, 2022
by
Volker Krause
Browse files
Factor out barcode decoding of document nodes
Will be reused in the PDF document node processor.
parent
f5fc1c50
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/lib/CMakeLists.txt
View file @
ac1d46c2
...
...
@@ -76,6 +76,7 @@ target_sources(KPimItinerary PRIVATE
pdf/popplerglobalparams.cpp
pdf/popplerutils.cpp
processors/barcodedocumentprocessorhelper.cpp
processors/binarydocumentprocessor.cpp
processors/externalprocessor.cpp
processors/htmldocumentprocessor.cpp
...
...
src/lib/processors/barcodedocumentprocessorhelper.cpp
0 → 100644
View file @
ac1d46c2
/*
SPDX-FileCopyrightText: 2021-2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include
"barcodedocumentprocessorhelper.h"
#include
<KItinerary/ExtractorDocumentNode>
#include
<KItinerary/ExtractorDocumentNodeFactory>
#include
<KItinerary/ExtractorEngine>
using
namespace
KItinerary
;
void
BarcodeDocumentProcessorHelper
::
expandNode
(
const
QImage
&
img
,
BarcodeDecoder
::
BarcodeTypes
barcodeHints
,
ExtractorDocumentNode
&
parent
,
const
ExtractorEngine
*
engine
)
{
// in case the barcode raw data (string or bytearray) gets detected as a type we handle,
// we nevertheless inject a raw data node in between. 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
(
img
,
barcodeHints
);
if
(
!
b
.
isEmpty
())
{
auto
c
=
engine
->
documentNodeFactory
()
->
createNode
(
b
);
if
(
c
.
isA
<
QByteArray
>
()
||
c
.
isA
<
QString
>
())
{
parent
.
appendChild
(
c
);
return
;
}
auto
rawNode
=
engine
->
documentNodeFactory
()
->
createNode
(
QVariant
::
fromValue
(
b
),
u"application/octet-stream"
);
rawNode
.
appendChild
(
c
);
parent
.
appendChild
(
rawNode
);
return
;
}
const
auto
s
=
engine
->
barcodeDecoder
()
->
decodeString
(
img
,
barcodeHints
);
if
(
!
s
.
isEmpty
())
{
auto
c
=
engine
->
documentNodeFactory
()
->
createNode
(
s
.
toUtf8
());
if
(
c
.
isA
<
QByteArray
>
()
||
c
.
isA
<
QString
>
())
{
parent
.
appendChild
(
c
);
return
;
}
auto
rawNode
=
engine
->
documentNodeFactory
()
->
createNode
(
QVariant
::
fromValue
(
s
),
u"text/plain"
);
rawNode
.
appendChild
(
c
);
parent
.
appendChild
(
rawNode
);
return
;
}
}
src/lib/processors/barcodedocumentprocessorhelper.h
0 → 100644
View file @
ac1d46c2
/*
SPDX-FileCopyrightText: 2021-2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KITINERARY_BARCODEDOCUMENTPROCESSORHELPER_H
#define KITINERARY_BARCODEDOCUMENTPROCESSORHELPER_H
#include
<barcodedecoder.h>
namespace
KItinerary
{
class
ExtractorDocumentNode
;
class
ExtractorEngine
;
/** Barcode-related document processor implementation details. */
namespace
BarcodeDocumentProcessorHelper
{
void
expandNode
(
const
QImage
&
img
,
BarcodeDecoder
::
BarcodeTypes
barcodeHints
,
ExtractorDocumentNode
&
parent
,
const
ExtractorEngine
*
engine
);
}
}
#endif // KITINERARY_BARCODEDOCUMENTPROCESSORHELPER_H
src/lib/processors/imagedocumentprocessor.cpp
View file @
ac1d46c2
...
...
@@ -5,6 +5,7 @@
*/
#include
"imagedocumentprocessor.h"
#include
"barcodedocumentprocessorhelper.h"
#include
<KItinerary/BarcodeDecoder>
#include
<KItinerary/ExtractorDocumentNodeFactory>
...
...
@@ -36,33 +37,5 @@ void ImageDocumentProcessor::expandNode(ExtractorDocumentNode &node, const Extra
}
barcodeHints
=
BarcodeDecoder
::
maybeBarcode
(
img
.
width
(),
img
.
height
(),
barcodeHints
);
// in case the barcode raw data (string or bytearray) gets detected as a type we handle,
// we nevertheless inject a raw data node in between. 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
(
img
,
barcodeHints
);
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
(
img
,
barcodeHints
);
if
(
!
s
.
isEmpty
())
{
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
;
}
BarcodeDocumentProcessorHelper
::
expandNode
(
img
,
barcodeHints
,
node
,
engine
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment