forked from ONLYOFFICE/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.cpp
More file actions
224 lines (178 loc) · 7.06 KB
/
common.cpp
File metadata and controls
224 lines (178 loc) · 7.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* (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 "common.h"
#include "../../OfficeUtils/src/OfficeUtils.h"
#include "Reader/Converter/pptx_package.h"
#include "Writer/Converter/Converter.h"
#include "Writer/Converter/PptxConverter.h"
#include "Writer/Format/office_elements.h"
boost::shared_ptr<cpdoccore::odf_reader::odf_document> ReadOdfDocument(const std::wstring& from, const std::wstring& temp, const std::wstring& tempUnpackedOdf)
{
COfficeUtils oCOfficeUtils(NULL);
if (S_OK == oCOfficeUtils.ExtractToDirectory(from, tempUnpackedOdf, NULL, 0))
return boost::make_shared<cpdoccore::odf_reader::odf_document>(tempUnpackedOdf, temp, L"");
else
return nullptr;
}
boost::shared_ptr<cpdoccore::oox::pptx_conversion_context> Convert(boost::shared_ptr<cpdoccore::odf_reader::odf_document> inputOdf)
{
cpdoccore::oox::package::pptx_document outputPptx;
boost::shared_ptr<cpdoccore::oox::pptx_conversion_context> conversionContext = boost::make_shared<cpdoccore::oox::pptx_conversion_context>(inputOdf.get());
conversionContext->set_output_document(&outputPptx);
conversionContext->set_font_directory(L"");
inputOdf->pptx_convert(*conversionContext);
return conversionContext;
}
ODP2OOX_AnimationEnvironment::ODP2OOX_AnimationEnvironment(const std::wstring& exampleFilename, boost::shared_ptr<cpdoccore::odf_reader::odf_document>* doc, boost::shared_ptr<cpdoccore::oox::pptx_conversion_context>* context)
: testing::Environment()
{
sExampleFilename = NSFile::GetFileName(exampleFilename);
mDocument = doc;
mContext = context;
}
ODP2OOX_AnimationEnvironment::~ODP2OOX_AnimationEnvironment()
{
}
void ODP2OOX_AnimationEnvironment::SetUp()
{
std::wstring rootDir = NSFile::GetProcessDirectory() + CH_DIR("..");
std::wstring sExampleFilesDirectory = rootDir + CH_DIR("ExampleFiles");
sFrom = sExampleFilesDirectory + FILE_SEPARATOR_STR + sExampleFilename;
sTemp = sFrom + _T(".tmp");
sTempUnpackedOdf = sTemp + CH_DIR("odf_unpacked");
NSDirectory::CreateDirectory(sTemp);
NSDirectory::CreateDirectory(sTempUnpackedOdf);
*mDocument = ReadOdfDocument(sFrom, sTemp, sTempUnpackedOdf);
*mContext = Convert(*mDocument);
}
void ODP2OOX_AnimationEnvironment::TearDown()
{
NSDirectory::DeleteDirectory(sTemp);
}
//////////////////////////////////////////////////////////////////////////
OOX2ODP_AnimationEnvironment::OOX2ODP_AnimationEnvironment(const std::wstring& exampleFilename, boost::shared_ptr<Oox2Odf::Converter>* converter, cpdoccore::odf_writer::odp_conversion_context** context)
{
mExampleFilename = exampleFilename;
mConverter = converter;
mContext = context;
}
void OOX2ODP_AnimationEnvironment::SetUp()
{
std::wstring rootDir = NSFile::GetProcessDirectory() + CH_DIR("..");
std::wstring exampleFilesDirectory = rootDir + CH_DIR("ExampleFiles");
mFrom = exampleFilesDirectory + FILE_SEPARATOR_STR + mExampleFilename;
mTemp = mFrom + _T(".tmp");
mTempUnpackedOox = mTemp + CH_DIR("pptx_unpacked");
NSDirectory::CreateDirectory(mTemp);
NSDirectory::CreateDirectory(mTempUnpackedOox);
COfficeUtils oCOfficeUtils(NULL);
if (S_OK == oCOfficeUtils.ExtractToDirectory(mFrom, mTempUnpackedOox, NULL, 0))
{
*mConverter = boost::make_shared<Oox2Odf::Converter>(mTempUnpackedOox, _T("presentation"), L"", false, mTemp);
try
{
(*mConverter)->convert();
*mContext = dynamic_cast<cpdoccore::odf_writer::odp_conversion_context*>((*mConverter)->get_ooxConverter()->odf_context());
}
catch (...)
{
_CP_LOG << L"[ error ]: Failed to setup OOX2ODP_EntranceAnimationTestEnvironment";
}
}
}
void OOX2ODP_AnimationEnvironment::TearDown()
{
NSDirectory::DeleteDirectory(mTemp);
}
const cpdoccore::odf_writer::anim_par* OOX2ODP_AnimationTest::GetTimingRoot()
{
using namespace cpdoccore::odf_writer;
draw_page* page = dynamic_cast<draw_page*>(mContext->current_slide().page_elm_.get());
if (!page)
return nullptr;
anim_par* timing_root = dynamic_cast<anim_par*>(page->animation_.get());
if (!timing_root)
return nullptr;
return timing_root;
}
const cpdoccore::odf_writer::anim_seq* OOX2ODP_AnimationTest::GetMainSequence()
{
using namespace cpdoccore::odf_writer;
const anim_par* timing_root = GetTimingRoot();
if (!timing_root)
return nullptr;
if (timing_root->anim_seq_array_.size() < 1)
return nullptr;
const anim_seq* main_sequence = dynamic_cast<anim_seq*>(timing_root->anim_seq_array_.at(0).get());
if (!main_sequence)
return nullptr;
return main_sequence;
}
const cpdoccore::odf_writer::anim_par* OOX2ODP_AnimationTest::GetMainSequenceParByIndex(size_t index)
{
using namespace cpdoccore::odf_writer;
const anim_seq* main_sequence = GetMainSequence();
if (index >= main_sequence->anim_par_array_.size())
return nullptr;
const anim_par* par = dynamic_cast<anim_par*>(main_sequence->anim_par_array_[index].get());
if (!par)
return nullptr;
return par;
}
const cpdoccore::odf_writer::anim_par* OOX2ODP_AnimationTest::GetInnerPar(const cpdoccore::odf_writer::anim_par* par)
{
using namespace cpdoccore::odf_writer;
if (!par)
return nullptr;
const anim_par* inner_par = dynamic_cast<anim_par*>(par->anim_par_.get());
if (!inner_par)
return nullptr;
return inner_par;
}
const cpdoccore::odf_writer::anim_par* OOX2ODP_AnimationTest::GetInnermostPar(const cpdoccore::odf_writer::anim_par* par)
{
using namespace cpdoccore::odf_writer;
if (!par)
return nullptr;
const anim_par* innermost = GetInnerPar(par);
while (innermost->anim_par_)
{
innermost = dynamic_cast<anim_par*>(innermost->anim_par_.get());
if (!innermost)
return nullptr;
}
return innermost;
}
const cpdoccore::odf_writer::odp_conversion_context* OOX2ODP_AnimationTest::GetContext() const
{
return mContext;
}