Font tool finished

This commit is contained in:
Jakub Melka 2020-10-24 15:36:00 +02:00
parent 6142b263a0
commit acee5f2186
3 changed files with 73 additions and 1 deletions

View File

@ -360,6 +360,9 @@ public:
/// Dumps information about the font
virtual void dumpFontToTreeItem(QTreeWidgetItem* item) const { Q_UNUSED(item); }
/// Returns postscript name of the font
virtual QString getPostScriptName() const { return QString(); }
};
/// Implementation of the PDFRealizedFont class using PIMPL pattern for Type 3 fonts
@ -390,6 +393,7 @@ public:
virtual void fillTextSequence(const QByteArray& byteArray, TextSequence& textSequence, PDFRenderErrorReporter* reporter) override;
virtual bool isHorizontalWritingSystem() const override { return !m_isVertical; }
virtual void dumpFontToTreeItem(QTreeWidgetItem* item) const override;
virtual QString getPostScriptName() const override { return m_postScriptName; }
static constexpr const PDFReal PIXEL_SIZE_MULTIPLIER = 100.0;
@ -446,6 +450,9 @@ private:
/// True, if font has vertical writing system
bool m_isVertical;
/// Postscript name of the font
QString m_postScriptName;
};
PDFRealizedFontImpl::PDFRealizedFontImpl() :
@ -774,6 +781,11 @@ void PDFRealizedFont::dumpFontToTreeItem(QTreeWidgetItem* item) const
m_impl->dumpFontToTreeItem(item);
}
QString PDFRealizedFont::getPostScriptName() const
{
return m_impl->getPostScriptName();
}
PDFRealizedFontPointer PDFRealizedFont::createRealizedFont(PDFFontPointer font, PDFReal pixelSize, PDFRenderErrorReporter* reporter)
{
PDFRealizedFontPointer result;
@ -832,6 +844,10 @@ PDFRealizedFontPointer PDFRealizedFont::createRealizedFont(PDFFontPointer font,
PDFRealizedFontImpl::checkFreeTypeError(FT_Set_Pixel_Sizes(impl->m_face, 0, qRound(pixelSize * PDFRealizedFontImpl::PIXEL_SIZE_MULTIPLIER)));
impl->m_isVertical = impl->m_face->face_flags & FT_FACE_FLAG_VERTICAL;
impl->m_isEmbedded = false;
if (const char* postScriptName = FT_Get_Postscript_Name(impl->m_face))
{
impl->m_postScriptName = QString::fromLatin1(postScriptName);
}
result.reset(new PDFRealizedFont(implPtr.release()));
}
}

View File

@ -239,6 +239,9 @@ public:
/// Adds information about the font into tree item
void dumpFontToTreeItem(QTreeWidgetItem* item) const;
/// Returns postscript name of the font
QString getPostScriptName() const;
/// Creates new realized font from the standard font. If font can't be created,
/// then exception is thrown.
static PDFRealizedFontPointer createRealizedFont(PDFFontPointer font, PDFReal pixelSize, PDFRenderErrorReporter* reporter);

View File

@ -57,6 +57,7 @@ struct FontInfo
bool isSubset = false;
bool isToUnicodePresent = false;
pdf::PDFObjectReference reference;
QString substitutedFont;
};
int PDFToolInfoFonts::execute(const PDFToolOptions& options)
@ -191,10 +192,11 @@ int PDFToolInfoFonts::execute(const PDFToolOptions& options)
info.fontName = fontName;
info.pages.addValue(pageIndex + 1);
info.fontTypeName = fontTypeName;
info.isEmbedded = fontDescriptor->isEmbedded();
info.isEmbedded = fontDescriptor->isEmbedded() || fontType == pdf::FontType::Type3;
info.isSubset = isSubset;
info.isToUnicodePresent = toUnicode && toUnicode->isValid();
info.reference = fontReference;
info.substitutedFont = realizedFont->getPostScriptName();
const pdf::PDFSimpleFont* simpleFont = dynamic_cast<const pdf::PDFSimpleFont*>(font.data());
if (simpleFont)
@ -290,6 +292,7 @@ int PDFToolInfoFonts::execute(const PDFToolOptions& options)
QString noText = PDFToolTranslationContext::tr("No");
QString noRef = PDFToolTranslationContext::tr("--");
bool hasSubstitutions = false;
int ref = 1;
for (const FontInfo& info : directFonts)
{
@ -315,12 +318,62 @@ int PDFToolInfoFonts::execute(const PDFToolOptions& options)
formatter.writeTableColumn("generation-no", noRef, Qt::AlignRight);
}
hasSubstitutions = hasSubstitutions || !info.isEmbedded;
formatter.endTableRow();
++ref;
}
formatter.endTable();
formatter.endl();
if (hasSubstitutions)
{
formatter.beginTable("fonts-substitutions", PDFToolTranslationContext::tr("Substitutions"));
formatter.beginTableHeaderRow("header");
formatter.writeTableHeaderColumn("no", PDFToolTranslationContext::tr("No."), Qt::AlignLeft);
formatter.writeTableHeaderColumn("font-name", PDFToolTranslationContext::tr("Font Name"), Qt::AlignLeft);
formatter.writeTableHeaderColumn("font-substitute", PDFToolTranslationContext::tr("Substituted by Font"), Qt::AlignLeft);
formatter.writeTableHeaderColumn("match", PDFToolTranslationContext::tr("Match"), Qt::AlignLeft);
formatter.writeTableHeaderColumn("object-no", PDFToolTranslationContext::tr("Object"), Qt::AlignLeft);
formatter.writeTableHeaderColumn("generation-no", PDFToolTranslationContext::tr("Gen."), Qt::AlignLeft);
formatter.endTableHeaderRow();
ref = 1;
for (const FontInfo& info : directFonts)
{
if (info.isEmbedded)
{
continue;
}
formatter.beginTableRow("substitution", ref);
formatter.writeTableColumn("no", locale.toString(ref), Qt::AlignRight);
formatter.writeTableColumn("font-name", info.fontName);
formatter.writeTableColumn("font-substitute", !info.substitutedFont.isEmpty() ? info.substitutedFont : PDFToolTranslationContext::tr("??"));
formatter.writeTableColumn("match", (info.fontName == info.substitutedFont) ? yesText : noText);
if (info.reference.isValid())
{
formatter.writeTableColumn("object-no", locale.toString(info.reference.objectNumber), Qt::AlignRight);
formatter.writeTableColumn("generation-no", locale.toString(info.reference.generation), Qt::AlignRight);
}
else
{
formatter.writeTableColumn("object-no", noRef, Qt::AlignRight);
formatter.writeTableColumn("generation-no", noRef, Qt::AlignRight);
}
formatter.endTableRow();
++ref;
}
formatter.endTable();
}
formatter.endDocument();
PDFConsole::writeText(formatter.getString(), options.outputCodec);