mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-02-19 13:10:51 +01:00
XFA: xfa engine parsing template
This commit is contained in:
parent
624794554c
commit
f739e9f544
@ -242,7 +242,7 @@ DEPENDPATH += $$Pdf4Qt_DEPENDENCIES_PATH/lcms2/include
|
|||||||
# ensure debug info even for RELEASE build
|
# ensure debug info even for RELEASE build
|
||||||
CONFIG += force_debug_info
|
CONFIG += force_debug_info
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += /std:c++latest /utf-8
|
QMAKE_CXXFLAGS += /std:c++latest /utf-8 /bigobj
|
||||||
QMAKE_RESOURCE_FLAGS += -threshold 0 -compress 9
|
QMAKE_RESOURCE_FLAGS += -threshold 0 -compress 9
|
||||||
|
|
||||||
PdfforQt_library.files = $$DESTDIR/Pdf4QtLib.dll
|
PdfforQt_library.files = $$DESTDIR/Pdf4QtLib.dll
|
||||||
|
@ -1161,6 +1161,8 @@ void PDFFormManager::setDocument(const PDFModifiedDocument& document)
|
|||||||
// Just update field values
|
// Just update field values
|
||||||
updateFieldValues();
|
updateFieldValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_xfaEngine.setDocument(document, &m_form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "pdfannotation.h"
|
#include "pdfannotation.h"
|
||||||
#include "pdfdocumentdrawinterface.h"
|
#include "pdfdocumentdrawinterface.h"
|
||||||
#include "pdfsignaturehandler.h"
|
#include "pdfsignaturehandler.h"
|
||||||
|
#include "pdfxfaengine.h"
|
||||||
|
|
||||||
#include <QTextLayout>
|
#include <QTextLayout>
|
||||||
|
|
||||||
@ -720,6 +721,8 @@ private:
|
|||||||
PDFForm m_form;
|
PDFForm m_form;
|
||||||
bool m_isCommitDisabled;
|
bool m_isCommitDisabled;
|
||||||
|
|
||||||
|
PDFXFAEngine m_xfaEngine;
|
||||||
|
|
||||||
std::vector<PDFFormFieldWidgetEditor*> m_widgetEditors;
|
std::vector<PDFFormFieldWidgetEditor*> m_widgetEditors;
|
||||||
PDFFormFieldWidgetEditor* m_focusedEditor;
|
PDFFormFieldWidgetEditor* m_focusedEditor;
|
||||||
MouseGrabInfo m_mouseGrabInfo;
|
MouseGrabInfo m_mouseGrabInfo;
|
||||||
|
@ -16,8 +16,10 @@
|
|||||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "pdfxfaengine.h"
|
#include "pdfxfaengine.h"
|
||||||
|
#include "pdfform.h"
|
||||||
|
|
||||||
#include <QDomElement>
|
#include <QDomElement>
|
||||||
|
#include <QDomDocument>
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
@ -8887,10 +8889,16 @@ std::optional<XFA_variables> XFA_variables::parse(const QDomElement& element)
|
|||||||
class PDFXFAEngineImpl
|
class PDFXFAEngineImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PDFXFAEngineImpl() = default;
|
PDFXFAEngineImpl();
|
||||||
|
|
||||||
|
void setDocument(const PDFModifiedDocument& document, PDFForm* form);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void clear();
|
||||||
|
|
||||||
xfa::XFA_Node<xfa::XFA_template> m_template;
|
xfa::XFA_Node<xfa::XFA_template> m_template;
|
||||||
|
const PDFDocument* m_document;
|
||||||
|
PDFForm* m_form;
|
||||||
};
|
};
|
||||||
|
|
||||||
PDFXFAEngine::PDFXFAEngine() :
|
PDFXFAEngine::PDFXFAEngine() :
|
||||||
@ -8904,4 +8912,77 @@ PDFXFAEngine::~PDFXFAEngine()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFXFAEngine::setDocument(const PDFModifiedDocument& document, PDFForm* form)
|
||||||
|
{
|
||||||
|
m_impl->setDocument(document, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFXFAEngineImpl::PDFXFAEngineImpl() :
|
||||||
|
m_document(nullptr),
|
||||||
|
m_form(nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFXFAEngineImpl::setDocument(const PDFModifiedDocument& document, PDFForm* form)
|
||||||
|
{
|
||||||
|
if (m_document != document || document.hasReset())
|
||||||
|
{
|
||||||
|
m_document = document;
|
||||||
|
|
||||||
|
if (document.hasReset())
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
|
||||||
|
if (form->getFormType() == PDFForm::FormType::XFAForm)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const PDFObject& xfaObject = m_document->getObject(form->getXFA());
|
||||||
|
|
||||||
|
std::map<QByteArray, QByteArray> xfaData;
|
||||||
|
if (xfaObject.isArray())
|
||||||
|
{
|
||||||
|
const PDFArray* xfaArrayData = xfaObject.getArray();
|
||||||
|
const size_t pairCount = xfaArrayData->getCount() / 2;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < pairCount; ++i)
|
||||||
|
{
|
||||||
|
const PDFObject& itemName = m_document->getObject(xfaArrayData->getItem(2 * i + 0));
|
||||||
|
const PDFObject& streamObject = m_document->getObject(xfaArrayData->getItem(2 * i + 1));
|
||||||
|
|
||||||
|
if (itemName.isString() && streamObject.isStream())
|
||||||
|
{
|
||||||
|
xfaData[itemName.getString()] = m_document->getDecodedStream(streamObject.getStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (xfaObject.isStream())
|
||||||
|
{
|
||||||
|
xfaData["template"] = m_document->getDecodedStream(xfaObject.getStream());
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomDocument document;
|
||||||
|
if (document.setContent(xfaData["template"]))
|
||||||
|
{
|
||||||
|
m_template = xfa::XFA_template::parse(document.firstChildElement("template"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (PDFException)
|
||||||
|
{
|
||||||
|
// Just clear once again - if some errorneous data
|
||||||
|
// were read, we want to clear them.
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFXFAEngineImpl::clear()
|
||||||
|
{
|
||||||
|
// Clear the template
|
||||||
|
m_template = xfa::XFA_Node<xfa::XFA_template>();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace pdf
|
} // namespace pdf
|
||||||
|
@ -19,12 +19,14 @@
|
|||||||
#define PDFXFAENGINE_H
|
#define PDFXFAENGINE_H
|
||||||
|
|
||||||
#include "pdfglobal.h"
|
#include "pdfglobal.h"
|
||||||
|
#include "pdfdocument.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace pdf
|
namespace pdf
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class PDFForm;
|
||||||
class PDFXFAEngineImpl;
|
class PDFXFAEngineImpl;
|
||||||
|
|
||||||
class PDFXFAEngine
|
class PDFXFAEngine
|
||||||
@ -33,6 +35,8 @@ public:
|
|||||||
PDFXFAEngine();
|
PDFXFAEngine();
|
||||||
~PDFXFAEngine();
|
~PDFXFAEngine();
|
||||||
|
|
||||||
|
void setDocument(const PDFModifiedDocument& document, PDFForm* form);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<PDFXFAEngineImpl> m_impl;
|
std::unique_ptr<PDFXFAEngineImpl> m_impl;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user