Commit 5f12552f authored by ElenaSubbotina's avatar ElenaSubbotina

XlsFormat - theme

parent d293769c
...@@ -60,7 +60,7 @@ HRESULT convert_single(std::wstring srcFileName) ...@@ -60,7 +60,7 @@ HRESULT convert_single(std::wstring srcFileName)
std::wstring dstPath; std::wstring dstPath;
bool bMacros = true; bool bMacros = true;
hr = ConvertXls2Xlsx(srcFileName, dstTempPath, L"password", L"C:\\Windows\\Fonts", NULL, bMacros); hr = ConvertXls2Xlsx(srcFileName, dstTempPath, L"password", L"C:\\Windows\\Fonts", L"C:\\Windows\\Temp", NULL, bMacros);
if (bMacros) if (bMacros)
{ {
......
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
*/ */
#include "Theme.h" #include "Theme.h"
#include <fstream> #include "../../../DesktopEditor/common/File.h"
#include <iostream> // endl
namespace XLS namespace XLS
{ {
...@@ -59,13 +58,15 @@ void Theme::readFields(CFRecord& record) ...@@ -59,13 +58,15 @@ void Theme::readFields(CFRecord& record)
{ {
//default theme //default theme
} }
else if (dwThemeVersion == 0) //else if (dwThemeVersion == 0)
else
{ {
nThemeDataSize = record.getDataSize() - record.getRdPtr(); nThemeDataSize = record.getDataSize() - record.getRdPtr();
pThemeData = boost::shared_array<char>(new char[nThemeDataSize]); pThemeData = boost::shared_array<char>(new char[nThemeDataSize]);
memcpy(pThemeData.get(), record.getCurData<char>(), nThemeDataSize); memcpy(pThemeData.get(), record.getCurData<char>(), nThemeDataSize);
record.skipNunBytes(nThemeDataSize); record.skipNunBytes(nThemeDataSize);
} }
} }
......
...@@ -94,7 +94,8 @@ void PtgSxName::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool f ...@@ -94,7 +94,8 @@ void PtgSxName::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool f
{ {
_Name = field_db->stFieldName.value(); _Name = field_db->stFieldName.value();
if (std::wstring::npos != _Name.find(L" ")) if (std::wstring::npos != _Name.find(L" ") ||
std::wstring::npos != _Name.find(L":"))
{ {
_Name = L"'" + _Name + L"'"; _Name = L"'" + _Name + L"'";
} }
...@@ -104,7 +105,13 @@ void PtgSxName::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool f ...@@ -104,7 +105,13 @@ void PtgSxName::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool f
SXOPER* cache = dynamic_cast<SXOPER*>(field->m_arSRCSXOPER[pair->iCache].get()); SXOPER* cache = dynamic_cast<SXOPER*>(field->m_arSRCSXOPER[pair->iCache].get());
if (cache) if (cache)
{ {
_Name += L"[" + cache->value + L"]"; std::wstring value = cache->value;
if (std::wstring::npos != value.find(L" ") ||
std::wstring::npos != value.find(L":"))
{
value = L"'" + value + L"'";
}
_Name += L"[" + value + L"]";
} }
} }
} }
......
...@@ -127,7 +127,8 @@ void SXFMLA::serialize_attr(CP_ATTR_NODE) ...@@ -127,7 +127,8 @@ void SXFMLA::serialize_attr(CP_ATTR_NODE)
global_info->arPivotSxNames = m_arPivotSxNames; global_info->arPivotSxNames = m_arPivotSxNames;
CP_XML_ATTR(L"formula", sx_fmla->fmla.getAssembledFormula()); std::wstring fmla = sx_fmla->fmla.getAssembledFormula();
CP_XML_ATTR(L"formula", fmla);
} }
......
...@@ -586,7 +586,7 @@ int ChartSheetSubstream::serialize_3D (std::wostream & _stream) ...@@ -586,7 +586,7 @@ int ChartSheetSubstream::serialize_3D (std::wostream & _stream)
if (ax_parent->iax == 0) //primary axes if (ax_parent->iax == 0) //primary axes
{ {
for (int i = 0 ; i < parent->m_arCRT.size() ; i++) for (size_t i = 0 ; i < parent->m_arCRT.size() ; i++)
{ {
CRT* crt = dynamic_cast<CRT*>(parent->m_arCRT[i].get()); CRT* crt = dynamic_cast<CRT*>(parent->m_arCRT[i].get());
if((crt) && (crt->m_Chart3d)) if((crt) && (crt->m_Chart3d))
......
...@@ -155,6 +155,8 @@ public: ...@@ -155,6 +155,8 @@ public:
CApplicationFonts *applicationFonts; CApplicationFonts *applicationFonts;
std::wstring fontsDirectory; std::wstring fontsDirectory;
std::wstring tempDirectory;
int Version; int Version;
int cmt_rules; int cmt_rules;
......
...@@ -36,9 +36,9 @@ ...@@ -36,9 +36,9 @@
#include "../../../Common/OfficeFileErrorDescription.h" #include "../../../Common/OfficeFileErrorDescription.h"
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const std::wstring & password, const std::wstring & fontsPath, const ProgressCallback* pCallBack, bool &bMacros) long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const std::wstring & password, const std::wstring & fontsPath, const std::wstring & tempPath, const ProgressCallback* pCallBack, bool &bMacros)
{ {
XlsConverter converter(srcFile, dstPath, password, fontsPath, pCallBack, bMacros); XlsConverter converter(srcFile, dstPath, password, fontsPath, tempPath, pCallBack, bMacros);
if (converter.isError()) if (converter.isError())
{ {
......
...@@ -33,4 +33,4 @@ ...@@ -33,4 +33,4 @@
struct ProgressCallback; struct ProgressCallback;
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const std::wstring & password, const std::wstring& fontsPath, const ProgressCallback* CallBack, bool & bMacros); long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const std::wstring & password, const std::wstring& fontsPath, const std::wstring & tempPath, const ProgressCallback* CallBack, bool & bMacros);
\ No newline at end of file \ No newline at end of file
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
#include "../XlsFormat/Logic/Biff_records/IMDATA.h" #include "../XlsFormat/Logic/Biff_records/IMDATA.h"
#include "../XlsFormat/Logic/Biff_records/Note.h" #include "../XlsFormat/Logic/Biff_records/Note.h"
#include "../XlsFormat/Logic/Biff_records/WsBool.h" #include "../XlsFormat/Logic/Biff_records/WsBool.h"
#include "../XlsFormat/Logic/Biff_records/Theme.h"
#include "../XlsFormat/Logic/Biff_structures/URLMoniker.h" #include "../XlsFormat/Logic/Biff_structures/URLMoniker.h"
#include "../XlsFormat/Logic/Biff_structures/FileMoniker.h" #include "../XlsFormat/Logic/Biff_structures/FileMoniker.h"
...@@ -94,9 +95,9 @@ ...@@ -94,9 +95,9 @@
#include <simple_xml_writer.h> #include <simple_xml_writer.h>
#include <utils.h> #include <utils.h>
#include "../../../OfficeUtils/src/OfficeUtils.h"
#include <boost/lexical_cast.hpp> //#include <boost/utility.hpp>
#include <boost/utility.hpp>
#include "../../../DesktopEditor/common/File.h" #include "../../../DesktopEditor/common/File.h"
#include "../../../DesktopEditor/raster/BgraFrame.h" #include "../../../DesktopEditor/raster/BgraFrame.h"
...@@ -127,7 +128,7 @@ typedef struct tagBITMAPCOREHEADER { ...@@ -127,7 +128,7 @@ typedef struct tagBITMAPCOREHEADER {
} BITMAPCOREHEADER; } BITMAPCOREHEADER;
#endif #endif
XlsConverter::XlsConverter(const std::wstring & xlsFileName, const std::wstring & xlsxFilePath, const std::wstring & password, const std::wstring & fontsPath, const ProgressCallback* CallBack, bool & bMacros) XlsConverter::XlsConverter(const std::wstring & xlsFileName, const std::wstring & xlsxFilePath, const std::wstring & password, const std::wstring & fontsPath, const std::wstring & tempPath, const ProgressCallback* CallBack, bool & bMacros)
{ {
xlsx_path = xlsxFilePath; xlsx_path = xlsxFilePath;
output_document = NULL; output_document = NULL;
...@@ -174,6 +175,7 @@ XlsConverter::XlsConverter(const std::wstring & xlsFileName, const std::wstring ...@@ -174,6 +175,7 @@ XlsConverter::XlsConverter(const std::wstring & xlsFileName, const std::wstring
xls_global_info->fontsDirectory = fontsPath; xls_global_info->fontsDirectory = fontsPath;
xls_global_info->password = password; xls_global_info->password = password;
xls_global_info->tempDirectory = tempPath;
XLS::CFStreamCacheReader stream_reader(xls_file->getWorkbookStream(), xls_global_info); XLS::CFStreamCacheReader stream_reader(xls_file->getWorkbookStream(), xls_global_info);
...@@ -1086,9 +1088,45 @@ void XlsConverter::convert(XLS::BACKGROUND * back) ...@@ -1086,9 +1088,45 @@ void XlsConverter::convert(XLS::BACKGROUND * back)
} }
void XlsConverter::convert(XLS::THEME* theme) void XlsConverter::convert(XLS::THEME* THEME_)
{ {
if (theme == NULL) return; if (THEME_ == NULL) return;
XLS::Theme *theme = dynamic_cast<XLS::Theme*>(THEME_->m_Theme.get());
if (!theme) return;
if (theme->nThemeDataSize < 1) return;
std::wstring tempThemePath = xls_global_info->tempDirectory + FILE_SEPARATOR_STR + L"theme.temp";
NSFile::CFileBinary file;
if (!file.CreateFileW(tempThemePath)) return;
file.WriteFile((BYTE*)theme->pThemeData.get(), theme->nThemeDataSize);
file.CloseFile();
COfficeUtils OfficeUtils(NULL);
ULONG nBufferSize = 0;
BYTE *pBuffer = NULL;
HRESULT hresult = OfficeUtils.LoadFileFromArchive(tempThemePath, L"theme1.xml", &pBuffer, nBufferSize);// todooo - parsing ThemeManager
if (hresult != S_OK || pBuffer == NULL)
hresult = OfficeUtils.LoadFileFromArchive(tempThemePath, L"theme/theme1.xml", &pBuffer, nBufferSize);
if (hresult != S_OK || pBuffer == NULL)
hresult = OfficeUtils.LoadFileFromArchive(tempThemePath, L"theme/theme/theme1.xml", &pBuffer, nBufferSize);
if (hresult == S_OK && pBuffer != NULL)
{
oox::package::theme_content_ptr content = oox::package::theme_content::create((char*)pBuffer, nBufferSize);
output_document->get_xl_files().add_theme(content);
delete []pBuffer;
pBuffer = NULL;
}
} }
struct _group_object struct _group_object
......
...@@ -102,7 +102,7 @@ namespace ODRAW ...@@ -102,7 +102,7 @@ namespace ODRAW
class XlsConverter class XlsConverter
{ {
public: public:
XlsConverter(const std::wstring & xlsFileName, const std::wstring & xlsxFilePath, const std::wstring & password, const std::wstring & fontsPath, const ProgressCallback* ffCallBack, bool & bMacros); XlsConverter(const std::wstring & xlsFileName, const std::wstring & xlsxFilePath, const std::wstring & password, const std::wstring & fontsPath, const std::wstring & tempPath, const ProgressCallback* ffCallBack, bool & bMacros);
~XlsConverter() ; ~XlsConverter() ;
oox::xlsx_conversion_context * xlsx_context; oox::xlsx_conversion_context * xlsx_context;
......
...@@ -201,7 +201,23 @@ void rels_files::add(std::wstring const & Id, ...@@ -201,7 +201,23 @@ void rels_files::add(std::wstring const & Id,
{ {
return add(relationship(Id, Type, Target, TargetMode)); return add(relationship(Id, Type, Target, TargetMode));
} }
//--------------------------------------------------------------------------------------------
customXml_content::customXml_content()
{
}
_CP_PTR(customXml_content) customXml_content::create()
{
return boost::make_shared<customXml_content>();
}
//--------------------------------------------------------------------------------------------
theme_content::theme_content(char* data, size_t size)
{
content_ = std::string(data, size);
}
_CP_PTR(theme_content) theme_content::create(char* data, size_t size)
{
return boost::make_shared<theme_content>(data, size);
}
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
chart_content::chart_content() : rels_file_(rels_file::create(L"")) chart_content::chart_content() : rels_file_(rels_file::create(L""))
{ {
......
...@@ -215,6 +215,22 @@ private: ...@@ -215,6 +215,22 @@ private:
std::string content_props; std::string content_props;
}; };
//------------------------------------------------------------------------ //------------------------------------------------------------------------
class theme_content;
typedef _CP_PTR(theme_content) theme_content_ptr;
class theme_content : boost::noncopyable
{
public:
theme_content(char* data, size_t size);
static _CP_PTR(theme_content) create(char* data, size_t size);
std::string content() { return content_; }
friend class xl_theme_files;
private:
std::string content_;
};
//------------------------------------------------------------------------
class document : public element class document : public element
{ {
public: public:
......
...@@ -137,14 +137,6 @@ _CP_PTR(activeX_content) activeX_content::create() ...@@ -137,14 +137,6 @@ _CP_PTR(activeX_content) activeX_content::create()
return boost::make_shared<activeX_content>(); return boost::make_shared<activeX_content>();
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
customXml_content::customXml_content()
{
}
_CP_PTR(customXml_content) customXml_content::create()
{
return boost::make_shared<customXml_content>();
}
//--------------------------------------------------------------------------------------------
sheet_content::sheet_content() : rels_(rels_file::create(L"")) sheet_content::sheet_content() : rels_(rels_file::create(L""))
{ {
...@@ -300,11 +292,15 @@ void xl_files::write(const std::wstring & RootPath) ...@@ -300,11 +292,15 @@ void xl_files::write(const std::wstring & RootPath)
contentTypes.add_override(L"/xl/connections.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml"); contentTypes.add_override(L"/xl/connections.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml");
} }
{
theme_files_.set_rels(&rels_files_);
theme_files_.set_main_document( this->get_main_document() );
theme_files_.write(path);
}
if (styles_) if (styles_)
{ {
styles_->write(path); styles_->write(path);
rels_files_.add( relationship( L"stId1", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", L"styles.xml" ) ); rels_files_.add( relationship( L"stId1", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", L"styles.xml" ) );
} }
if (workbook_) if (workbook_)
...@@ -329,11 +325,6 @@ void xl_files::write(const std::wstring & RootPath) ...@@ -329,11 +325,6 @@ void xl_files::write(const std::wstring & RootPath)
contentTypes.add_override(L"/xl/attachedToolbars.bin", L"application/vnd.ms-excel.attachedToolbars"); contentTypes.add_override(L"/xl/attachedToolbars.bin", L"application/vnd.ms-excel.attachedToolbars");
} }
if (theme_)
{
theme_->write(path);
}
if (media_) if (media_)
{ {
media_->set_main_document(get_main_document()); media_->set_main_document(get_main_document());
...@@ -398,7 +389,6 @@ void xl_files::set_connections(element_ptr Element) ...@@ -398,7 +389,6 @@ void xl_files::set_connections(element_ptr Element)
{ {
connections_ = Element; connections_ = Element;
} }
void xl_files::add_sheet(int type, sheet_content_ptr sheet) void xl_files::add_sheet(int type, sheet_content_ptr sheet)
{ {
sheets_files_.add_sheet(type, sheet); sheets_files_.add_sheet(type, sheet);
...@@ -422,6 +412,10 @@ void xl_files::set_vml_drawings(element_ptr Element) ...@@ -422,6 +412,10 @@ void xl_files::set_vml_drawings(element_ptr Element)
xl_drawings* d = dynamic_cast<xl_drawings*>(vml_drawings_.get()); xl_drawings* d = dynamic_cast<xl_drawings*>(vml_drawings_.get());
d->vml = true; d->vml = true;
} }
void xl_files::add_theme(theme_content_ptr theme)
{
theme_files_.add_theme(theme);
}
void xl_files::add_chart(chart_content_ptr chart) void xl_files::add_chart(chart_content_ptr chart)
{ {
charts_files_.add_chart(chart); charts_files_.add_chart(chart);
...@@ -702,6 +696,44 @@ void xl_customXml_files::write(const std::wstring & RootPath) ...@@ -702,6 +696,44 @@ void xl_customXml_files::write(const std::wstring & RootPath)
} }
} }
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
void xl_theme_files::add_theme(theme_content_ptr themeXml)
{
themes_.push_back(themeXml);
}
void xl_theme_files::write(const std::wstring & RootPath)
{
if (themes_.empty()) return;
std::wstring path = RootPath + FILE_SEPARATOR_STR + L"theme";
NSDirectory::CreateDirectory(path.c_str());
std::wstring path_rels = path + FILE_SEPARATOR_STR + L"_rels";
NSDirectory::CreateDirectory(path_rels.c_str());
content_type & contentTypes = this->get_main_document()->content_type().get_content_type();
static const std::wstring kWSConType = L"application/vnd.openxmlformats-officedocument.theme+xml";
for (size_t i = 0; i < themes_.size(); i++)
{
if (!themes_[i])continue;
const std::wstring fileName = std::wstring(L"theme") + std::to_wstring(i + 1) + L".xml";
contentTypes.add_override(std::wstring(L"/xl/theme/") + fileName, kWSConType);
package::simple_element(fileName, themes_[i]->content()).write(path);
if (rels_)
{
const std::wstring id = std::wstring(L"thmId") + std::to_wstring(i + 1);
static const std::wstring kWSRel = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
const std::wstring fileRef = std::wstring(L"theme/") + fileName;
rels_->add(id, kWSRel, fileRef);
}
}
}
//----------------------------------------------------------------------------------------
void xl_externals_files::add_external(external_content_ptr external) void xl_externals_files::add_external(external_content_ptr external)
{ {
externals_.push_back(external); externals_.push_back(external);
......
...@@ -208,6 +208,21 @@ public: ...@@ -208,6 +208,21 @@ public:
std::vector<customXml_content_ptr> customXmls_; std::vector<customXml_content_ptr> customXmls_;
rels_files * rels_; rels_files * rels_;
}; };
class xl_theme_files : public element
{
public:
xl_theme_files(){}
void set_rels(rels_files * rels)
{
rels_ = rels;
}
void add_theme(theme_content_ptr themeXml);
virtual void write(const std::wstring & RootPath);
std::vector<theme_content_ptr> themes_;
rels_files * rels_;
};
class xl_query_table_files : public element class xl_query_table_files : public element
{ {
public: public:
...@@ -344,6 +359,7 @@ public: ...@@ -344,6 +359,7 @@ public:
void set_vml_drawings (element_ptr Element); void set_vml_drawings (element_ptr Element);
void set_comments (element_ptr Element); void set_comments (element_ptr Element);
void add_theme (theme_content_ptr theme);
void add_chart (chart_content_ptr chart); void add_chart (chart_content_ptr chart);
void add_activeX (activeX_content_ptr activeX); void add_activeX (activeX_content_ptr activeX);
void add_external (external_content_ptr external); void add_external (external_content_ptr external);
...@@ -357,6 +373,7 @@ public: ...@@ -357,6 +373,7 @@ public:
private: private:
rels_files rels_files_; rels_files rels_files_;
sheets_files sheets_files_; sheets_files sheets_files_;
xl_theme_files theme_files_;
xl_charts_files charts_files_; xl_charts_files charts_files_;
xl_externals_files externals_files_; xl_externals_files externals_files_;
xl_pivot_cache_files pivot_cache_files_; xl_pivot_cache_files pivot_cache_files_;
...@@ -366,11 +383,10 @@ private: ...@@ -366,11 +383,10 @@ private:
xl_control_props_files control_props_files_; xl_control_props_files control_props_files_;
xl_table_part_files table_part_files_; xl_table_part_files table_part_files_;
element_ptr theme_;
element_ptr workbook_; element_ptr workbook_;
element_ptr connections_; element_ptr connections_;
element_ptr styles_; element_ptr styles_;
element_ptr sharedStrings_; element_ptr sharedStrings_;
element_ptr media_; element_ptr media_;
element_ptr drawings_; element_ptr drawings_;
......
...@@ -3661,7 +3661,7 @@ namespace NExtractTools ...@@ -3661,7 +3661,7 @@ namespace NExtractTools
{ {
bool bMacros = false; bool bMacros = false;
long hRes = ConvertXls2Xlsx( sFrom, sTo, params.getPassword(), params.getFontPath(), NULL, bMacros); long hRes = ConvertXls2Xlsx( sFrom, sTo, params.getPassword(), params.getFontPath(), sTemp, NULL, bMacros);
if (AVS_ERROR_DRM == hRes) if (AVS_ERROR_DRM == hRes)
{ {
if(!params.getDontSaveAdditional()) if(!params.getDontSaveAdditional())
...@@ -3696,7 +3696,7 @@ namespace NExtractTools ...@@ -3696,7 +3696,7 @@ namespace NExtractTools
{ {
bool bMacros = true; bool bMacros = true;
long hRes = ConvertXls2Xlsx( sFrom, sTo, params.getPassword(), params.getFontPath(), NULL, bMacros); long hRes = ConvertXls2Xlsx( sFrom, sTo, params.getPassword(), params.getFontPath(), sTemp, NULL, bMacros);
if (AVS_ERROR_DRM == hRes) if (AVS_ERROR_DRM == hRes)
{ {
if(!params.getDontSaveAdditional()) if(!params.getDontSaveAdditional())
...@@ -3740,7 +3740,7 @@ namespace NExtractTools ...@@ -3740,7 +3740,7 @@ namespace NExtractTools
bool bMacros = true; bool bMacros = true;
if (ConvertXls2Xlsx( sFrom, sResultXlsxDir, params.getPassword(), params.getFontPath(), NULL, bMacros)== S_OK) if (ConvertXls2Xlsx( sFrom, sResultXlsxDir, params.getPassword(), params.getFontPath(), sTempm NULL, bMacros)== S_OK)
{ {
BinXlsxRW::CXlsxSerializer m_oCXlsxSerializer; BinXlsxRW::CXlsxSerializer m_oCXlsxSerializer;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment