Support for MMType1 fonts, minor bugfixing

This commit is contained in:
Jakub Melka 2020-08-18 19:39:09 +02:00
parent 8ea714555c
commit b1beca8ef9
6 changed files with 24 additions and 11 deletions

View File

@ -480,6 +480,7 @@ void PDFRealizedFontImpl::fillTextSequence(const QByteArray& byteArray, TextSequ
{
case FontType::Type1:
case FontType::TrueType:
case FontType::MMType1:
{
// We can use encoding
Q_ASSERT(dynamic_cast<PDFSimpleFont*>(m_parentFont.get()));
@ -808,7 +809,7 @@ PDFRealizedFontPointer PDFRealizedFont::createRealizedFont(PDFFontPointer font,
else
{
StandardFontType standardFontType = StandardFontType::Invalid;
if (font->getFontType() == FontType::Type1)
if (font->getFontType() == FontType::Type1 || font->getFontType() == FontType::MMType1)
{
Q_ASSERT(dynamic_cast<const PDFType1Font*>(font.get()));
const PDFType1Font* type1Font = static_cast<const PDFType1Font*>(font.get());
@ -905,11 +906,12 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d
PDFDocumentDataLoaderDecorator fontLoader(document);
// First, determine the font subtype
constexpr const std::array<std::pair<const char*, FontType>, 4> fontTypes = {
constexpr const std::array fontTypes = {
std::pair<const char*, FontType>{ "Type0", FontType::Type0 },
std::pair<const char*, FontType>{ "Type1", FontType::Type1 },
std::pair<const char*, FontType>{ "TrueType", FontType::TrueType },
std::pair<const char*, FontType>{ "Type3", FontType::Type3}
std::pair<const char*, FontType>{ "Type3", FontType::Type3},
std::pair<const char*, FontType>{ "MMType1", FontType::MMType1 }
};
const FontType fontType = fontLoader.readEnumByName(fontDictionary->get("Subtype"), fontTypes.cbegin(), fontTypes.cend(), FontType::Invalid);
@ -966,6 +968,7 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d
switch (fontType)
{
case FontType::Type1:
case FontType::MMType1:
case FontType::TrueType:
{
bool hasDifferences = false;
@ -1417,7 +1420,8 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d
switch (fontType)
{
case FontType::Type1:
return PDFFontPointer(new PDFType1Font(qMove(fontDescriptor), qMove(name), qMove(baseFont), firstChar, lastChar, qMove(widths), encoding, simpleFontEncodingTable, standardFont, glyphIndexArray));
case FontType::MMType1:
return PDFFontPointer(new PDFType1Font(fontType, qMove(fontDescriptor), qMove(name), qMove(baseFont), firstChar, lastChar, qMove(widths), encoding, simpleFontEncodingTable, standardFont, glyphIndexArray));
case FontType::TrueType:
return PDFFontPointer(new PDFTrueTypeFont(qMove(fontDescriptor), qMove(name), qMove(baseFont), firstChar, lastChar, qMove(widths), encoding, simpleFontEncodingTable, glyphIndexArray));
@ -1524,7 +1528,8 @@ void PDFSimpleFont::dumpFontToTreeItem(QTreeWidgetItem* item) const
new QTreeWidgetItem(item, { PDFTranslationContext::tr("Encoding"), encodingTypeString });
}
PDFType1Font::PDFType1Font(FontDescriptor fontDescriptor,
PDFType1Font::PDFType1Font(FontType fontType,
FontDescriptor fontDescriptor,
QByteArray name,
QByteArray baseFont,
PDFInteger firstChar,
@ -1535,6 +1540,7 @@ PDFType1Font::PDFType1Font(FontDescriptor fontDescriptor,
StandardFontType standardFontType,
GlyphIndices glyphIndices) :
PDFSimpleFont(qMove(fontDescriptor), qMove(name), qMove(baseFont), firstChar, lastChar, qMove(widths), encodingType, encoding, glyphIndices),
m_fontType(fontType),
m_standardFontType(standardFontType)
{
@ -1542,7 +1548,7 @@ PDFType1Font::PDFType1Font(FontDescriptor fontDescriptor,
FontType PDFType1Font::getFontType() const
{
return FontType::Type1;
return m_fontType;
}
void PDFType1Font::dumpFontToTreeItem(QTreeWidgetItem* item) const

View File

@ -129,6 +129,7 @@ enum class FontType
Invalid,
Type0,
Type1,
MMType1,
TrueType,
Type3
};
@ -321,7 +322,8 @@ class PDFType1Font : public PDFSimpleFont
using BaseClass = PDFSimpleFont;
public:
explicit PDFType1Font(FontDescriptor fontDescriptor,
explicit PDFType1Font(FontType fontType,
FontDescriptor fontDescriptor,
QByteArray name,
QByteArray baseFont,
PDFInteger firstChar,
@ -340,6 +342,7 @@ public:
StandardFontType getStandardFontType() const { return m_standardFontType; }
private:
FontType m_fontType;
StandardFontType m_standardFontType; ///< Type of the standard font (or invalid, if it is not a standard font)
};

View File

@ -198,7 +198,7 @@ PDFOptionalContentConfiguration::UsageApplication PDFOptionalContentConfiguratio
PDFDocumentDataLoaderDecorator loader(document);
const PDFDictionary* dictionary = dereferencedObject.getDictionary();
result.event = loader.readNameFromDictionary(dictionary, "Event");
result.optionalContengGroups = loader.readReferenceArrayFromDictionary(dictionary, "OCGs");
result.optionalContentGroups = loader.readReferenceArrayFromDictionary(dictionary, "OCGs");
result.categories = loader.readNameArrayFromDictionary(dictionary, "Category");
}
@ -451,7 +451,7 @@ void PDFOptionalContentActivity::applyConfiguration(const PDFOptionalContentConf
if (usage == m_usage)
{
for (PDFObjectReference ocg : usageApplication.optionalContengGroups)
for (PDFObjectReference ocg : usageApplication.optionalContentGroups)
{
if (!m_properties->hasOptionalContentGroup(ocg))
{

View File

@ -221,7 +221,7 @@ public:
struct UsageApplication
{
QByteArray event;
std::vector<PDFObjectReference> optionalContengGroups;
std::vector<PDFObjectReference> optionalContentGroups;
std::vector<QByteArray> categories;
};

View File

@ -3131,7 +3131,7 @@ void PDFPageContentProcessor::drawText(const TextSequence& textSequence)
fontAdjustedMatrix.map(item.advance, 0.0, &displacementX, &ry);
}
if (item.characterContentStream)
if (item.characterContentStream && (fill || stroke))
{
PDFPageContentProcessorStateGuard guard(this);

View File

@ -328,6 +328,10 @@ void PDFDocumentPropertiesDialog::initializeFonts(const pdf::PDFDocument* docume
fontTypeString = tr("Type1 (8 bit keyed)");
break;
case pdf::FontType::MMType1:
fontTypeString = tr("MMType1 (8 bit keyed)");
break;
case pdf::FontType::Type3:
fontTypeString = tr("Type3 (content streams for font glyphs)");
break;