Commit bc2235c0 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

(1.0.1.185): ASCOfficeOdfFile

Интерпритация Ole объектов из Open Office в Microsoft Office как изображений.
(odt, ods, odp)

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@54200 954022d7-b5bf-4e40-9824-e11837661b57
parent f583e8a6
......@@ -2,6 +2,6 @@
//1
//0
//1
//184
#define INTVER 1,0,1,184
#define STRVER "1,0,1,184\0"
//185
#define INTVER 1,0,1,185
#define STRVER "1,0,1,185\0"
......@@ -107,6 +107,7 @@ public:
odf::draw_frame *ptr;
std::wstring text_content;
size_t id;
bool use_image_replace;
};
drawing_context() : objects_count_(0), current_shape_(NULL),shape_text_content_(L""),zero_string_(L""),current_level_(0),current_shape_id_ (0){}
......@@ -117,10 +118,10 @@ public:
current_level_++;
objects_count_++;
_frame_ fr = {drawFrame,L"",objects_count_};
_frame_ fr = {drawFrame,L"",objects_count_,false};
frames_.push_back(fr);
}
}
void start_shape(odf::draw_shape * drawShape)
{
current_level_++;
......@@ -148,6 +149,15 @@ public:
else
return zero_string_;
}
bool & get_use_image_replace()
{
bool res = false;
if (frames_.size()>0)
return frames_.back().use_image_replace;
else
return res;
}
std::wstring & get_text_stream_shape()
{
return shape_text_content_;
......@@ -189,7 +199,6 @@ public:
}
odf::draw_shape * get_current_shape() const { return current_shape_; }
private:
std::wstring shape_text_content_;
......
......@@ -16,14 +16,12 @@ docx_content_types_file::docx_content_types_file()
{
content_type_.add_default(L"rels", L"application/vnd.openxmlformats-package.relationships+xml");
content_type_.add_default(L"xml", L"application/xml");
//content_type_.add_default(L"xlsx", L"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//
content_type_.add_default(L"jpg", L"image/jpeg");
content_type_.add_default(L"gif", L"image/gif");
content_type_.add_default(L"jpeg", L"image/jpeg");
content_type_.add_default(L"png", L"image/png");
content_type_.add_default(L"wmf", L"image/x-wmf");
//content_type_.add_default(L"svm", L"application/octet-stream");
content_type_.add_override(L"/_rels/.rels", L"application/vnd.openxmlformats-package.relationships+xml");
content_type_.add_override(L"/word/_rels/document.xml.rels", L"application/vnd.openxmlformats-package.relationships+xml");
......
......@@ -34,6 +34,8 @@ struct drawing_object_description
_oox_fill fill_;
bool use_image_replace_;
int type_; //default - frame
};
......
......@@ -91,7 +91,7 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, Type type, bool
else if ( type == typeImage)
{
fs::wpath file_name = fs::wpath(inputPath);
if (file_name.extension() == L".svm")
if (file_name.extension() == L".svm" || file_name.extension().empty())
{
outputPath = outputPath + L".png";
}
......
......@@ -14,26 +14,6 @@ namespace media {
using boost::filesystem::wpath;
bool check_file_type(const std::wstring & Name)
{
#ifdef BOOST_FILESYSTEM_LEGACY
std::wstring ext = wpath(Name).extension();
#else
std::wstring ext = wpath(Name).extension().string<std::wstring>();
#endif
boost::algorithm::to_lower(ext);
if (ext == L".jpg" ||
ext == L".jpeg" ||
ext == L".gif" ||
ext == L".png" ||
ext == L".svm" ||
ext == L".wmf"
)
return true;
else
return false;
}
bool is_internal(const std::wstring & uri, const std::wstring & packetRoot)
{
......
......@@ -10,7 +10,6 @@ namespace oox {
namespace utils {
namespace media {
bool check_file_type(const std::wstring & Name);
bool is_internal(const std::wstring & uri, const std::wstring & packetRoot);
std::wstring create_file_name(const std::wstring & uri, mediaitems::Type type, size_t Num);
std::wstring get_rel_type(mediaitems::Type type);
......
......@@ -11,6 +11,9 @@
#include "..\..\..\ASCImageStudio3\ASCGraphics\OfficeSvmFile\SvmConverter.h"
#import "../../../Redist/ASCImageFile3.dll" named_guids rename_namespace("ImageFile") raw_interfaces_only
namespace cpdoccore {
namespace oox {
namespace package {
......@@ -173,14 +176,38 @@ void media::write(const std::wstring & RootPath)
if (item.mediaInternal && item.valid && item.type == mediaitems::typeImage )
{
fs::wpath file_name = fs::wpath(item.href);
fs::wpath file_name_out = fs::wpath(RootPath) / item.outputName;
if (file_name.extension() == L".svm")
{
ConvertSvmToImage(file_name, fs::wpath(RootPath) / item.outputName);
ConvertSvmToImage(file_name, file_name_out);
}
else if(file_name.extension().empty())
{
// .. svm, emf, wmf
//???
ImageFile::IImageFile3Ptr piImageFile = NULL;
piImageFile.CreateInstance( __uuidof(ImageFile::ImageFile3) );
if( NULL != piImageFile )
{
VARIANT_BOOL vbSuccess = VARIANT_TRUE;
IUnknown* pImage = NULL;
BSTR bstrFilename = SysAllocString(item.href.data());
piImageFile->LoadImage2(bstrFilename, &pImage, &vbSuccess);
SysFreeString( bstrFilename );
if (vbSuccess && pImage)
{
bstrFilename = SysAllocString(file_name_out.string().data());
piImageFile->SaveImage2( &pImage, 4, bstrFilename, &vbSuccess );//to png
SysFreeString( bstrFilename );
pImage->Release();
}
}
}
else
boost::filesystem::copy_file(item.href, fs::wpath(RootPath) / item.outputName);
boost::filesystem::copy_file(item.href, file_name_out);
}
// ???
}
}
......
......@@ -89,8 +89,6 @@ public:
{
BOOST_FOREACH(rel_ const & r, pptx_drawing_rels_)
{
const bool valid = utils::media::check_file_type(r.ref_);
if (r.type_ == mediaitems::typeChart)// -
{
Rels.add(relationship(
......@@ -106,7 +104,7 @@ public:
Rels.add(relationship(
r.rid_,
utils::media::get_rel_type(r.type_),
/*valid ? (*/r.is_internal_ ? std::wstring(L"../") + r.ref_ : r.ref_/*) : L"NULL"*/,
r.is_internal_ ? std::wstring(L"../") + r.ref_ : r.ref_,
(r.is_internal_ ? L"" : L"External")
)
);
......
......@@ -183,6 +183,8 @@ void pptx_slide_context::default_set()
impl_->object_description_.additional_.clear();
impl_->object_description_.fill_.clear();
impl_->object_description_.use_image_replace_ = false;
}
void pptx_slide_context::set_placeHolder_type(std::wstring typeHolder)
......@@ -318,12 +320,19 @@ void pptx_slide_context::start_table()
impl_->object_description_.type_ = 0; //frame
}
void pptx_slide_context::start_object_ole()
{
impl_->object_description_.use_image_replace_ = true;
}
void pptx_slide_context::start_chart(std::wstring const & path)
{
impl_->object_description_.xlink_href_ = path;
impl_->object_description_.type_ = 0; //frame
}
void pptx_slide_context::end_object_ole()
{
}
void pptx_slide_context::end_shape()
{
impl_->shapes_.push_back(impl_->object_description_);
......@@ -370,7 +379,7 @@ void pptx_slide_context::process_images()
pos_replaicement = pic.xlink_href_.find(L"ObjectReplacements");
pos_preview = pic.xlink_href_.find(L"TablePreview");
if (pos_replaicement <0 && pos_preview <0)//,
if ((pos_replaicement <0 && pos_preview <0) || pic.use_image_replace_)//, ( )
{
_pptx_drawing drawing=_pptx_drawing();
......
......@@ -58,6 +58,9 @@ public:
void start_shape(int type);
void end_shape();
void start_object_ole();
void end_object_ole();
bool empty() const;
//////////////////////////////////////////////////////////////////////////////////////////////
void serialize_objects(std::wostream & strm);
......
......@@ -155,6 +155,8 @@ void xlsx_drawing_context::default_set()
impl_->object_description_.hlinks_.clear();
impl_->object_description_.additional_.clear();
impl_->object_description_.use_image_replace_ = false;
}
xlsx_drawing_context::~xlsx_drawing_context()
{
......@@ -252,6 +254,15 @@ void xlsx_drawing_context::start_shape(int type)
{
impl_->object_description_.type_ = type; //2,3...
}
void xlsx_drawing_context::start_object_ole()
{
impl_->object_description_.use_image_replace_ = true;
}
void xlsx_drawing_context::end_object_ole()
{
}
void xlsx_drawing_context::end_shape()
{
impl_->shapes_.push_back(impl_->object_description_);
......@@ -282,6 +293,7 @@ bool xlsx_drawing_context::empty() const
{
return impl_->empty();
}
void xlsx_drawing_context::process_images(xlsx_table_metrics & table_metrics)
{
using boost::filesystem::wpath;
......@@ -290,7 +302,7 @@ void xlsx_drawing_context::process_images(xlsx_table_metrics & table_metrics)
BOOST_FOREACH(drawing_object_description & pic, impl_->images_)
{
pos_replaicement= pic.xlink_href_.find(L"ObjectReplacements");
if (pos_replaicement <0)//,
if (pos_replaicement <0 || pic.use_image_replace_)//,
{
_xlsx_drawing drawing=_xlsx_drawing();
drawing.fill = pic.fill_;
......
......@@ -80,6 +80,9 @@ public:
void start_shape(int type);
//... ...
void end_shape();
void start_object_ole();
void end_object_ole();
bool empty() const;
......
......@@ -97,8 +97,6 @@ public:
{
BOOST_FOREACH(rel_ const & r, xlsx_drawing_rels_)
{
const bool valid = utils::media::check_file_type(r.ref_);
if (r.type_ == mediaitems::typeChart)// -
{
Rels.add(relationship(
......@@ -114,7 +112,7 @@ public:
Rels.add(relationship(
r.rid_,
utils::media::get_rel_type(r.type_),
/*valid ? (*/r.is_internal_ ? std::wstring(L"../") + r.ref_ : r.ref_/*) : L"NULL"*/,
r.is_internal_ ? std::wstring(L"../") + r.ref_ : r.ref_,
(r.is_internal_ ? L"" : L"External")
)
);
......
......@@ -24,7 +24,6 @@ xlsx_content_types_file::xlsx_content_types_file()
content_type_.add_default(L"jpeg", L"image/jpeg");
content_type_.add_default(L"png", L"image/png");
content_type_.add_default(L"wmf", L"image/x-wmf");
//content_type_.add_default(L"svm", L"application/octet-stream");
content_type_.add_default(L"vml", L"application/vnd.openxmlformats-officedocument.vmlDrawing");
......
......@@ -221,7 +221,6 @@ void draw_text_box::add_text(const std::wstring & Text)
{
}
// draw:object
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * draw_object::ns = L"draw";
......@@ -238,5 +237,22 @@ void draw_object::add_child_element( xml::sax * Reader, const ::std::wstring & N
CP_NOT_APPLICABLE_ELM(); // TODO
}
// draw:object
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * draw_object_ole::ns = L"draw";
const wchar_t * draw_object_ole::name = L"object-ole";
void draw_object_ole::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
CP_APPLY_ATTR(L"draw:class-id", draw_class_id_);
common_xlink_attlist_.add_attributes(Attributes);
}
void draw_object_ole::add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name)
{
CP_NOT_APPLICABLE_ELM();
}
}
}
......@@ -244,18 +244,13 @@ class draw_object_attlist
public:
void add_attributes( const xml::attributes_wc_ptr & Attributes )
{
// TODO
}
public:
};
/// \class draw_object
/// draw:object
/// draw-object
// draw:object
class draw_object : public office_element_impl<draw_object>
{
public:
......@@ -280,6 +275,30 @@ public:
CP_REGISTER_OFFICE_ELEMENT2(draw_object);
// draw:object-ole
class draw_object_ole : public office_element_impl<draw_object>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeDrawObjectOle;
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);
public:
common_xlink_attlist common_xlink_attlist_;
_CP_OPT(std::wstring) draw_class_id_;
};
CP_REGISTER_OFFICE_ELEMENT2(draw_object_ole);
}
}
......@@ -935,13 +935,14 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
std::wstring href = common_xlink_attlist_.href_.get_value_or(L"");
int pos_replaicement= href.find(L"ObjectReplacements");
if (pos_replaicement >=0)
return;//
const draw_frame * frame = Context.get_drawing_context().get_current_frame();//owner
if (!frame)
return;
if (pos_replaicement >=0 && !Context.get_drawing_context().get_use_image_replace())
return;//
// , , ...
oox::docx_conversion_context::StreamsManPtr prev = Context.get_stream_man();
......@@ -1217,6 +1218,14 @@ void draw_object::docx_convert(oox::docx_conversion_context & Context)
}
}
void draw_object_ole::docx_convert(oox::docx_conversion_context & Context)
{
// - ( )
bool & use_image_replace = Context.get_drawing_context().get_use_image_replace();
use_image_replace = true;
}
}
}
......@@ -300,6 +300,16 @@ void draw_object::pptx_convert(oox::pptx_conversion_context & Context)
}
}
void draw_object_ole::pptx_convert(oox::pptx_conversion_context & Context)
{
// embeddings
// guid???
// - ( )
Context.get_slide_context().start_object_ole();
}
}
}
......@@ -278,7 +278,11 @@ void draw_object::xlsx_convert(oox::xlsx_conversion_context & Context)
_CP_LOG(error) << "convert draw::object error" << std::endl;
}
}
void draw_object_ole::xlsx_convert(oox::xlsx_conversion_context & Context)
{
// - ( )
Context.get_drawing_context().start_object_ole();
}
}
}
......@@ -173,6 +173,7 @@ enum ElementType
typeDrawImage,
typeDrawTextBox,
typeDrawObject,
typeDrawObjectOle,
typeDrawChart,
typeDrawShape,
......
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