mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-11 05:24:10 +08:00
Co-authored-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com> Co-committed-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com>
222 lines
6.4 KiB
C++
222 lines
6.4 KiB
C++
/*
|
|
* Copyright (C) Ascensio System SIA, 2009-2026
|
|
*
|
|
* 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, together with the
|
|
* additional terms provided in the LICENSE file.
|
|
*
|
|
* 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: https://www.gnu.org/licenses/agpl-3.0.html
|
|
*
|
|
* You can contact Ascensio System SIA by email at info@onlyoffice.com
|
|
* or by postal mail at 20A-6 Ernesta Birznieka-Upisha Street, Riga,
|
|
* LV-1050, Latvia, European Union.
|
|
*
|
|
* The interactive user interfaces in modified versions of the Program
|
|
* are required to display Appropriate Legal Notices in accordance with
|
|
* Section 5 of the GNU AGPL version 3.
|
|
*
|
|
* No trademark rights are granted under this License.
|
|
*
|
|
* All non-code elements of the Product, including illustrations,
|
|
* icon sets, and technical writing content, are licensed under the
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License:
|
|
* https://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
*
|
|
* This license applies only to such non-code elements and does not
|
|
* modify or replace the licensing terms applicable to the Program's
|
|
* source code, which remains licensed under the GNU Affero General
|
|
* Public License v3.
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
#include "Docx.h"
|
|
|
|
#include "App.h"
|
|
#include "Core.h"
|
|
#include "Document.h"
|
|
#include "FontTable.h"
|
|
#include "Numbering.h"
|
|
#include "Comments.h"
|
|
#include "Styles.h"
|
|
#include "Footnote.h"
|
|
#include "Endnote.h"
|
|
#include "Settings/Settings.h"
|
|
#include "Media/VbaProject.h"
|
|
#include "Media/JsaProject.h"
|
|
#include "HeaderFooter.h"
|
|
#include "CustomXml.h"
|
|
|
|
#include "../PPTXFormat/Theme.h"
|
|
#include "../../DesktopEditor/common/Directory.h"
|
|
|
|
namespace OOX
|
|
{
|
|
void CDocx::_part_summary::init()
|
|
{
|
|
document = NULL;
|
|
fontTable = NULL;
|
|
numbering = NULL;
|
|
styles = NULL;
|
|
footnotes = NULL;
|
|
endnotes = NULL;
|
|
settings = NULL;
|
|
comments = NULL;
|
|
}
|
|
|
|
CDocx::CDocx() : OOX::IFileContainer(dynamic_cast<OOX::Document*>(this))
|
|
{
|
|
init();
|
|
}
|
|
CDocx::CDocx(const CPath& oFilePath) : OOX::IFileContainer(this)
|
|
{
|
|
init();
|
|
Read( oFilePath );
|
|
}
|
|
CDocx::~CDocx()
|
|
{
|
|
m_oMain.init();
|
|
m_oGlossary.init();
|
|
|
|
m_pApp = NULL;
|
|
m_pCore = NULL;
|
|
m_pTheme = NULL;
|
|
|
|
m_pCommentsExt = NULL;
|
|
m_pCommentsExtensible = NULL;
|
|
m_pCommentsIds = NULL;
|
|
m_pPeople = NULL;
|
|
m_pDocumentComments = NULL;
|
|
m_pDocumentCommentsExt = NULL;
|
|
m_pDocumentCommentsExtensible = NULL;
|
|
m_pDocumentPeople = NULL;
|
|
m_pDocumentCommentsIds = NULL;
|
|
m_pCommentsUserData = NULL;
|
|
|
|
m_pVbaProject = NULL;
|
|
m_pJsaProject = NULL;
|
|
}
|
|
bool CDocx::Write(const CPath& oFilePath)
|
|
{
|
|
// Create folder
|
|
std::wstring filePath = oFilePath.GetPath();
|
|
NSDirectory::CreateDirectory(filePath);
|
|
|
|
OOX::CRels oRels;
|
|
OOX::CContentTypes oContent;
|
|
|
|
IFileContainer::Write( oRels, oFilePath, OOX::CPath( L"" ), oContent );
|
|
oRels.Write( oFilePath / FILE_SEPARATOR_STR );
|
|
oContent.Write( oFilePath );
|
|
|
|
return true;
|
|
}
|
|
bool CDocx::Read(const CPath& oFilePath)
|
|
{
|
|
m_sDocumentPath = oFilePath.GetPath();
|
|
|
|
// Find "/_rels/.rels" and read all files by relationships
|
|
OOX::CRels oRels( oFilePath / FILE_SEPARATOR_STR );
|
|
IFileContainer::Read( oRels, oFilePath, oFilePath );
|
|
|
|
FixAfterRead();
|
|
return true;
|
|
}
|
|
void CDocx::FixAfterRead()
|
|
{
|
|
//solve id conflict between comments and documentComments
|
|
if ((NULL != m_oMain.comments && NULL != m_pDocumentComments) && (false == m_oMain.comments->m_arrComments.empty() && false != m_pDocumentComments->m_arrComments.empty()))
|
|
{
|
|
int maxId = INT_MIN;
|
|
for (size_t i = 0; i < m_oMain.comments->m_arrComments.size(); ++i)
|
|
{
|
|
OOX::CComment* pComment = m_oMain.comments->m_arrComments[i];
|
|
if (pComment->m_oId.IsInit() && maxId < pComment->m_oId->GetValue())
|
|
{
|
|
maxId = pComment->m_oId->GetValue();
|
|
}
|
|
}
|
|
m_pDocumentComments->m_mapComments.clear();
|
|
for (size_t i = 0; i < m_pDocumentComments->m_arrComments.size(); ++i)
|
|
{
|
|
OOX::CComment* pComment = m_pDocumentComments->m_arrComments[i];
|
|
pComment->m_oId.Init();
|
|
pComment->m_oId->SetValue(++maxId);
|
|
m_pDocumentComments->m_mapComments.insert( std::make_pair( pComment->m_oId->GetValue(), i));
|
|
}
|
|
}
|
|
}
|
|
OOX::CHdrFtr *CDocx::GetHeaderOrFooter(const OOX::RId& rId, bool glossary) const
|
|
{
|
|
if (glossary && m_oGlossary.document)
|
|
{
|
|
OOX::IFileContainer* pDocumentContainer = (OOX::IFileContainer*)m_oGlossary.document;
|
|
|
|
smart_ptr<OOX::File> pFile = pDocumentContainer->Find(rId);
|
|
if (pFile.IsInit() && (OOX::FileTypes::Header == pFile->type() || OOX::FileTypes::Footer == pFile->type()))
|
|
return (OOX::CHdrFtr*)pFile.GetPointer();
|
|
else
|
|
return NULL;
|
|
}
|
|
else if (!glossary && m_oMain.document)
|
|
{
|
|
OOX::IFileContainer* pDocumentContainer = (OOX::IFileContainer*)m_oMain.document;
|
|
|
|
smart_ptr<OOX::File> pFile = pDocumentContainer->Find( rId );
|
|
if ( pFile.IsInit() && ( OOX::FileTypes::Header == pFile->type() || OOX::FileTypes::Footer == pFile->type() ) )
|
|
return (OOX::CHdrFtr*)pFile.GetPointer();
|
|
else
|
|
return NULL;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
const std::wstring CDocx::GetCustomSettings() const
|
|
{
|
|
if (m_oMain.document)
|
|
{
|
|
std::vector<smart_ptr<OOX::File>>& container = m_oMain.document->GetContainer();
|
|
for (size_t i = 0; i < container.size(); ++i)
|
|
{
|
|
if (OOX::FileTypes::CustomXml == container[i]->type())
|
|
{
|
|
OOX::CCustomXML* pCustomXml = dynamic_cast<OOX::CCustomXML*>(container[i].GetPointer());
|
|
if(OOX::CSettingsCustom::GetSchemaUrl() == pCustomXml->GetSchemaUrl())
|
|
{
|
|
pCustomXml->m_bUsed = true;
|
|
return NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)pCustomXml->m_sXmlA.c_str(), pCustomXml->m_sXmlA.length());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return L"";
|
|
}
|
|
void CDocx::init()
|
|
{
|
|
m_oMain.init();
|
|
m_oGlossary.init();
|
|
|
|
m_pApp = NULL;
|
|
m_pCore = NULL;
|
|
m_pTheme = NULL;
|
|
|
|
m_pCommentsExt = NULL;
|
|
m_pCommentsExtensible = NULL;
|
|
m_pCommentsIds = NULL;
|
|
m_pPeople = NULL;
|
|
m_pDocumentComments = NULL;
|
|
m_pDocumentCommentsExt = NULL;
|
|
m_pDocumentCommentsExtensible = NULL;
|
|
m_pDocumentPeople = NULL;
|
|
m_pDocumentCommentsIds = NULL;
|
|
m_pCommentsUserData = NULL;
|
|
|
|
m_pVbaProject = NULL;
|
|
m_pJsaProject = NULL;
|
|
|
|
m_bGlossaryRead = false;
|
|
}
|
|
}
|