Finishing display content

This commit is contained in:
Jakub Melka 2021-06-14 19:16:41 +02:00
parent f4ea513208
commit 47baae321e
4 changed files with 39 additions and 3 deletions

View File

@ -2453,6 +2453,23 @@ QString PDFEncoding::getEncodingCharacters(Encoding encoding)
return string;
}
QByteArray PDFEncoding::getPrintableCharacters()
{
QByteArray result;
const char min = std::numeric_limits<char>::min();
const char max = std::numeric_limits<char>::max();
for (char i = min; i < max; ++i)
{
if (std::isprint(static_cast<unsigned char>(i)))
{
result.push_back(i);
}
}
return result;
}
bool PDFEncoding::hasUnicodeLeadMarkings(const QByteArray& stream)
{
if (stream.size() >= 2)

View File

@ -132,6 +132,9 @@ public:
/// \returns All characters reprezentable by encoding.
static QString getEncodingCharacters(Encoding encoding);
/// Returns all printable characters
static QByteArray getPrintableCharacters();
private:
/// Returns true, if byte array has UTF-16BE/LE unicode marking bytes at the
/// stream start. If they are present, then byte stream is probably encoded

View File

@ -42,6 +42,9 @@ ObjectViewerWidget::ObjectViewerWidget(bool isPinned, QWidget* parent) :
{
ui->setupUi(this);
m_printableCharacters = pdf::PDFEncoding::getPrintableCharacters();
m_printableCharacters.push_back('\n');
connect(ui->pinButton, &QPushButton::clicked, this, &ObjectViewerWidget::pinRequest);
connect(ui->unpinButton, &QPushButton::clicked, this, &ObjectViewerWidget::pinRequest);
@ -160,7 +163,7 @@ void ObjectViewerWidget::updateUi()
break;
case pdf::PDFObject::Type::Name:
ui->descriptionEdit->setText(QString("/%1").arg(QString::fromLatin1(m_currentObject.getString().toPercentEncoding())));
ui->descriptionEdit->setText(QString("/%1").arg(QString::fromLatin1(m_currentObject.getString().toPercentEncoding(m_printableCharacters))));
break;
case pdf::PDFObject::Type::Array:
@ -216,11 +219,23 @@ void ObjectViewerWidget::updateUi()
QImage image = pdfImage.getImage(m_cms, &dummyErrorReporter);
ui->stackedWidget->setCurrentWidget(ui->imageBrowserPage);
ui->imageBrowser->setPixmap(QPixmap::fromImage(image));
const int width = image.width();
const int height = image.height();
const int depth = loader.readIntegerFromDictionary(dictionary, "BitsPerComponent", 8);
QString textDescription = tr("Image Stream [%1 items, %2 data bytes, %3 x %4 pixels, %5 bits per component]");
ui->descriptionEdit->setText(textDescription.arg(locale.toString(m_currentObject.getStream()->getDictionary()->getCount()),
locale.toString(m_currentObject.getStream()->getContent()->size()),
locale.toString(width),
locale.toString(height),
locale.toString(depth)));
}
else
{
QByteArray data = m_document->getDecodedStream(stream);
QByteArray percentEncodedData = data.toPercentEncoding(" \n");
data.replace('\r', ' ');
QByteArray percentEncodedData = data.toPercentEncoding(m_printableCharacters);
ui->contentTextBrowser->setText(QString::fromLatin1(percentEncodedData));
ui->stackedWidget->setCurrentWidget(ui->contentTextBrowserPage);
}
@ -234,7 +249,7 @@ void ObjectViewerWidget::updateUi()
else
{
QByteArray serializedObject = pdf::PDFDocumentWriter::getSerializedObject(m_currentObject);
QByteArray percentEncodedData = serializedObject.toPercentEncoding(" \n");
QByteArray percentEncodedData = serializedObject.toPercentEncoding(m_printableCharacters);
ui->contentTextBrowser->setText(QString::fromLatin1(percentEncodedData));
ui->stackedWidget->setCurrentWidget(ui->contentTextBrowserPage);
}

View File

@ -65,6 +65,7 @@ private:
pdf::PDFObjectReference m_currentReference;
pdf::PDFObject m_currentObject;
bool m_isRootObject;
QByteArray m_printableCharacters;
};
} // pdfplugin