2019-04-06 17:16:42 +02:00
|
|
|
#include <QFile>
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QDebug>
|
|
|
|
#include "defaulttextprocessor.h"
|
|
|
|
|
|
|
|
DefaultTextProcessor::DefaultTextProcessor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DefaultTextProcessor::processText(const QByteArray &data) const
|
|
|
|
{
|
|
|
|
QString encoding = encodingDetector.detectEncoding(data);
|
|
|
|
if(!encoding.isEmpty())
|
|
|
|
{
|
|
|
|
QTextCodec *codec = QTextCodec::codecForName(encoding.toUtf8());
|
|
|
|
if(codec != nullptr)
|
|
|
|
{
|
|
|
|
return codec->toUnicode(data);
|
|
|
|
}
|
|
|
|
qWarning() << "No codec found for " << encoding;
|
|
|
|
return QString(data);
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-05-14 14:14:51 +02:00
|
|
|
DocumentProcessResult DefaultTextProcessor::process(const QByteArray &data) const
|
2019-04-06 17:16:42 +02:00
|
|
|
{
|
2023-05-14 14:14:51 +02:00
|
|
|
DocumentProcessResult result;
|
|
|
|
result.pages.append({0, processText(data)});
|
|
|
|
return result;
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|