From 564c4068a51685bd1e339cd77f1fc1af68e1c6c9 Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Wed, 27 Oct 2021 19:23:40 +0200 Subject: [PATCH] XFA: xfa engine basics --- CodeGenerator/CodeGenerator.pro | 4 +- CodeGenerator/codegenerator.h | 5 + CodeGenerator/generatormainwindow.cpp | 41 +++++++ CodeGenerator/generatormainwindow.h | 8 ++ CodeGenerator/generatormainwindow.ui | 30 ++++++ Pdf4QtLib/Pdf4QtLib.pro | 2 + Pdf4QtLib/sources/pdfxfaengine.cpp | 28 +++++ Pdf4QtLib/sources/pdfxfaengine.h | 150 ++++++++++++++++++++++++++ README.md | 4 +- 9 files changed, 267 insertions(+), 5 deletions(-) create mode 100644 Pdf4QtLib/sources/pdfxfaengine.cpp create mode 100644 Pdf4QtLib/sources/pdfxfaengine.h diff --git a/CodeGenerator/CodeGenerator.pro b/CodeGenerator/CodeGenerator.pro index c7da918..21f91e6 100644 --- a/CodeGenerator/CodeGenerator.pro +++ b/CodeGenerator/CodeGenerator.pro @@ -15,9 +15,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with PDF4QT. If not, see . -QT += core gui xml - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +QT += core gui xml widgets CONFIG += c++11 diff --git a/CodeGenerator/codegenerator.h b/CodeGenerator/codegenerator.h index 611bfbc..46afb1e 100644 --- a/CodeGenerator/codegenerator.h +++ b/CodeGenerator/codegenerator.h @@ -446,6 +446,11 @@ private: GeneratedCodeStorage* m_storage = nullptr; }; +class XFACodeGenerator +{ + +}; + } // namespace codegen Q_DECLARE_METATYPE(codegen::GeneratedCodeStorage*) diff --git a/CodeGenerator/generatormainwindow.cpp b/CodeGenerator/generatormainwindow.cpp index c37dc43..d8faeff 100644 --- a/CodeGenerator/generatormainwindow.cpp +++ b/CodeGenerator/generatormainwindow.cpp @@ -88,6 +88,9 @@ void GeneratorMainWindow::saveSettings() settings.setValue("fileName", m_defaultFileName); settings.setValue("headerFile", m_headerFileName); settings.setValue("sourceFile", m_sourceFileName); + settings.setValue("XFAdefinitionFileName", m_XFAdefinitionFileName); + settings.setValue("XFAheaderFileName", m_XFAheaderFileName); + settings.setValue("XFAsourceFileName", m_XFAsourceFileName); } void GeneratorMainWindow::loadGeneratedSettings() @@ -356,6 +359,9 @@ void GeneratorMainWindow::loadSettings() m_defaultFileName = settings.value("fileName").toString(); m_headerFileName = settings.value("headerFile", QVariant()).toString(); m_sourceFileName = settings.value("sourceFile", QVariant()).toString(); + m_XFAdefinitionFileName = settings.value("XFAdefinitionFileName", QVariant()).toString(); + m_XFAheaderFileName = settings.value("XFAheaderFileName", QVariant()).toString(); + m_XFAsourceFileName = settings.value("XFAsourceFileName", QVariant()).toString(); } void GeneratorMainWindow::save(const QString& fileName) @@ -521,3 +527,38 @@ void GeneratorMainWindow::on_actionGenerate_code_triggered() m_generator->generateCode(m_headerFileName, m_sourceFileName); } } + +void GeneratorMainWindow::on_actionSet_code_header_XFA_triggered() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Select cpp header"), QString(), "cpp header (*.h)"); + if (!fileName.isEmpty()) + { + m_XFAheaderFileName = fileName; + saveSettings(); + } +} + +void GeneratorMainWindow::on_actionSet_code_source_XFA_triggered() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Select cpp source"), QString(), "cpp source (*.cpp)"); + if (!fileName.isEmpty()) + { + m_XFAsourceFileName = fileName; + saveSettings(); + } +} + +void GeneratorMainWindow::on_actionSet_XFA_description_triggered() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Select xml definition"), QString(), "XML file (*.xml)"); + if (!fileName.isEmpty()) + { + m_XFAdefinitionFileName = fileName; + saveSettings(); + } +} + +void GeneratorMainWindow::on_actionGenerate_XFA_code_triggered() +{ + +} diff --git a/CodeGenerator/generatormainwindow.h b/CodeGenerator/generatormainwindow.h index dc510d2..2828b24 100644 --- a/CodeGenerator/generatormainwindow.h +++ b/CodeGenerator/generatormainwindow.h @@ -80,6 +80,10 @@ private slots: void on_actionSet_code_header_h_triggered(); void on_actionSet_code_source_cpp_triggered(); void on_actionGenerate_code_triggered(); + void on_actionSet_code_header_XFA_triggered(); + void on_actionSet_code_source_XFA_triggered(); + void on_actionGenerate_XFA_code_triggered(); + void on_actionSet_XFA_description_triggered(); private: void loadSettings(); @@ -104,6 +108,10 @@ private: QString m_sourceFileName; std::map m_mapFunctionToWidgetItem; bool m_isLoadingData; + + QString m_XFAdefinitionFileName; + QString m_XFAheaderFileName; + QString m_XFAsourceFileName; }; #endif // GENERATORMAINWINDOW_H diff --git a/CodeGenerator/generatormainwindow.ui b/CodeGenerator/generatormainwindow.ui index 10fac04..2114f57 100644 --- a/CodeGenerator/generatormainwindow.ui +++ b/CodeGenerator/generatormainwindow.ui @@ -241,8 +241,18 @@ + + + XFA + + + + + + + @@ -284,6 +294,26 @@ Ctrl+G + + + Set code header XFA + + + + + Set code source XFA + + + + + Generate XFA code + + + + + Set XFA description + + diff --git a/Pdf4QtLib/Pdf4QtLib.pro b/Pdf4QtLib/Pdf4QtLib.pro index e10897a..3f6d8a0 100644 --- a/Pdf4QtLib/Pdf4QtLib.pro +++ b/Pdf4QtLib/Pdf4QtLib.pro @@ -91,6 +91,7 @@ SOURCES += \ sources/pdfutils.cpp \ sources/pdfwidgettool.cpp \ sources/pdfwidgetutils.cpp \ + sources/pdfxfaengine.cpp \ sources/pdfxreftable.cpp \ sources/pdfvisitor.cpp \ sources/pdfencoding.cpp \ @@ -165,6 +166,7 @@ HEADERS += \ sources/pdftransparencyrenderer.h \ sources/pdfwidgettool.h \ sources/pdfwidgetutils.h \ + sources/pdfxfaengine.h \ sources/pdfxreftable.h \ sources/pdfflatmap.h \ sources/pdfvisitor.h \ diff --git a/Pdf4QtLib/sources/pdfxfaengine.cpp b/Pdf4QtLib/sources/pdfxfaengine.cpp new file mode 100644 index 0000000..cc5235c --- /dev/null +++ b/Pdf4QtLib/sources/pdfxfaengine.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2021 Jakub Melka +// +// This file is part of PDF4QT. +// +// PDF4QT is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// with the written consent of the copyright owner, any later version. +// +// PDF4QT is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with PDF4QT. If not, see . + +#include "pdfxfaengine.h" + + +namespace pdf +{ + +/* START GENERATED CODE */ + +/* END GENERATED CODE */ + +} // namespace pdf diff --git a/Pdf4QtLib/sources/pdfxfaengine.h b/Pdf4QtLib/sources/pdfxfaengine.h new file mode 100644 index 0000000..2910f72 --- /dev/null +++ b/Pdf4QtLib/sources/pdfxfaengine.h @@ -0,0 +1,150 @@ +// Copyright (C) 2021 Jakub Melka +// +// This file is part of PDF4QT. +// +// PDF4QT is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// with the written consent of the copyright owner, any later version. +// +// PDF4QT is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with PDF4QT. If not, see . + +#ifndef PDFXFAENGINE_H +#define PDFXFAENGINE_H + +#include "pdfglobal.h" + +#include +#include + +namespace pdf +{ + +namespace xfa +{ +struct XFA_InplaceTag; +struct XFA_SharedMemoryTag; + +template +class PDFXFAValueHolder +{ +public: + constexpr inline bool hasValue() const { return false; } + constexpr const Value* getValue() const { return nullptr; } +}; + +template +class PDFXFAValueHolder +{ +public: + inline constexpr PDFXFAValueHolder(std::optional value) : + m_value(std::move(value)) + { + + } + + constexpr inline bool hasValue() const { return m_value.has_value(); } + constexpr const Value* getValue() const { return m_value.has_value() ? &m_value.value() : nullptr; } + +private: + std::optional m_value; +}; + +template +class PDFXFAValueHolder +{ +public: + inline constexpr PDFXFAValueHolder(std::optional value) : + m_value() + { + if (value) + { + m_value = std::make_shared(std::move(*value)); + } + } + + constexpr inline bool hasValue() const { return m_value; } + constexpr const Value* getValue() const { return m_value.get(); } + +private: + std::shared_ptr m_value; +}; + +template +using XFA_Attribute = PDFXFAValueHolder; + +template +using XFA_Node = PDFXFAValueHolder; + +class XFA_Measurement +{ +public: + enum Type + { + in, + cm, + mm, + pt, + em, + percent + }; + + constexpr inline XFA_Measurement() : + m_value(0.0), + m_type(in) + { + + } + + constexpr inline XFA_Measurement(PDFReal value, Type type) : + m_value(value), + m_type(type) + { + + } + + constexpr inline XFA_Measurement(PDFReal value) : + m_value(value), + m_type(in) + { + + } + + constexpr PDFReal getValue() const { return m_value; } + constexpr Type getType() const { return m_type; } + +private: + PDFReal m_value; + Type m_type; +}; + +class XFA_AbstractNode +{ +public: + constexpr inline XFA_AbstractNode() = default; + virtual ~XFA_AbstractNode(); +}; + +} // namespace xfa + +class PDFXFAEngine +{ +public: + PDFXFAEngine(); + +private: +}; + +/* START GENERATED CODE */ + +/* END GENERATED CODE */ + +} // namespace pdf + +#endif // PDFXFAENGINE_H diff --git a/README.md b/README.md index ab1b468..c3faeb4 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,9 @@ Software have following features (the list is not complete): - [x] audio book conversion - [x] internal structure inspector - [x] compare documents -- [ ] XFA support *(planned in year 2022)* +- [ ] XFA support *(planned in year 2021)* - [ ] create fillable forms *(planned in year 2022)* -- [ ] electronically/digitally sign documents *(planned in year 2023)* +- [ ] electronically/digitally sign documents *(planned in year 2022)* - [ ] 3D PDF support *(planned in year 2023)* - [ ] watermarks / headers / footers *(planned in year 2023)* - [ ] presentation application *(planned in year 2023)*