Add odg file format conversion

This commit is contained in:
Kamil Kerimov
2024-03-11 18:25:03 +05:00
parent f10ad91f0f
commit 320dcf8a0f
10 changed files with 256 additions and 0 deletions

View File

@ -1084,6 +1084,7 @@ bool COfficeFileFormatChecker::isOpenOfficeFormatFile(const std::wstring &fileNa
const char *odtFormatLine = "application/vnd.oasis.opendocument.text"; const char *odtFormatLine = "application/vnd.oasis.opendocument.text";
const char *odsFormatLine = "application/vnd.oasis.opendocument.spreadsheet"; const char *odsFormatLine = "application/vnd.oasis.opendocument.spreadsheet";
const char *odpFormatLine = "application/vnd.oasis.opendocument.presentation"; const char *odpFormatLine = "application/vnd.oasis.opendocument.presentation";
const char* odgFormatLine = "application/vnd.oasis.opendocument.graphics";
const char *ottFormatLine = "application/vnd.oasis.opendocument.text-template"; const char *ottFormatLine = "application/vnd.oasis.opendocument.text-template";
const char *otsFormatLine = "application/vnd.oasis.opendocument.spreadsheet-template"; const char *otsFormatLine = "application/vnd.oasis.opendocument.spreadsheet-template";
const char *otpFormatLine = "application/vnd.oasis.opendocument.presentation-template"; const char *otpFormatLine = "application/vnd.oasis.opendocument.presentation-template";
@ -1134,6 +1135,10 @@ bool COfficeFileFormatChecker::isOpenOfficeFormatFile(const std::wstring &fileNa
{ {
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_ODP; nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_ODP;
} }
else if (NULL != strstr((char*)pBuffer, odgFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_ODG;
}
else if (NULL != strstr((char *)pBuffer, epubFormatLine)) else if (NULL != strstr((char *)pBuffer, epubFormatLine))
{ {
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_EPUB; nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_EPUB;

View File

@ -71,6 +71,7 @@
#define AVS_OFFICESTUDIO_FILE_PRESENTATION_ODP_FLAT AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0009 #define AVS_OFFICESTUDIO_FILE_PRESENTATION_ODP_FLAT AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0009
#define AVS_OFFICESTUDIO_FILE_PRESENTATION_OTP AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x000a #define AVS_OFFICESTUDIO_FILE_PRESENTATION_OTP AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x000a
#define AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX_PACKAGE AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x000b #define AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX_PACKAGE AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x000b
#define AVS_OFFICESTUDIO_FILE_PRESENTATION_ODG AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x000c
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET 0x0100 #define AVS_OFFICESTUDIO_FILE_SPREADSHEET 0x0100
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0001 #define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0001

View File

@ -574,6 +574,7 @@ enum ElementType
typeOfficeScripts, typeOfficeScripts,
typeOfficeScript, typeOfficeScript,
typeOfficePresentation, typeOfficePresentation,
typeOfficeDrawing,
typeOfficeChart, typeOfficeChart,
typeOfficeEventListeners, typeOfficeEventListeners,

View File

@ -387,6 +387,7 @@ SOURCES += \
../../Writer/Format/odp_page_state.cpp \ ../../Writer/Format/odp_page_state.cpp \
../../Writer/Format/odp_slide_context.cpp \ ../../Writer/Format/odp_slide_context.cpp \
../../Writer/Format/office_presentation.cpp \ ../../Writer/Format/office_presentation.cpp \
../../Writer/Format/office_drawing.cpp \
../../Writer/Format/style_presentation.cpp \ ../../Writer/Format/style_presentation.cpp \
../../Writer/Format/odf_math_context.cpp \ ../../Writer/Format/odf_math_context.cpp \
../../Writer/Format/math_elementaries.cpp \ ../../Writer/Format/math_elementaries.cpp \
@ -594,6 +595,7 @@ HEADERS += \
../../Reader/Format/office_elements_type.h \ ../../Reader/Format/office_elements_type.h \
../../Reader/Format/office_event_listeners.h \ ../../Reader/Format/office_event_listeners.h \
../../Reader/Format/office_presentation.h \ ../../Reader/Format/office_presentation.h \
../../Reader/Format/office_drawing.h \
../../Reader/Format/office_scripts.h \ ../../Reader/Format/office_scripts.h \
../../Reader/Format/office_forms.h \ ../../Reader/Format/office_forms.h \
../../Reader/Format/office_settings.h \ ../../Reader/Format/office_settings.h \

View File

@ -62,6 +62,7 @@
#include "../../Reader/Format/office_elements_create.cpp" #include "../../Reader/Format/office_elements_create.cpp"
#include "../../Reader/Format/office_event_listeners.cpp" #include "../../Reader/Format/office_event_listeners.cpp"
#include "../../Reader/Format/office_presentation.cpp" #include "../../Reader/Format/office_presentation.cpp"
#include "../../Reader/Format/office_drawing.cpp"
#include "../../Reader/Format/office_scripts.cpp" #include "../../Reader/Format/office_scripts.cpp"
#include "../../Reader/Format/office_forms.cpp" #include "../../Reader/Format/office_forms.cpp"
#include "../../Reader/Format/office_settings.cpp" #include "../../Reader/Format/office_settings.cpp"

View File

@ -120,6 +120,7 @@ _UINT32 ConvertODF2OOXml(const std::wstring & srcPath, const std::wstring & dstP
break; break;
case 3: case 3:
case 6: case 6:
case 7:
nResult = ConvertOdp2Pptx(inputOdf, dstPath, fontsPath); nResult = ConvertOdp2Pptx(inputOdf, dstPath, fontsPath);
break; break;
} }

View File

@ -50,6 +50,7 @@
#include "office_text.h" #include "office_text.h"
#include "office_spreadsheet.h" #include "office_spreadsheet.h"
#include "office_presentation.h" #include "office_presentation.h"
#include "office_drawing.h"
#include "office_chart.h" #include "office_chart.h"
#include "office_annotation.h" #include "office_annotation.h"
#include "office_settings.h" #include "office_settings.h"
@ -540,6 +541,10 @@ int odf_document::Impl::GetMimetype(std::wstring value)
{ {
return 6; return 6;
} }
else if (std::wstring::npos != value.find(L"application/vnd.oasis.opendocument.graphics"))
{
return 7;
}
return 0; return 0;
} }
void odf_document::Impl::parse_manifests(office_element *element) void odf_document::Impl::parse_manifests(office_element *element)

View File

@ -0,0 +1,160 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "office_drawing.h"
#include "draw_page.h"
#include <xml/xmlchar.h>
#include "odf_document.h"
#include "odfcontext.h"
#include "serialize_elements.h"
namespace cpdoccore {
namespace odf_reader {
const wchar_t* office_drawing::ns = L"office";
const wchar_t* office_drawing::name = L"drawing";
void office_drawing::add_child_element(xml::sax* Reader, const std::wstring& Ns, const std::wstring& Name)
{
if CP_CHECK_NAME(L"draw", L"page")
{
CP_CREATE_ELEMENT(pages_);
}
else if CP_CHECK_NAME(L"table", L"tracked-changes")
{
CP_CREATE_ELEMENT(tracked_changes_);
}
else if CP_CHECK_NAME(L"table", L"content-validations")
{
CP_CREATE_ELEMENT(content_validations_);
}
else if CP_CHECK_NAME(L"presentation", L"footer-decl")
{
CP_CREATE_ELEMENT(footer_decls_);
}
else if CP_CHECK_NAME(L"presentation", L"date-time-decl")
{
CP_CREATE_ELEMENT(date_time_decls_);
}
else if CP_CHECK_NAME(L"text", L"user-field-decls")
{
CP_CREATE_ELEMENT(user_fields_);
}
else if CP_CHECK_NAME(L"text", L"sequence-decls")
{
CP_CREATE_ELEMENT(sequences_);
}
else if CP_CHECK_NAME(L"text", L"variable-decls")
{
CP_CREATE_ELEMENT(variables_);
}
}
void office_drawing::add_text(const std::wstring& Text)
{
}
void office_drawing::add_attributes(const xml::attributes_wc_ptr& Attributes)
{
}
void office_drawing::docx_convert(oox::docx_conversion_context& Context)
{
Context.start_office_text();
_CP_LOG << L"[info][docx] process pages (" << pages_.size() << L" elmements)" << std::endl;
for (size_t i = 0; i < pages_.size(); i++)
{
pages_[i]->docx_convert(Context);
}
Context.end_office_text();
}
void office_drawing::xlsx_convert(oox::xlsx_conversion_context& Context)
{
Context.start_office_spreadsheet(this);
_CP_LOG << L"[info][xlsx] process pages (" << pages_.size() << L" elmements)" << std::endl;
for (size_t i = 0; i < pages_.size(); i++)
{
pages_[i]->xlsx_convert(Context);
}
Context.end_office_spreadsheet();
}
void office_drawing::pptx_convert(oox::pptx_conversion_context& Context)
{
Context.start_office_presentation();
_CP_LOG << L"[info][pptx] process pages(" << pages_.size() << L" elmements)" << std::endl;
for (size_t i = 0; i < footer_decls_.size(); i++)
{
presentation_footer_decl* style = dynamic_cast<presentation_footer_decl*>(footer_decls_[i].get());
if (!style)
continue;
std::wstring style_name_ = L"footer:" + style->presentation_name_.get_value_or(L"");
Context.root()->odf_context().drawStyles().add(style_name_, footer_decls_[i]);
}
for (size_t i = 0; i < date_time_decls_.size(); i++)
{
presentation_date_time_decl* style = dynamic_cast<presentation_date_time_decl*>(date_time_decls_[i].get());
if (!style)
continue;
std::wstring style_name_ = L"datetime:" + style->presentation_name_.get_value_or(L"");
Context.root()->odf_context().drawStyles().add(style_name_, date_time_decls_[i]);
}
if (user_fields_)
user_fields_->pptx_convert(Context);
if (variables_)
variables_->pptx_convert(Context);
if (sequences_)
sequences_->pptx_convert(Context);
for (size_t i = 0; i < pages_.size(); i++)
{
pages_[i]->pptx_convert(Context);
}
Context.end_office_presentation();
}
}
}

View File

@ -0,0 +1,79 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include <iosfwd>
#include "office_elements.h"
#include "office_elements_create.h"
namespace cpdoccore {
namespace odf_reader {
class office_drawing : public office_element_impl<office_drawing>
{
public:
static const wchar_t* ns;
static const wchar_t* name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeOfficeDrawing;
CPDOCCORE_DEFINE_VISITABLE();
virtual void docx_convert(oox::docx_conversion_context& Context);
virtual void xlsx_convert(oox::xlsx_conversion_context& Context);
virtual void pptx_convert(oox::pptx_conversion_context& Context);
private:
virtual void add_attributes(const xml::attributes_wc_ptr& Attributes);
virtual void add_child_element(xml::sax* Reader, const std::wstring& Ns, const std::wstring& Name);
virtual void add_text(const std::wstring& Text);
public:
office_element_ptr tracked_changes_;
office_element_ptr content_validations_;
office_element_ptr_array date_time_decls_;
office_element_ptr_array footer_decls_;
office_element_ptr_array pages_;
office_element_ptr user_fields_;
office_element_ptr variables_;
office_element_ptr sequences_;
};
CP_REGISTER_OFFICE_ELEMENT2(office_drawing);
} // namespace odf_reader
} // namespace cpdoccore

View File

@ -472,6 +472,7 @@ namespace NExtractTools
case AVS_OFFICESTUDIO_FILE_DOCUMENT_OTT: case AVS_OFFICESTUDIO_FILE_DOCUMENT_OTT:
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_OTS: case AVS_OFFICESTUDIO_FILE_SPREADSHEET_OTS:
case AVS_OFFICESTUDIO_FILE_PRESENTATION_OTP: case AVS_OFFICESTUDIO_FILE_PRESENTATION_OTP:
case AVS_OFFICESTUDIO_FILE_PRESENTATION_ODG:
{ {
if (0 == sExt2.compare(L".bin")) if (0 == sExt2.compare(L".bin"))
res = TCD_ODF2OOT_BIN; res = TCD_ODF2OOT_BIN;