Commit 4176176e authored by Alexey.Musinov's avatar Alexey.Musinov

Merge branch 'develop' of https://github.com/ONLYOFFICE/core into develop

* 'develop' of https://github.com/ONLYOFFICE/core:
  OdfFormat - embedded office text (against text  box)
  .
  OdfFormatReader - presentation - support convert ole objects (and other embedded)
parents 34d03c74 4cf55208
...@@ -426,7 +426,7 @@ void _oox_drawing::serialize_shape(std::wostream & strm) ...@@ -426,7 +426,7 @@ void _oox_drawing::serialize_shape(std::wostream & strm)
} }
} }
void _oox_drawing::serialize_xfrm(std::wostream & strm, const std::wstring & name_space) void _oox_drawing::serialize_xfrm(std::wostream & strm, const std::wstring & name_space, bool always_position)
{ {
CP_XML_WRITER(strm) CP_XML_WRITER(strm)
{ {
...@@ -470,7 +470,7 @@ void _oox_drawing::serialize_xfrm(std::wostream & strm, const std::wstring & nam ...@@ -470,7 +470,7 @@ void _oox_drawing::serialize_xfrm(std::wostream & strm, const std::wstring & nam
CP_XML_NODE(L"a:off") CP_XML_NODE(L"a:off")
{ {
if (inGroup) if (inGroup || always_position)
{ {
CP_XML_ATTR(L"x", x); CP_XML_ATTR(L"x", x);
CP_XML_ATTR(L"y", y); CP_XML_ATTR(L"y", y);
......
...@@ -81,7 +81,7 @@ namespace oox { ...@@ -81,7 +81,7 @@ namespace oox {
virtual void serialize (std::wostream & strm) = 0; virtual void serialize (std::wostream & strm) = 0;
void serialize_shape (std::wostream & strm); void serialize_shape (std::wostream & strm);
void serialize_xfrm (std::wostream & strm, const std::wstring & namespace_ = L"a"); void serialize_xfrm (std::wostream & strm, const std::wstring & namespace_ = L"a", bool always_position = false);
void serialize_bodyPr (std::wostream & strm, const std::wstring & namespace_ = L"a"); void serialize_bodyPr (std::wostream & strm, const std::wstring & namespace_ = L"a");
}; };
......
...@@ -74,6 +74,8 @@ static std::wstring get_mime_type(const std::wstring & extension) ...@@ -74,6 +74,8 @@ static std::wstring get_mime_type(const std::wstring & extension)
else if (L"wav" == extension) return L"audio/wav"; else if (L"wav" == extension) return L"audio/wav";
else if (L"bin" == extension) return L"application/vnd.openxmlformats-officedocument.oleObject"; else if (L"bin" == extension) return L"application/vnd.openxmlformats-officedocument.oleObject";
else if (L"xlsx" == extension) return L"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; else if (L"xlsx" == extension) return L"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
else if (L"docx" == extension) return L"application/vnd.openxmlformats-officedocument.wordprocessingml.document";
else if (L"doc" == extension) return L"application/msword";
else return L"application/octet-stream"; else return L"application/octet-stream";
...@@ -135,8 +137,8 @@ bool content_types_file::add_or_find_override(const std::wstring & fileName) ...@@ -135,8 +137,8 @@ bool content_types_file::add_or_find_override(const std::wstring & fileName)
} }
std::wstring content_type; std::wstring content_type;
int pos = fileName.rfind(L".");
int pos = fileName.rfind(L".");
std::wstring extension = pos >= 0 ? fileName.substr(pos + 1) : L""; std::wstring extension = pos >= 0 ? fileName.substr(pos + 1) : L"";
if (extension == L"xlsx") if (extension == L"xlsx")
...@@ -362,7 +364,10 @@ void embeddings::write(const std::wstring & RootPath) ...@@ -362,7 +364,10 @@ void embeddings::write(const std::wstring & RootPath)
if ( items[i].mediaInternal && items[i].valid && if ( items[i].mediaInternal && items[i].valid &&
(items[i].type == typeMsObject || items[i].type == typeOleObject)) (items[i].type == typeMsObject || items[i].type == typeOleObject))
{ {
content_types.add_or_find_override(std::wstring(L"/word/") + items[i].outputName); int pos = items[i].outputName.rfind(L".");
std::wstring extension = pos >= 0 ? items[i].outputName.substr(pos + 1) : L"";
content_types.add_or_find_default(extension);
std::wstring file_name_out = RootPath + FILE_SEPARATOR_STR + items[i].outputName; std::wstring file_name_out = RootPath + FILE_SEPARATOR_STR + items[i].outputName;
......
...@@ -514,7 +514,7 @@ void pptx_conversion_context::end_page() ...@@ -514,7 +514,7 @@ void pptx_conversion_context::end_page()
} }
get_slide_context().serialize_background(current_slide().Background()); get_slide_context().serialize_background(current_slide().Background());
get_slide_context().serialize_objects(current_slide().Data()); get_slide_context().serialize_objects (current_slide().Data());
get_slide_context().serialize_animations(current_slide().Timing()); get_slide_context().serialize_animations(current_slide().Timing());
get_slide_context().dump_rels(current_slide().Rels());//hyperlinks, mediaitems, ... get_slide_context().dump_rels(current_slide().Rels());//hyperlinks, mediaitems, ...
...@@ -543,9 +543,9 @@ std::pair<int,int> pptx_conversion_context::add_author_comments(std::wstring aut ...@@ -543,9 +543,9 @@ std::pair<int,int> pptx_conversion_context::add_author_comments(std::wstring aut
void pptx_conversion_context::end_master() void pptx_conversion_context::end_master()
{ {
get_slide_context().serialize_background(current_master().Background(),true); get_slide_context().serialize_background (current_master().Background(),true);
get_slide_context().serialize_objects(current_master().Data()); get_slide_context().serialize_objects (current_master().Data());
get_slide_context().serialize_HeaderFooter(current_master().DataExtra()); get_slide_context().serialize_HeaderFooter (current_master().DataExtra());
get_slide_context().dump_rels(current_master().Rels());//hyperlinks, mediaitems, ... get_slide_context().dump_rels(current_master().Rels());//hyperlinks, mediaitems, ...
......
...@@ -90,7 +90,7 @@ void pptx_serialize_image(std::wostream & strm, _pptx_drawing & val) ...@@ -90,7 +90,7 @@ void pptx_serialize_image(std::wostream & strm, _pptx_drawing & val)
CP_XML_ATTR(L"id", val.id); CP_XML_ATTR(L"id", val.id);
CP_XML_ATTR(L"name", val.name); CP_XML_ATTR(L"name", val.name);
oox_serialize_hlink(CP_XML_STREAM(),val.hlinks); oox_serialize_hlink(CP_XML_STREAM(), val.hlinks);
} }
CP_XML_NODE(L"p:cNvPicPr") CP_XML_NODE(L"p:cNvPicPr")
...@@ -107,7 +107,7 @@ void pptx_serialize_image(std::wostream & strm, _pptx_drawing & val) ...@@ -107,7 +107,7 @@ void pptx_serialize_image(std::wostream & strm, _pptx_drawing & val)
CP_XML_NODE(L"p:spPr") CP_XML_NODE(L"p:spPr")
{ {
val.serialize_xfrm(CP_XML_STREAM()); val.serialize_xfrm(CP_XML_STREAM(), L"a", true);
CP_XML_NODE(L"a:prstGeom") CP_XML_NODE(L"a:prstGeom")
{ {
...@@ -170,7 +170,7 @@ void pptx_serialize_shape(std::wostream & strm, _pptx_drawing & val) ...@@ -170,7 +170,7 @@ void pptx_serialize_shape(std::wostream & strm, _pptx_drawing & val)
if (!bNoRect) if (!bNoRect)
{ {
val.serialize_xfrm(CP_XML_STREAM()); val.serialize_xfrm(CP_XML_STREAM(), L"a", true);
val.serialize_shape(CP_XML_STREAM()); val.serialize_shape(CP_XML_STREAM());
oox_serialize_ln(CP_XML_STREAM(), val.additional); oox_serialize_ln(CP_XML_STREAM(), val.additional);
...@@ -198,7 +198,7 @@ void pptx_serialize_chart(std::wostream & strm, _pptx_drawing & val) ...@@ -198,7 +198,7 @@ void pptx_serialize_chart(std::wostream & strm, _pptx_drawing & val)
CP_XML_NODE(L"p:cNvGraphicFramePr"); CP_XML_NODE(L"p:cNvGraphicFramePr");
CP_XML_NODE(L"p:nvPr"); CP_XML_NODE(L"p:nvPr");
} }
val.serialize_xfrm(CP_XML_STREAM(), L"p"); val.serialize_xfrm(CP_XML_STREAM(), L"p", true);
//oox_serialize_ln(CP_XML_STREAM(),val.additional); //oox_serialize_ln(CP_XML_STREAM(),val.additional);
...@@ -218,7 +218,6 @@ void pptx_serialize_chart(std::wostream & strm, _pptx_drawing & val) ...@@ -218,7 +218,6 @@ void pptx_serialize_chart(std::wostream & strm, _pptx_drawing & val)
} // p:graphicFrame } // p:graphicFrame
} // CP_XML_WRITER } // CP_XML_WRITER
} }
void pptx_serialize_table(std::wostream & strm, _pptx_drawing & val) void pptx_serialize_table(std::wostream & strm, _pptx_drawing & val)
{ {
CP_XML_WRITER(strm) CP_XML_WRITER(strm)
...@@ -236,7 +235,7 @@ void pptx_serialize_table(std::wostream & strm, _pptx_drawing & val) ...@@ -236,7 +235,7 @@ void pptx_serialize_table(std::wostream & strm, _pptx_drawing & val)
CP_XML_NODE(L"p:cNvGraphicFramePr"); CP_XML_NODE(L"p:cNvGraphicFramePr");
CP_XML_NODE(L"p:nvPr"); CP_XML_NODE(L"p:nvPr");
} }
val.serialize_xfrm(CP_XML_STREAM(), L"p"); val.serialize_xfrm(CP_XML_STREAM(), L"p", true);
//oox_serialize_ln(CP_XML_STREAM(),val.additional); //oox_serialize_ln(CP_XML_STREAM(),val.additional);
...@@ -260,11 +259,55 @@ void pptx_serialize_table(std::wostream & strm, _pptx_drawing & val) ...@@ -260,11 +259,55 @@ void pptx_serialize_table(std::wostream & strm, _pptx_drawing & val)
} }
void pptx_serialize_object(std::wostream & strm, _pptx_drawing & val)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"p:graphicFrame")
{
CP_XML_NODE(L"p:nvGraphicFramePr")
{
CP_XML_NODE(L"p:cNvPr")
{
CP_XML_ATTR(L"id", val.id);
CP_XML_ATTR(L"name", val.name);
}
CP_XML_NODE(L"p:cNvGraphicFramePr");
CP_XML_NODE(L"p:nvPr");
}
val.serialize_xfrm(CP_XML_STREAM(), L"p", true);
//oox_serialize_ln(CP_XML_STREAM(),val.additional);
CP_XML_NODE(L"a:graphic")
{
CP_XML_NODE(L"a:graphicData")
{
CP_XML_ATTR(L"uri", L"http://schemas.openxmlformats.org/presentationml/2006/ole");
CP_XML_NODE(L"p:oleObj")
{
CP_XML_ATTR(L"r:id", val.objectId);
CP_XML_ATTR(L"progId", val.objectProgId);
CP_XML_ATTR(L"imgW", val.cx );
CP_XML_ATTR(L"imgH", val.cy );
CP_XML_NODE(L"p:embed");
val.id = 0;
pptx_serialize_image(CP_XML_STREAM(), val);
}
}
}
} // p:graphicFrame
} // CP_XML_WRITER
}
void _pptx_drawing::serialize(std::wostream & strm) void _pptx_drawing::serialize(std::wostream & strm)
{ {
if (type == typeShape) if (type == typeShape)
{ {
serialize_shape(strm); pptx_serialize_shape(strm, *this);
} }
else if (type == typeImage) else if (type == typeImage)
{ {
...@@ -278,6 +321,11 @@ void _pptx_drawing::serialize(std::wostream & strm) ...@@ -278,6 +321,11 @@ void _pptx_drawing::serialize(std::wostream & strm)
{ {
pptx_serialize_table(strm, *this); pptx_serialize_table(strm, *this);
} }
else if (type == typeMsObject ||
type == typeOleObject)
{
pptx_serialize_object(strm, *this);
}
} }
......
This diff is collapsed.
...@@ -238,6 +238,7 @@ private: ...@@ -238,6 +238,7 @@ private:
element_ptr comments_; element_ptr comments_;
element_ptr media_; element_ptr media_;
element_ptr embeddings_;
}; };
// xlsx_document // xlsx_document
......
...@@ -78,8 +78,9 @@ public: ...@@ -78,8 +78,9 @@ public:
std::wstring add_hyperlink(std::wstring const & ref, bool object); std::wstring add_hyperlink(std::wstring const & ref, bool object);
void start_frame(); void start_frame();
void set_image (std::wstring const & path); void set_image (const std::wstring & path);
void set_chart (std::wstring const & path); void set_chart (const std::wstring & path);
void set_ms_object (const std::wstring & path, const std::wstring & progId);
void set_ole_object (const std::wstring & path, const std::wstring & progId); void set_ole_object (const std::wstring & path, const std::wstring & progId);
void set_text_box (); void set_text_box ();
void end_frame(); void end_frame();
...@@ -118,15 +119,8 @@ public: ...@@ -118,15 +119,8 @@ public:
void set_page_number(); void set_page_number();
void set_date_time(); void set_date_time();
private: private:
void process_common_properties(drawing_object_description& obj,_pptx_drawing & drawing);
void default_set(); void default_set();
void process_shape (drawing_object_description& obj);
void process_image (drawing_object_description& obj);
void process_chart (drawing_object_description& obj);
void process_table (drawing_object_description& obj);
void process_object (drawing_object_description& obj);
int hlinks_size_; int hlinks_size_;
class Impl; class Impl;
......
...@@ -340,7 +340,7 @@ void _xlsx_drawing::serialize(std::wostream & strm) ...@@ -340,7 +340,7 @@ void _xlsx_drawing::serialize(std::wostream & strm)
void _xlsx_drawing::serialize_object (std::wostream & strm) void _xlsx_drawing::serialize_object (std::wostream & strm)
{ {
if (type != typeOleObject) return; if (type != typeOleObject && type != typeMsObject) return;
CP_XML_WRITER(strm) CP_XML_WRITER(strm)
{ {
......
...@@ -288,8 +288,13 @@ void xlsx_drawing_context::set_ole_object(const std::wstring & path, const std:: ...@@ -288,8 +288,13 @@ void xlsx_drawing_context::set_ole_object(const std::wstring & path, const std::
impl_->object_description_.xlink_href_ = path; impl_->object_description_.xlink_href_ = path;
impl_->object_description_.descriptor_ = progId; impl_->object_description_.descriptor_ = progId;
} }
void xlsx_drawing_context::set_ms_object(const std::wstring & path, const std::wstring & progId)
void xlsx_drawing_context::set_image(std::wstring const & path) {
impl_->object_description_.type_ = typeMsObject;
impl_->object_description_.xlink_href_ = path;
impl_->object_description_.descriptor_ = progId;
}
void xlsx_drawing_context::set_image(const std::wstring & path)
{ {
if (impl_->object_description_.type_ == typeUnknown) if (impl_->object_description_.type_ == typeUnknown)
{ {
...@@ -312,7 +317,7 @@ void xlsx_drawing_context::end_frame() ...@@ -312,7 +317,7 @@ void xlsx_drawing_context::end_frame()
impl_->current_level_->push_back(impl_->object_description_); impl_->current_level_->push_back(impl_->object_description_);
} }
void xlsx_drawing_context::set_chart(std::wstring const & path) void xlsx_drawing_context::set_chart(const std::wstring & path)
{ {
impl_->object_description_.type_ = typeChart; impl_->object_description_.type_ = typeChart;
impl_->object_description_.xlink_href_ = path; impl_->object_description_.xlink_href_ = path;
......
...@@ -91,9 +91,10 @@ public: ...@@ -91,9 +91,10 @@ public:
void end_shape(); void end_shape();
void start_frame(); void start_frame();
void set_image (std::wstring const & path); void set_image (const std::wstring & path);
void set_chart (std::wstring const & path); void set_chart (const std::wstring & path);
void set_ole_object (const std::wstring & path, const std::wstring & progId); void set_ole_object (const std::wstring & path, const std::wstring & progId);
void set_ms_object (const std::wstring & path, const std::wstring & progId);
void set_text_box (); void set_text_box ();
void end_frame(); void end_frame();
......
...@@ -114,7 +114,7 @@ public: ...@@ -114,7 +114,7 @@ public:
{ {
for (int i = 0 ; i < xlsx_drawings_.size(); i++) for (int i = 0 ; i < xlsx_drawings_.size(); i++)
{ {
if (xlsx_drawings_[i].type != typeOleObject) continue; if (xlsx_drawings_[i].type != typeOleObject && xlsx_drawings_[i].type != typeMsObject) continue;
xlsx_drawings_[i].serialize_object(strm); xlsx_drawings_[i].serialize_object(strm);
} }
......
...@@ -175,7 +175,7 @@ void object_odf_context::xlsx_convert(oox::xlsx_conversion_context & Context) ...@@ -175,7 +175,7 @@ void object_odf_context::xlsx_convert(oox::xlsx_conversion_context & Context)
} }
else if (object_type_ == 2 && office_text_) else if (object_type_ == 2 && office_text_)
{ {
office_text_->xlsx_convert(Context); //embedded
} }
else if (object_type_ == 3 && office_math_) else if (object_type_ == 3 && office_math_)
{ {
...@@ -183,6 +183,10 @@ void object_odf_context::xlsx_convert(oox::xlsx_conversion_context & Context) ...@@ -183,6 +183,10 @@ void object_odf_context::xlsx_convert(oox::xlsx_conversion_context & Context)
Context.get_math_context().start(); Context.get_math_context().start();
office_math_->oox_convert(Context.get_math_context()); office_math_->oox_convert(Context.get_math_context());
} }
else if(object_type_ == 4 && office_spreadsheet_)
{
//embedded
}
} }
void object_odf_context::docx_convert(oox::docx_conversion_context & Context) void object_odf_context::docx_convert(oox::docx_conversion_context & Context)
{ {
...@@ -199,7 +203,7 @@ void object_odf_context::docx_convert(oox::docx_conversion_context & Context) ...@@ -199,7 +203,7 @@ void object_odf_context::docx_convert(oox::docx_conversion_context & Context)
} }
else if (object_type_ == 2 && office_text_) else if (object_type_ == 2 && office_text_)
{ {
office_text_->docx_convert(Context); //embedded
} }
else if (object_type_ == 3 && office_math_) else if (object_type_ == 3 && office_math_)
{ {
...@@ -227,7 +231,7 @@ void object_odf_context::docx_convert(oox::docx_conversion_context & Context) ...@@ -227,7 +231,7 @@ void object_odf_context::docx_convert(oox::docx_conversion_context & Context)
} }
else if(object_type_ == 4 && office_spreadsheet_) else if(object_type_ == 4 && office_spreadsheet_)
{ {
//office_spreadsheet_ //embedded
} }
} }
void object_odf_context::pptx_convert(oox::pptx_conversion_context & Context) void object_odf_context::pptx_convert(oox::pptx_conversion_context & Context)
...@@ -244,7 +248,7 @@ void object_odf_context::pptx_convert(oox::pptx_conversion_context & Context) ...@@ -244,7 +248,7 @@ void object_odf_context::pptx_convert(oox::pptx_conversion_context & Context)
} }
else if (object_type_ == 2 && office_text_) else if (object_type_ == 2 && office_text_)
{ {
office_text_->pptx_convert(Context); //embedded
} }
else if (object_type_ == 3 && office_math_) else if (object_type_ == 3 && office_math_)
{ {
...@@ -252,6 +256,10 @@ void object_odf_context::pptx_convert(oox::pptx_conversion_context & Context) ...@@ -252,6 +256,10 @@ void object_odf_context::pptx_convert(oox::pptx_conversion_context & Context)
Context.get_math_context().start(); Context.get_math_context().start();
office_math_->oox_convert(Context.get_math_context()); office_math_->oox_convert(Context.get_math_context());
} }
else if(object_type_ == 4 && office_spreadsheet_)
{
//embedded
}
} }
void object_odf_context::calc_cache_series(std::wstring adress, std::vector<std::wstring> & cash) void object_odf_context::calc_cache_series(std::wstring adress, std::vector<std::wstring> & cash)
{ {
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <boost/foreach.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/regex.hpp> #include <boost/regex.hpp>
...@@ -48,16 +47,20 @@ ...@@ -48,16 +47,20 @@
#include "style_graphic_properties.h" #include "style_graphic_properties.h"
#include "odfcontext.h" #include "odfcontext.h"
#include "../docx/xlsx_package.h"
#include "../docx/docx_package.h"
#include "../docx/pptx_package.h"
#include "datatypes/length.h" #include "datatypes/length.h"
#include "datatypes/borderstyle.h" #include "datatypes/borderstyle.h"
#include "../../../OfficeUtils/src/OfficeUtils.h"
#include "../../../Common/3dParty/pole/pole.h"
namespace cpdoccore { namespace cpdoccore {
namespace odf_reader { namespace odf_reader {
// draw-image-attlist
/// draw-image-attlist
void draw_image_attlist::add_attributes( const xml::attributes_wc_ptr & Attributes ) void draw_image_attlist::add_attributes( const xml::attributes_wc_ptr & Attributes )
{ {
CP_APPLY_ATTR(L"draw:filter-name", draw_filter_name_); CP_APPLY_ATTR(L"draw:filter-name", draw_filter_name_);
...@@ -283,5 +286,108 @@ void draw_object_ole::add_child_element( xml::sax * Reader, const std::wstring & ...@@ -283,5 +286,108 @@ void draw_object_ole::add_child_element( xml::sax * Reader, const std::wstring &
CP_NOT_APPLICABLE_ELM(); CP_NOT_APPLICABLE_ELM();
} }
std::wstring draw_object_ole::detectObject(const std::wstring &fileName)
{
POLE::Storage *storage = new POLE::Storage(fileName.c_str());
if (storage == NULL) return L"";
if (storage->open(false, false) == false)
{
delete storage;
return L"";
}
std::wstring prog;
POLE::Stream* pStream = new POLE::Stream(storage, "CompObj");
if ((pStream) && (pStream->size() > 28))
{
//skip the CompObjHeader
pStream->seek(28);
int sz_obj = pStream->size() - 28;
std::vector<std::string> str;
while (sz_obj > 0)
{
_UINT32 sz = 0;
pStream->read((unsigned char*)&sz, 4); sz_obj-= 4;
if (sz > sz_obj)
break;
unsigned char *data = new unsigned char[sz];
pStream->read(data, sz);
str.push_back(std::string((char*)data, sz));
delete []data;
sz_obj-= sz;
}
if (!str.empty())
{
prog = std::wstring (str.back().begin(), str.back().end());
}
delete pStream;
}
delete storage;
return prog;
}
std::wstring draw_object::office_convert(odf_document * odfDocument, int type)
{
std::wstring href_result;
std::wstring folderPath = odfDocument->get_folder();
std::wstring objectOutPath = FileSystem::Directory::CreateDirectoryWithUniqueName(folderPath);
if (type == 1)
{
oox::package::docx_document outputDocx;
oox::docx_conversion_context conversionDocxContext ( odfDocument);
conversionDocxContext.set_output_document (&outputDocx);
//conversionContext.set_font_directory (fontsPath);
if (odfDocument->docx_convert(conversionDocxContext))
{
outputDocx.write(objectOutPath);
href_result = common_xlink_attlist_.href_.get_value_or(L"Object");
int pos = href_result.find(L"./");
if (pos >= 0) href_result = href_result.substr(2);
href_result = L"docx" + href_result + L".docx";
}
}
if (type == 2)
{
oox::package::xlsx_document outputXlsx;
oox::xlsx_conversion_context conversionXlsxContext ( odfDocument);
conversionXlsxContext.set_output_document (&outputXlsx);
//conversionContext.set_font_directory (fontsPath);
if (odfDocument->xlsx_convert(conversionXlsxContext))
{
outputXlsx.write(objectOutPath);
href_result = common_xlink_attlist_.href_.get_value_or(L"Object");
int pos = href_result.find(L"./");
if (pos >= 0) href_result = href_result.substr(2);
href_result = L"xlsx" + href_result + L".xlsx";
}
}
if (!href_result.empty())
{
std::wstring temp_file = folderPath + FILE_SEPARATOR_STR + href_result;
COfficeUtils oCOfficeUtils(NULL);
oCOfficeUtils.CompressFileOrDirectory(objectOutPath.c_str(), temp_file.c_str(), -1);
}
FileSystem::Directory::DeleteDirectory(objectOutPath);
return href_result;
}
} }
} }
...@@ -292,16 +292,18 @@ public: ...@@ -292,16 +292,18 @@ public:
static const ElementType type = typeDrawObject; static const ElementType type = typeDrawObject;
CPDOCCORE_DEFINE_VISITABLE(); CPDOCCORE_DEFINE_VISITABLE();
virtual void docx_convert(oox::docx_conversion_context & Context); virtual void docx_convert (oox::docx_conversion_context & Context);
virtual void xlsx_convert(oox::xlsx_conversion_context & Context); virtual void xlsx_convert (oox::xlsx_conversion_context & Context);
virtual void pptx_convert(oox::pptx_conversion_context & Context); virtual void pptx_convert (oox::pptx_conversion_context & Context);
draw_object_attlist draw_object_attlist_; draw_object_attlist draw_object_attlist_;
odf_types::common_xlink_attlist common_xlink_attlist_; odf_types::common_xlink_attlist common_xlink_attlist_;
private: private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes ); 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_child_element ( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
std::wstring office_convert(odf_document * odfDocument, int type);
}; };
CP_REGISTER_OFFICE_ELEMENT2(draw_object); CP_REGISTER_OFFICE_ELEMENT2(draw_object);
......
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
#include "draw_common.h" #include "draw_common.h"
#include "../docx/docx_drawing.h" #include "../docx/docx_drawing.h"
#include "../docx/xlsx_package.h"
#include "chart_build_oox.h" #include "chart_build_oox.h"
#include "calcs_styles.h" #include "calcs_styles.h"
...@@ -57,9 +56,6 @@ ...@@ -57,9 +56,6 @@
#include "datatypes/length.h" #include "datatypes/length.h"
#include "datatypes/borderstyle.h" #include "datatypes/borderstyle.h"
#include "../../../OfficeUtils/src/OfficeUtils.h"
#include "../../../Common/3dParty/pole/pole.h"
namespace cpdoccore { namespace cpdoccore {
using namespace odf_types; using namespace odf_types;
...@@ -1437,7 +1433,7 @@ void draw_object::docx_convert(oox::docx_conversion_context & Context) ...@@ -1437,7 +1433,7 @@ void draw_object::docx_convert(oox::docx_conversion_context & Context)
boost::algorithm::replace_all(objectPath, FILE_SEPARATOR_STR + std::wstring(L"./"), FILE_SEPARATOR_STR); boost::algorithm::replace_all(objectPath, FILE_SEPARATOR_STR + std::wstring(L"./"), FILE_SEPARATOR_STR);
cpdoccore::odf_reader::odf_document objectSubDoc(objectPath ,NULL); cpdoccore::odf_reader::odf_document objectSubDoc(objectPath ,NULL);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //---------------------------------------------------------------------------------------------------------------------
draw_frame* frame = NULL; draw_frame* frame = NULL;
oox::_docx_drawing * drawing = NULL; oox::_docx_drawing * drawing = NULL;
office_element* contentSubDoc = objectSubDoc.get_impl()->get_content(); office_element* contentSubDoc = objectSubDoc.get_impl()->get_content();
...@@ -1454,7 +1450,6 @@ void draw_object::docx_convert(oox::docx_conversion_context & Context) ...@@ -1454,7 +1450,6 @@ void draw_object::docx_convert(oox::docx_conversion_context & Context)
if (frame) if (frame)
drawing = dynamic_cast<oox::_docx_drawing *>(frame->oox_drawing_.get()); drawing = dynamic_cast<oox::_docx_drawing *>(frame->oox_drawing_.get());
} }
//------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------
if (!frame || !drawing) if (!frame || !drawing)
{ {
...@@ -1511,47 +1506,26 @@ void draw_object::docx_convert(oox::docx_conversion_context & Context) ...@@ -1511,47 +1506,26 @@ void draw_object::docx_convert(oox::docx_conversion_context & Context)
} }
Context.get_drawing_context().clear_stream_frame(); Context.get_drawing_context().clear_stream_frame();
} }
if (objectBuild.object_type_ == 4) //embedded sheet else if (objectBuild.object_type_ == 4) //embedded sheet
{ {
bool & use_image_replace = Context.get_drawing_context().get_use_image_replace(); bool & use_image_replace = Context.get_drawing_context().get_use_image_replace();
use_image_replace = true; use_image_replace = true;
oox::package::xlsx_document outputXlsx; std::wstring href_new = office_convert(&objectSubDoc, 2);
oox::xlsx_conversion_context conversionXlsxContext ( &objectSubDoc);
conversionXlsxContext.set_output_document (&outputXlsx);
//conversionContext.set_font_directory (fontsPath);
if (objectSubDoc.xlsx_convert(conversionXlsxContext)) if (!href_new.empty())
{ {
drawing->type = oox::typeMsObject; drawing->type = oox::typeMsObject;
std::wstring objectXlsxPath = FileSystem::Directory::CreateDirectoryWithUniqueName(folderPath);
outputXlsx.write(objectXlsxPath);
href = Context.get_drawing_context().get_current_object_name() + L".xlsx";
std::wstring temp_file = folderPath + FILE_SEPARATOR_STR + href;
COfficeUtils oCOfficeUtils(NULL);
oCOfficeUtils.CompressFileOrDirectory(objectXlsxPath.c_str(), temp_file.c_str(), -1);
FileSystem::Directory::DeleteDirectory(objectXlsxPath);
bool isMediaInternal = true; bool isMediaInternal = true;
drawing->objectId = Context.add_mediaitem(href, drawing->type, isMediaInternal, temp_file);
href += FILE_SEPARATOR_STR + href_new;
drawing->objectId = Context.add_mediaitem(href, drawing->type, isMediaInternal, href);
drawing->objectProgId = L"Excel.Sheet.12"; drawing->objectProgId = L"Excel.Sheet.12";
} }
else
{
objectBuild.object_type_ = 0;
}
} }
else
if (objectBuild.object_type_ == 0)
{ {
//замещающая картинка(если она конечно присутствует) //замещающая картинка(если она конечно присутствует)
bool & use_image_replace = Context.get_drawing_context().get_use_image_replace(); bool & use_image_replace = Context.get_drawing_context().get_use_image_replace();
use_image_replace = true; use_image_replace = true;
} }
...@@ -1588,51 +1562,5 @@ void draw_object_ole::docx_convert(oox::docx_conversion_context & Context) ...@@ -1588,51 +1562,5 @@ void draw_object_ole::docx_convert(oox::docx_conversion_context & Context)
drawing->objectProgId = detectObject(objectPath); drawing->objectProgId = detectObject(objectPath);
} }
std::wstring draw_object_ole::detectObject(const std::wstring &fileName)
{
POLE::Storage *storage = new POLE::Storage(fileName.c_str());
if (storage == NULL) return L"";
if (storage->open(false, false) == false)
{
delete storage;
return L"";
}
std::wstring prog;
POLE::Stream* pStream = new POLE::Stream(storage, "CompObj");
if ((pStream) && (pStream->size() > 28))
{
//skip the CompObjHeader
pStream->seek(28);
int sz_obj = pStream->size() - 28;
std::vector<std::string> str;
while (sz_obj > 0)
{
_UINT32 sz = 0;
pStream->read((unsigned char*)&sz, 4); sz_obj-= 4;
if (sz > sz_obj)
break;
unsigned char *data = new unsigned char[sz];
pStream->read(data, sz);
str.push_back(std::string((char*)data, sz));
delete []data;
sz_obj-= sz;
}
if (!str.empty())
{
prog = std::wstring (str.back().begin(), str.back().end());
}
delete pStream;
}
delete storage;
return prog;
}
} }
} }
...@@ -61,6 +61,8 @@ ...@@ -61,6 +61,8 @@
#include "datatypes/length.h" #include "datatypes/length.h"
#include "datatypes/borderstyle.h" #include "datatypes/borderstyle.h"
#include "../../../OfficeUtils/src/OfficeUtils.h"
namespace cpdoccore { namespace cpdoccore {
using namespace odf_types; using namespace odf_types;
...@@ -262,22 +264,16 @@ void draw_text_box::pptx_convert(oox::pptx_conversion_context & Context) ...@@ -262,22 +264,16 @@ void draw_text_box::pptx_convert(oox::pptx_conversion_context & Context)
void draw_object::pptx_convert(oox::pptx_conversion_context & Context) void draw_object::pptx_convert(oox::pptx_conversion_context & Context)
{ {
try { try {
const std::wstring href = common_xlink_attlist_.href_.get_value_or(L""); std::wstring href = common_xlink_attlist_.href_.get_value_or(L"");
odf_reader::odf_document * odf_reader = Context.root();
std::wstring folderPath = odf_reader->get_folder();
std::wstring folderPath = Context.root()->get_folder();
std::wstring objectPath = folderPath + FILE_SEPARATOR_STR + href; std::wstring objectPath = folderPath + FILE_SEPARATOR_STR + href;
//normalize path ??? todooo //normalize path ??? todooo
boost::algorithm::replace_all(objectPath, FILE_SEPARATOR_STR + std::wstring(L"./"), FILE_SEPARATOR_STR); boost::algorithm::replace_all(objectPath, FILE_SEPARATOR_STR + std::wstring(L"./"), FILE_SEPARATOR_STR);
cpdoccore::odf_reader::odf_document objectSubDoc(objectPath, NULL); cpdoccore::odf_reader::odf_document objectSubDoc(objectPath, NULL);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //---------------------------------------------------------------------------------------------------------------------
//в отдельных embd объектах чаще всего диаграммы, уравнения... но МОГУТ быть и обычные объекты подтипа frame!!!
//пример RemanejamentoOrcamentario.ods
///////////////////////////////////////////////////////////////////////////
//функциональная часть
office_element *contentSubDoc = objectSubDoc.get_impl()->get_content(); office_element *contentSubDoc = objectSubDoc.get_impl()->get_content();
if (!contentSubDoc) if (!contentSubDoc)
{ {
...@@ -290,9 +286,7 @@ void draw_object::pptx_convert(oox::pptx_conversion_context & Context) ...@@ -290,9 +286,7 @@ void draw_object::pptx_convert(oox::pptx_conversion_context & Context)
process_build_object process_build_object_(objectBuild, objectSubDoc.odf_context()); process_build_object process_build_object_(objectBuild, objectSubDoc.odf_context());
contentSubDoc->accept(process_build_object_); contentSubDoc->accept(process_build_object_);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //---------------------------------------------------------------------------------------------------------------------
//отображательная часть
if (objectBuild.object_type_ == 1)//диаграмма if (objectBuild.object_type_ == 1)//диаграмма
{ {
const std::wstring href_draw = common_xlink_attlist_.href_.get_value_or(L""); const std::wstring href_draw = common_xlink_attlist_.href_.get_value_or(L"");
...@@ -300,25 +294,20 @@ void draw_object::pptx_convert(oox::pptx_conversion_context & Context) ...@@ -300,25 +294,20 @@ void draw_object::pptx_convert(oox::pptx_conversion_context & Context)
Context.get_slide_context().set_chart(href_draw); // в рисовательной части только место объекта, рамочки ... и релсы Context.get_slide_context().set_chart(href_draw); // в рисовательной части только место объекта, рамочки ... и релсы
} }
else if (objectBuild.object_type_ == 2)//odt текст else if (objectBuild.object_type_ == 2)//odt text
{ {
Context.get_slide_context().set_text_box(); Context.get_slide_context().set_use_image_replacement();
Context.get_text_context().start_object();
//сменить контекст с главного на другой ... проблема со стилями!!
Context.get_text_context().set_local_styles_container(&objectSubDoc.odf_context().styleContainer());
objectBuild.pptx_convert(Context);
std::wstring text_content_ = Context.get_text_context().end_object(); std::wstring href_new = office_convert( &objectSubDoc, 1);
Context.get_text_context().set_local_styles_container(NULL);//вытираем вручную ...
if (!text_content_.empty()) if (!href_new.empty())
{ {
Context.get_slide_context().set_property(_property(L"text-content",text_content_)); bool isMediaInternal = true;
href += FILE_SEPARATOR_STR + href_new;
Context.get_slide_context().set_ms_object(href, L"Word.Document");
} }
} }
else if (objectBuild.object_type_ == 3) //мат формулы else if (objectBuild.object_type_ == 3) //math
{ {
Context.get_slide_context().set_text_box(); Context.get_slide_context().set_text_box();
...@@ -339,6 +328,19 @@ void draw_object::pptx_convert(oox::pptx_conversion_context & Context) ...@@ -339,6 +328,19 @@ void draw_object::pptx_convert(oox::pptx_conversion_context & Context)
Context.get_slide_context().set_property(_property(L"text-content", text_content)); Context.get_slide_context().set_property(_property(L"text-content", text_content));
} }
} }
else if (objectBuild.object_type_ == 4) //ods sheet
{
Context.get_slide_context().set_use_image_replacement();
std::wstring href_new = office_convert( &objectSubDoc, 2);
if (!href_new.empty())
{
bool isMediaInternal = true;
href += FILE_SEPARATOR_STR + href_new;
Context.get_slide_context().set_ms_object(href, L"Excel.Sheet");
}
}
else else
{ {
//замещающая картинка(если она конечно присутствует) //замещающая картинка(если она конечно присутствует)
......
...@@ -257,21 +257,16 @@ void draw_text_box::xlsx_convert(oox::xlsx_conversion_context & Context) ...@@ -257,21 +257,16 @@ void draw_text_box::xlsx_convert(oox::xlsx_conversion_context & Context)
void draw_object::xlsx_convert(oox::xlsx_conversion_context & Context) void draw_object::xlsx_convert(oox::xlsx_conversion_context & Context)
{ {
try { try {
const std::wstring href = common_xlink_attlist_.href_.get_value_or(L""); std::wstring href = common_xlink_attlist_.href_.get_value_or(L"");
odf_reader::odf_document * odf_reader = Context.root();
std::wstring folderPath = odf_reader->get_folder(); std::wstring folderPath = Context.root()->get_folder();
std::wstring objectPath = folderPath + FILE_SEPARATOR_STR + href; std::wstring objectPath = folderPath + FILE_SEPARATOR_STR + href;
// normalize path ???? todooo // normalize path ???? todooo
boost::algorithm::replace_all(objectPath, FILE_SEPARATOR_STR + std::wstring(L"./"), FILE_SEPARATOR_STR); boost::algorithm::replace_all(objectPath, FILE_SEPARATOR_STR + std::wstring(L"./"), FILE_SEPARATOR_STR);
cpdoccore::odf_reader::odf_document objectSubDoc(objectPath,NULL); cpdoccore::odf_reader::odf_document objectSubDoc(objectPath,NULL);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //---------------------------------------------------------------------------------------------------------------------
//в отдельных embd объектах чаще всего диаграммы... но МОГУТ быть и обычные объекты подтипа frame!!! пример RemanejamentoOrcamentario.ods
///////////////////////////////////////////////////////////////////////////
//функциональная часть
office_element *contentSubDoc = objectSubDoc.get_impl()->get_content(); office_element *contentSubDoc = objectSubDoc.get_impl()->get_content();
object_odf_context objectBuild(href); object_odf_context objectBuild(href);
...@@ -280,9 +275,7 @@ void draw_object::xlsx_convert(oox::xlsx_conversion_context & Context) ...@@ -280,9 +275,7 @@ void draw_object::xlsx_convert(oox::xlsx_conversion_context & Context)
process_build_object process_build_object_(objectBuild, objectSubDoc.odf_context()); process_build_object process_build_object_(objectBuild, objectSubDoc.odf_context());
contentSubDoc->accept(process_build_object_); contentSubDoc->accept(process_build_object_);
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //---------------------------------------------------------------------------------------------------------------------
//отображательная часть
if (objectBuild.object_type_ == 1) //диаграмма if (objectBuild.object_type_ == 1) //диаграмма
{ {
const std::wstring href_draw = common_xlink_attlist_.href_.get_value_or(L""); const std::wstring href_draw = common_xlink_attlist_.href_.get_value_or(L"");
...@@ -292,20 +285,15 @@ void draw_object::xlsx_convert(oox::xlsx_conversion_context & Context) ...@@ -292,20 +285,15 @@ void draw_object::xlsx_convert(oox::xlsx_conversion_context & Context)
} }
else if (objectBuild.object_type_ == 2) //текст (odt text) else if (objectBuild.object_type_ == 2) //текст (odt text)
{ {
Context.get_drawing_context().set_text_box(); Context.get_drawing_context().set_use_image_replacement();
Context.get_text_context().start_drawing_content();
//сменить контекст с главного на другой ... проблема со стилями!!
Context.get_text_context().set_local_styles_container(&objectSubDoc.odf_context().styleContainer());
objectBuild.xlsx_convert(Context);
std::wstring text_content = Context.get_text_context().end_drawing_content(); std::wstring href_new = office_convert( &objectSubDoc, 1);
Context.get_text_context().set_local_styles_container(NULL);//вытираем вручную ...
if (!text_content.empty()) if (!href_new.empty())
{ {
Context.get_drawing_context().set_property(_property(L"text-content", text_content)); bool isMediaInternal = true;
href += FILE_SEPARATOR_STR + href_new;
Context.get_drawing_context().set_ms_object(href, L"Word.Document");
} }
} }
else if (objectBuild.object_type_ == 3) //мат формулы else if (objectBuild.object_type_ == 3) //мат формулы
......
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