From 47baae321e030c59666afc955479f58210b3253b Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Mon, 14 Jun 2021 19:16:41 +0200 Subject: [PATCH] Finishing display content --- Pdf4QtLib/sources/pdfencoding.cpp | 17 +++++++++++++++ Pdf4QtLib/sources/pdfencoding.h | 3 +++ .../objectviewerwidget.cpp | 21 ++++++++++++++++--- .../objectviewerwidget.h | 1 + 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Pdf4QtLib/sources/pdfencoding.cpp b/Pdf4QtLib/sources/pdfencoding.cpp index 4732259..1ec08b0 100644 --- a/Pdf4QtLib/sources/pdfencoding.cpp +++ b/Pdf4QtLib/sources/pdfencoding.cpp @@ -2453,6 +2453,23 @@ QString PDFEncoding::getEncodingCharacters(Encoding encoding) return string; } +QByteArray PDFEncoding::getPrintableCharacters() +{ + QByteArray result; + + const char min = std::numeric_limits::min(); + const char max = std::numeric_limits::max(); + for (char i = min; i < max; ++i) + { + if (std::isprint(static_cast(i))) + { + result.push_back(i); + } + } + + return result; +} + bool PDFEncoding::hasUnicodeLeadMarkings(const QByteArray& stream) { if (stream.size() >= 2) diff --git a/Pdf4QtLib/sources/pdfencoding.h b/Pdf4QtLib/sources/pdfencoding.h index 5779b12..c861a5e 100644 --- a/Pdf4QtLib/sources/pdfencoding.h +++ b/Pdf4QtLib/sources/pdfencoding.h @@ -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 diff --git a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.cpp b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.cpp index 08fba4f..a551aa0 100644 --- a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.cpp +++ b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.cpp @@ -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); } diff --git a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.h b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.h index 844719a..d166ce8 100644 --- a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.h +++ b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.h @@ -65,6 +65,7 @@ private: pdf::PDFObjectReference m_currentReference; pdf::PDFObject m_currentObject; bool m_isRootObject; + QByteArray m_printableCharacters; }; } // pdfplugin