Fontinfo tool (first steps)

This commit is contained in:
Jakub Melka
2020-10-24 14:39:09 +02:00
parent b6d216aea2
commit 6142b263a0
10 changed files with 406 additions and 9 deletions

View File

@@ -25,18 +25,19 @@
#include <QFont>
#include <QMatrix>
#include <QSharedPointer>
#include <QTreeWidgetItem>
#include <set>
#include <unordered_map>
class QPainterPath;
class QTreeWidgetItem;
namespace pdf
{
class PDFDocument;
class PDFModifiedDocument;
class PDFRenderErrorReporter;
class PDFFontCMap;
using CID = unsigned int;
using GID = unsigned int;
@@ -259,6 +260,9 @@ public:
/// Returns the font type
virtual FontType getFontType() const = 0;
/// Returns ToUnicode mapping (or nullptr, if font has no mapping to unicode)
virtual const PDFFontCMap* getToUnicode() const { return nullptr; }
/// Returns font descriptor
const FontDescriptor* getFontDescriptor() const { return &m_fontDescriptor; }
@@ -298,6 +302,7 @@ public:
GlyphIndices glyphIndices);
virtual ~PDFSimpleFont() override = default;
const PDFEncoding::Encoding getEncodingType() const { return m_encodingType; }
const encoding::EncodingTable* getEncoding() const { return &m_encoding; }
const GlyphIndices* getGlyphIndices() const { return &m_glyphIndices; }
@@ -523,6 +528,7 @@ public:
virtual FontType getFontType() const override;
virtual void dumpFontToTreeItem(QTreeWidgetItem*item) const override;
virtual const PDFFontCMap* getToUnicode() const override { return &m_toUnicode; }
/// Returns width of the character. If character doesn't exist, then zero is returned.
double getWidth(int characterIndex) const;
@@ -533,7 +539,6 @@ public:
const QMatrix& getFontMatrix() const { return m_fontMatrix; }
const PDFObject& getResources() const { return m_resources; }
const PDFFontCMap& getToUnicode() const { return m_toUnicode; }
/// Returns unicode character for given character index. If unicode mapping is not
/// present, empty (null) character is returned.
@@ -567,9 +572,9 @@ public:
virtual ~PDFType0Font() = default;
virtual FontType getFontType() const override { return FontType::Type0; }
virtual const PDFFontCMap* getToUnicode() const override { return &m_toUnicode; }
const PDFFontCMap* getCMap() const { return &m_cmap; }
const PDFFontCMap* getToUnicode() const { return &m_toUnicode; }
const PDFCIDtoGIDMapper* getCIDtoGIDMapper() const { return &m_mapper; }
/// Returns the glyph advance, if it can be obtained, or zero, if it cannot

View File

@@ -27,6 +27,7 @@
#include <QApplication>
#include <QByteArray>
#include <QClipboard>
#include <QStyleOption>
namespace pdf
{

View File

@@ -302,13 +302,30 @@ PDFInteger PDFClosedIntervalSet::getTotalLength() const
return std::accumulate(m_intervals.cbegin(), m_intervals.cend(), 0, [](PDFInteger count, const auto& b) { return count + b.second - b.first + 1; });
}
QString PDFClosedIntervalSet::toText() const
QString PDFClosedIntervalSet::toText(bool withoutBrackets) const
{
QStringList intervals;
for (const ClosedInterval& interval : m_intervals)
if (withoutBrackets)
{
intervals << QString("[%1 - %2]").arg(interval.first).arg(interval.second);
for (const ClosedInterval& interval : m_intervals)
{
if (interval.first == interval.second)
{
intervals << QString::number(interval.first);
}
else
{
intervals << QString("%1-%2").arg(interval.first).arg(interval.second);
}
}
}
else
{
for (const ClosedInterval& interval : m_intervals)
{
intervals << QString("[%1 - %2]").arg(interval.first).arg(interval.second);
}
}
return intervals.join(", ");

View File

@@ -615,7 +615,7 @@ public:
PDFInteger getTotalLength() const;
/// Transforms interval set to readable text
QString toText() const;
QString toText(bool withoutBrackets) const;
/// Returns all integers from the range
std::vector<PDFInteger> unfold() const;

View File

@@ -26,6 +26,7 @@
#include <QCursor>
class QCheckBox;
class QLineEdit;
namespace pdf
{