Optional content group update

This commit is contained in:
Jakub Melka 2020-08-15 18:22:04 +02:00
parent 7129793109
commit 8ea714555c
3 changed files with 54 additions and 10 deletions

View File

@ -206,6 +206,7 @@ PDFOptionalContentConfiguration::UsageApplication PDFOptionalContentConfiguratio
}
PDFOptionalContentGroup::PDFOptionalContentGroup() :
m_languagePreferred(false),
m_usageZoomMin(0),
m_usageZoomMax(std::numeric_limits<PDFReal>::infinity()),
m_usagePrintState(OCState::Unknown),
@ -253,14 +254,23 @@ PDFOptionalContentGroup PDFOptionalContentGroup::create(const PDFDocument* docum
{
const PDFDictionary* usageDictionary = usageDictionaryObject.getDictionary();
result.m_creatorInfo = document->getObject(usageDictionary->get("CreatorInfo"));
result.m_language = document->getObject(usageDictionary->get("Language"));
const PDFObject& zoomDictionary = document->getObject(usageDictionary->get("Zoom"));
if (zoomDictionary.isDictionary())
if (const PDFDictionary* creatorDictionary = document->getDictionaryFromObject(usageDictionary->get("CreatorInfo")))
{
result.m_usageZoomMin = loader.readNumberFromDictionary(usageDictionary, "min", result.m_usageZoomMin);
result.m_usageZoomMax = loader.readNumberFromDictionary(usageDictionary, "max", result.m_usageZoomMax);
result.m_creator = loader.readTextStringFromDictionary(creatorDictionary, "Creator", QString());
result.m_subtype = loader.readNameFromDictionary(creatorDictionary, "Subtype");
}
result.m_creatorInfo = document->getObject(usageDictionary->get("CreatorInfo"));
if (const PDFDictionary* languageDictionary = document->getDictionaryFromObject(usageDictionary->get("Language")))
{
result.m_language = loader.readTextStringFromDictionary(languageDictionary, "Lang", QString());
result.m_languagePreferred = loader.readNameFromDictionary(languageDictionary, "Preferred") == "ON";
}
if (const PDFDictionary* zoomDictionary = document->getDictionaryFromObject(usageDictionary->get("Zoom")))
{
result.m_usageZoomMin = loader.readNumberFromDictionary(zoomDictionary, "min", result.m_usageZoomMin);
result.m_usageZoomMax = loader.readNumberFromDictionary(zoomDictionary, "max", result.m_usageZoomMax);
}
auto readState = [document, usageDictionary, &loader](const char* dictionaryKey, const char* key) -> OCState
@ -287,6 +297,27 @@ PDFOptionalContentGroup PDFOptionalContentGroup::create(const PDFDocument* docum
result.m_usageViewState = readState("View", "ViewState");
result.m_usagePrintState = readState("Print", "PrintState");
result.m_usageExportState = readState("Export", "ExportState");
if (const PDFDictionary* userDictionary = document->getDictionaryFromObject(usageDictionary->get("User")))
{
result.m_userType = loader.readNameFromDictionary(userDictionary, "Type");
PDFObject namesObject = document->getObject(userDictionary->get("Name"));
if (namesObject.isArray())
{
result.m_userNames = loader.readTextStringList(userDictionary->get("Name"));
}
else
{
QString name = loader.readStringFromDictionary(userDictionary, "Name");
if (!name.isEmpty())
{
result.m_userNames.append(qMove(name));
}
}
}
result.m_pageElement = usageDictionary->get("PageElement");
}
return result;

View File

@ -282,26 +282,38 @@ public:
PDFObjectReference getReference() const { return m_reference; }
const QString& getName() const { return m_name; }
const std::vector<QByteArray>& getIntents() const { return m_intents; }
PDFObject getCreatorInfo() const { return m_creatorInfo; }
PDFObject getLanguage() const { return m_language; }
const PDFObject& getCreatorInfo() const { return m_creatorInfo; }
const QString& getCreator() const { return m_creator; }
const QByteArray& getSubtype() const { return m_subtype; }
const QString& getLanguage() const { return m_language; }
bool isLanguagePreferred() const { return m_languagePreferred; }
PDFReal getUsageZoomMin() const { return m_usageZoomMin; }
PDFReal getUsageZoomMax() const { return m_usageZoomMax; }
OCState getUsagePrintState() const { return m_usagePrintState; }
OCState getUsageViewState() const { return m_usageViewState; }
OCState getUsageExportState() const { return m_usageExportState; }
OCState getUsageState(OCUsage usage) const;
const QByteArray& getUserType() const { return m_userType; }
const QStringList& getUserNames() const { return m_userNames; }
const PDFObject& getPageElement() const { return m_pageElement; }
private:
PDFObjectReference m_reference;
QString m_name;
std::vector<QByteArray> m_intents;
PDFObject m_creatorInfo;
PDFObject m_language;
QString m_creator;
QByteArray m_subtype;
QString m_language;
QByteArray m_userType;
QStringList m_userNames;
bool m_languagePreferred;
PDFReal m_usageZoomMin;
PDFReal m_usageZoomMax;
OCState m_usagePrintState;
OCState m_usageViewState;
OCState m_usageExportState;
PDFObject m_pageElement;
};
/// Object containing properties of the optional content of the PDF document. It contains

View File

@ -659,6 +659,7 @@ void PDFPageContentProcessor::processForm(const QMatrix& matrix,
m_graphicState.setBlendMode(BlendMode::Normal);
m_graphicState.setAlphaFilling(1.0);
m_graphicState.setAlphaStroking(1.0);
m_graphicState.setSoftMask(nullptr);
}
QMatrix formMatrix = matrix * m_graphicState.getCurrentTransformationMatrix();