XFA: xfa engine basics

This commit is contained in:
Jakub Melka 2021-10-27 19:23:40 +02:00
parent a45807fb34
commit 564c4068a5
9 changed files with 267 additions and 5 deletions

View File

@ -15,9 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += core gui xml widgets
CONFIG += c++11

View File

@ -446,6 +446,11 @@ private:
GeneratedCodeStorage* m_storage = nullptr;
};
class XFACodeGenerator
{
};
} // namespace codegen
Q_DECLARE_METATYPE(codegen::GeneratedCodeStorage*)

View File

@ -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()
{
}

View File

@ -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<codegen::GeneratedFunction*, QTreeWidgetItem*> m_mapFunctionToWidgetItem;
bool m_isLoadingData;
QString m_XFAdefinitionFileName;
QString m_XFAheaderFileName;
QString m_XFAsourceFileName;
};
#endif // GENERATORMAINWINDOW_H

View File

@ -241,8 +241,18 @@
<addaction name="actionSet_code_source_cpp"/>
<addaction name="actionGenerate_code"/>
</widget>
<widget class="QMenu" name="menuXFA">
<property name="title">
<string>XFA</string>
</property>
<addaction name="actionSet_XFA_description"/>
<addaction name="actionSet_code_header_XFA"/>
<addaction name="actionSet_code_source_XFA"/>
<addaction name="actionGenerate_XFA_code"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuCode"/>
<addaction name="menuXFA"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionLoad">
@ -284,6 +294,26 @@
<string>Ctrl+G</string>
</property>
</action>
<action name="actionSet_code_header_XFA">
<property name="text">
<string>Set code header XFA</string>
</property>
</action>
<action name="actionSet_code_source_XFA">
<property name="text">
<string>Set code source XFA</string>
</property>
</action>
<action name="actionGenerate_XFA_code">
<property name="text">
<string>Generate XFA code</string>
</property>
</action>
<action name="actionSet_XFA_description">
<property name="text">
<string>Set XFA description</string>
</property>
</action>
</widget>
<resources/>
<connections/>

View File

@ -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 \

View File

@ -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 <https://www.gnu.org/licenses/>.
#include "pdfxfaengine.h"
namespace pdf
{
/* START GENERATED CODE */
/* END GENERATED CODE */
} // namespace pdf

View File

@ -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 <https://www.gnu.org/licenses/>.
#ifndef PDFXFAENGINE_H
#define PDFXFAENGINE_H
#include "pdfglobal.h"
#include <optional>
#include <memory>
namespace pdf
{
namespace xfa
{
struct XFA_InplaceTag;
struct XFA_SharedMemoryTag;
template<typename Value, struct Tag>
class PDFXFAValueHolder
{
public:
constexpr inline bool hasValue() const { return false; }
constexpr const Value* getValue() const { return nullptr; }
};
template<typename Value>
class PDFXFAValueHolder<Value, XFA_InplaceTag>
{
public:
inline constexpr PDFXFAValueHolder(std::optional<Value> 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<Value> m_value;
};
template<typename Value>
class PDFXFAValueHolder<Value, XFA_SharedMemoryTag>
{
public:
inline constexpr PDFXFAValueHolder(std::optional<Value> 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<Value> m_value;
};
template<typename Value>
using XFA_Attribute = PDFXFAValueHolder<Value, XFA_InplaceTag>;
template<typename Value>
using XFA_Node = PDFXFAValueHolder<Value, typename Value::StorageTag>;
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

View File

@ -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)*