Commit ed5e68c9 authored by ElenaSubbotina's avatar ElenaSubbotina Committed by Alexander Trofimov

OdtFormatReader - исправлена конвертация группировок объектов

parent 8ae0378e
......@@ -96,7 +96,17 @@ private:
class drawing_context : boost::noncopyable
{
public:
struct _frame_
struct _group
{
_group() : cx(0), cy(0), x(0x7fffffff), y(0x7fffffff) {}
_INT32 x;
_INT32 y;
_INT32 cx;
_INT32 cy;
};
struct _frame
{
odf_reader::draw_frame *ptr;
std::wstring text_content;
......@@ -112,7 +122,7 @@ public:
current_level_++;
objects_count_++;
_frame_ fr = {drawFrame, L"", objects_count_, false};
_frame fr = {drawFrame, L"", objects_count_, false};
frames_.push_back(fr);
}
......@@ -131,13 +141,44 @@ public:
objects_count_++;
current_shape_id_ = objects_count_;
groups_.push_back(current_level_);
current_object_name_ = L"";
groups_.push_back(_group());
}
void add_name_object(const std::wstring & name)
{
current_object_name_ = name;
}
void set_position_child_group(_INT32 x, _INT32 y)
{
if (groups_.size() < 1) return;
if (groups_.back().x > x) groups_.back().x = x;
if (groups_.back().y > y) groups_.back().y = y;
}
void set_size_child_group(_INT32 cx, _INT32 cy)
{
if (groups_.size() < 1) return;
if (groups_.back().cx < cx) groups_.back().cx = cx;
if (groups_.back().cy < cy) groups_.back().cy = cy;
}
void get_position_group(_INT32 & x, _INT32 & y)
{
x = y = 0;
if (groups_.size() < 1) return;
x = groups_.back().x;
y = groups_.back().y;
}
void get_size_group(_INT32 & cx, _INT32 & cy)
{
cx = cy = 0;
if (groups_.size() < 1) return;
cx = groups_.back().cx;
cy = groups_.back().cy;
}
void stop_frame()
{
current_level_--;
......@@ -210,8 +251,8 @@ private:
int current_level_;
std::vector<int> groups_;
std::vector<_frame_> frames_;
std::vector<_group> groups_;
std::vector<_frame> frames_;
odf_reader::draw_shape * current_shape_;
size_t current_shape_id_;
......
......@@ -156,8 +156,10 @@ void serialize_wrap(std::wostream & strm, _docx_drawing const & val)
}
}
void docx_serialize_text(std::wostream & strm, const std::vector<odf_reader::_property> & properties)
void docx_serialize_text(std::wostream & strm, _docx_drawing & val)
{
const std::vector<odf_reader::_property> & properties = val.additional;
_CP_OPT(std::wstring) strTextContent;
odf_reader::GetProperty(properties,L"text-content",strTextContent);
......@@ -176,7 +178,7 @@ void docx_serialize_text(std::wostream & strm, const std::vector<odf_reader::_pr
}
}
oox_serialize_bodyPr(strm, properties, L"wps");
oox_serialize_bodyPr(strm, val, L"wps");
}
//--------------------------------------------------------------------
......@@ -226,18 +228,25 @@ void docx_serialize_shape_child(std::wostream & strm, _docx_drawing & val)
{
CP_XML_NODE(L"wps:wsp")
{
CP_XML_NODE(L"wps:cNvPr")
{
CP_XML_ATTR(L"id", val.id + 1);
CP_XML_ATTR(L"name",val.name);
}
CP_XML_NODE(L"wps:cNvSpPr")
{
if (val.sub_type==1 || val.sub_type==0)//frame
{
CP_XML_ATTR(L"txBox", 1);
}
if (val.inGroup == false)
{
CP_XML_NODE(L"a:spLocks")
{
CP_XML_ATTR(L"noChangeAspect", 1);
}
}
}
CP_XML_NODE(L"wps:spPr")
{
oox_serialize_xfrm(CP_XML_STREAM(),val);
......@@ -246,22 +255,22 @@ void docx_serialize_shape_child(std::wostream & strm, _docx_drawing & val)
oox_serialize_ln(CP_XML_STREAM(), val.additional);
}
docx_serialize_text(CP_XML_STREAM(),val.additional);
docx_serialize_text(CP_XML_STREAM(),val);
}
}
}
void docx_serialize_group_child(std::wostream & strm, _docx_drawing & val)
{
std::wstring name_node = L"wpg:wgp";
if (val.inGroup)name_node = L"wpg:grpSp";
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"wpg:wgp")
CP_XML_NODE(name_node)
{
CP_XML_NODE(L"wpg:cNvGrpSpPr")
{
CP_XML_NODE(L"a:spLocks")
{
CP_XML_ATTR(L"noChangeAspect", 1);
}
CP_XML_ATTR(L"bwMode", L"auto");
}
CP_XML_NODE(L"wpg:grpSpPr")
......@@ -299,11 +308,11 @@ void docx_serialize_common(std::wostream & strm, _docx_drawing & val)
CP_XML_NODE(L"wp:cNvGraphicFramePr")
{
CP_XML_NODE(L"a:graphicFrameLocks")
{
CP_XML_ATTR(L"xmlns:a",L"http://schemas.openxmlformats.org/drawingml/2006/main");
CP_XML_ATTR(L"noChangeAspect",1);
}
//CP_XML_NODE(L"a:graphicFrameLocks")
//{
// CP_XML_ATTR(L"xmlns:a",L"http://schemas.openxmlformats.org/drawingml/2006/main");
// CP_XML_ATTR(L"noChangeAspect",1);
//}
}
CP_XML_NODE(L"a:graphic")
{
......@@ -371,11 +380,10 @@ void docx_serialize(std::wostream & strm, _docx_drawing & val)
{
CP_XML_NODE(L"wp:extent")
{
CP_XML_ATTR(L"cx",val.cx);
CP_XML_ATTR(L"cy",val.cy);
CP_XML_ATTR(L"cx", val.cx);
CP_XML_ATTR(L"cy", val.cy);
serialize_null_extent(CP_XML_STREAM());
}
}
else//anchor
......
......@@ -15,7 +15,7 @@ namespace oox {
struct _docx_drawing : _oox_drawing
{
_docx_drawing():_oox_drawing(), parallel(0), isInline(false), inGroup(false), number_wrapped_paragraphs(0), posOffsetV(0), posOffsetH(0)
_docx_drawing():_oox_drawing(), parallel(0), isInline(false), number_wrapped_paragraphs(0), posOffsetV(0), posOffsetH(0)
{
}
unsigned int parallel;
......@@ -28,7 +28,6 @@ struct _docx_drawing : _oox_drawing
_CP_OPT(odf_types::style_wrap) styleWrap;
bool inGroup;
bool isInline;
int number_wrapped_paragraphs;
......
......@@ -198,8 +198,10 @@ void oox_serialize_aLst(std::wostream & strm, const std::vector<odf_reader::_pro
}
}
}
void oox_serialize_bodyPr(std::wostream & strm, const std::vector<odf_reader::_property> & prop, const std::wstring & namespace_)
void oox_serialize_bodyPr(std::wostream & strm, _oox_drawing & val, const std::wstring & namespace_)
{
const std::vector<odf_reader::_property> & prop = val.additional;
_CP_OPT(bool) bWordArt;
odf_reader::GetProperty(prop,L"wordArt", bWordArt);
......@@ -218,9 +220,12 @@ void oox_serialize_bodyPr(std::wostream & strm, const std::vector<odf_reader::_p
if (dPaddingTop) CP_XML_ATTR(L"tIns", (int)(*dPaddingTop));
if (dPaddingBottom) CP_XML_ATTR(L"bIns", (int)(*dPaddingBottom));
if (val.inGroup == false)
{
_CP_OPT(int) iWrap;
odf_reader::GetProperty(prop,L"text-wrap" , iWrap);
if ((iWrap) && (*iWrap == 0))CP_XML_ATTR(L"wrap", L"none");
}
_CP_OPT(int) iAlign;
odf_reader::GetProperty(prop,L"textarea-vertical_align",iAlign);
......@@ -360,7 +365,7 @@ void oox_serialize_shape(std::wostream & strm, _oox_drawing & val)
}
}
void oox_serialize_xfrm(std::wostream & strm, _oox_drawing & val, std::wstring name_space)
void oox_serialize_xfrm(std::wostream & strm, _oox_drawing & val, const std::wstring name_space)
{
CP_XML_WRITER(strm)
{
......@@ -419,6 +424,20 @@ void oox_serialize_xfrm(std::wostream & strm, _oox_drawing & val, std::wstring n
{
_CP_LOG << L"[error!!!] not set size object\n";
}
//if (val.type == mediaitems::typeGroup)
//{
// CP_XML_NODE(L"a:chOff")
// {
// CP_XML_ATTR(L"x", 0);
// CP_XML_ATTR(L"y", 0);
// }
// CP_XML_NODE(L"a:chExt")
// {
// CP_XML_ATTR(L"cx", val.cx);
// CP_XML_ATTR(L"cy", val.cy);
// }
//}
}
}
}
......
......@@ -38,11 +38,12 @@ namespace oox {
};
struct _oox_drawing
{
_oox_drawing():type(mediaitems::typeUnknown),id(0),x(0),y(0),cx(0),cy(0),sub_type(0),name(L"object")
_oox_drawing() : type(mediaitems::typeUnknown), id(0), x(0), y(0), cx(0), cy(0), sub_type(0), inGroup(false), name(L"object")
{
}
mediaitems::Type type;
bool inGroup;
size_t id;
std::wstring name;
......@@ -60,11 +61,11 @@ namespace oox {
std::vector<odf_reader::_property> additional;
};
void oox_serialize_xfrm (std::wostream & strm, _oox_drawing & val,std::wstring name_space = L"a");
void oox_serialize_xfrm (std::wostream & strm, _oox_drawing & val, const std::wstring namespace_ = L"a");
void oox_serialize_shape (std::wostream & strm, _oox_drawing & val);
void oox_serialize_ln (std::wostream & strm, const std::vector<odf_reader::_property> & val, bool always_draw = false);
void oox_serialize_hlink (std::wostream & strm, const std::vector<_hlink_desc> & val);
void oox_serialize_bodyPr (std::wostream & strm, const std::vector<odf_reader::_property> & val, const std::wstring & namespace_ = L"a");
void oox_serialize_bodyPr (std::wostream & strm, _oox_drawing & val, const std::wstring & namespace_ = L"a");
void oox_serialize_aLst (std::wostream & strm, const std::vector<odf_reader::_property> & val);
}
}
......@@ -21,16 +21,16 @@ static const std::wstring _docxShapeType[]=
L"custGeom"
};
void pptx_serialize_text(std::wostream & strm, const std::vector<odf_reader::_property> & properties)
void pptx_serialize_text(std::wostream & strm, _pptx_drawing & val)
{
_CP_OPT(std::wstring) strTextContent;
odf_reader::GetProperty(properties,L"text-content",strTextContent);
odf_reader::GetProperty ( val.additional, L"text-content", strTextContent);
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"p:txBody")
{
oox_serialize_bodyPr(CP_XML_STREAM(), properties);
oox_serialize_bodyPr(CP_XML_STREAM(), val);
if (strTextContent)
{
CP_XML_STREAM() << strTextContent.get();
......@@ -141,10 +141,10 @@ void pptx_serialize_shape(std::wostream & strm, _pptx_drawing & val)
oox_serialize_xfrm(CP_XML_STREAM(),val);
oox_serialize_shape(CP_XML_STREAM(),val);
oox_serialize_ln(CP_XML_STREAM(),val.additional);
oox_serialize_ln(CP_XML_STREAM(), val.additional);
}
}
pptx_serialize_text(CP_XML_STREAM(),val.additional);
pptx_serialize_text(CP_XML_STREAM(), val);
}
} // CP_XML_WRITER
}
......
......@@ -21,10 +21,10 @@ std::wostream & operator << (std::wostream & strm, xlsx_drawing_position::type_t
}
}
void xlsx_serialize_text(std::wostream & strm, const std::vector<odf_reader::_property> & properties)
void xlsx_serialize_text(std::wostream & strm, _xlsx_drawing & val )
{
_CP_OPT(std::wstring) strTextContent;
odf_reader::GetProperty(properties,L"text-content",strTextContent);
odf_reader::GetProperty ( val.additional ,L"text-content", strTextContent);
if (!strTextContent)return;
if (strTextContent.get().length()<1)return;
......@@ -33,7 +33,7 @@ void xlsx_serialize_text(std::wostream & strm, const std::vector<odf_reader::_pr
{
CP_XML_NODE(L"xdr:txBody")
{
oox_serialize_bodyPr(CP_XML_STREAM(),properties);
oox_serialize_bodyPr(CP_XML_STREAM(), val);
CP_XML_NODE(L"a:lstStyle");
if (strTextContent)
{
......@@ -112,9 +112,9 @@ void xlsx_serialize_image(std::wostream & strm, _xlsx_drawing & val)
CP_XML_ATTR(L"prst", L"rect");
CP_XML_NODE(L"a:avLst");
}
oox_serialize_ln(CP_XML_STREAM(),val.additional);
oox_serialize_ln(CP_XML_STREAM(), val.additional);
}
xlsx_serialize_text(CP_XML_STREAM(),val.additional);
xlsx_serialize_text(CP_XML_STREAM(), val);
}
} // CP_XML_WRITER
}
......@@ -153,7 +153,7 @@ void xlsx_serialize_shape(std::wostream & strm, _xlsx_drawing & val)
oox_serialize_ln(CP_XML_STREAM(),val.additional, draw_always);
} // xdr:spPr
xlsx_serialize_text(CP_XML_STREAM(),val.additional);
xlsx_serialize_text(CP_XML_STREAM(), val);
}
} // CP_XML_WRITER
}
......
......@@ -853,6 +853,8 @@ void common_draw_docx_convert(oox::docx_conversion_context & Context, const unio
std::wstring transformStr = attlists_.shape_with_text_and_styles_.common_draw_shape_with_styles_attlist_.common_draw_transform_attlist_.draw_transform_.get();
oox_convert_transforms(transformStr,drawing.additional);
}
drawing.x = get_value_emu(attlists_.position_.svg_x_);
drawing.y = get_value_emu(attlists_.position_.svg_y_);
drawing.cx = get_value_emu(attlists_.rel_size_.common_draw_size_attlist_.svg_width_);
......@@ -932,6 +934,20 @@ void common_draw_docx_convert(oox::docx_conversion_context & Context, const unio
drawing.y = val >=0 ? val : 0; //??? todooo ...
}
if (drawing.inGroup && drawing.type != oox::mediaitems::typeGroup)
{
Context.get_drawing_context().set_position_child_group(drawing.x, drawing.y);
Context.get_drawing_context().set_size_child_group(drawing.cx + drawing.x, drawing.cy + drawing.y);
// "" ... ..
INT32 x_group_offset, y_group_offset;
Context.get_drawing_context().get_position_group(x_group_offset, y_group_offset);
drawing.x -= x_group_offset;
drawing.y -= y_group_offset;
}
}
void draw_shape::docx_convert(oox::docx_conversion_context & Context)
{
......@@ -1001,7 +1017,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
if (pos_replaicement >=0 && !Context.get_drawing_context().get_use_image_replace())
return;//
//--------------------------------------------------
// , , ...
oox::docx_conversion_context::StreamsManPtr prev = Context.get_stream_man();
......@@ -1024,8 +1040,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
Context.get_drawing_context().get_text_stream_frame() = temp_stream.str();
Context.set_stream_man(prev);
/////////////////////////////////////////////////////////////////////////////////////////////////////
//--------------------------------------------------
oox::_docx_drawing drawing = oox::_docx_drawing();
drawing.type = oox::mediaitems::typeImage;
......@@ -1033,7 +1048,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
drawing.name = Context.get_drawing_context().get_current_object_name();
drawing.inGroup = Context.get_drawing_context().in_group();
//////////////////////////////////////////////////////////////////////////////////////////////////
//--------------------------------------------------
oox::hyperlinks::_ref hyperlink = Context.last_hyperlink();
// - "" - ( )
// -
......@@ -1088,7 +1103,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
if (!Context.get_drawing_context().in_group())
Context.add_new_run(_T(""));
docx_serialize(strm,drawing);
docx_serialize(strm, drawing);
if (!Context.get_drawing_context().in_group())
Context.finish_run();
......@@ -1212,16 +1227,27 @@ void draw_g::docx_convert(oox::docx_conversion_context & Context)
Context.add_delayed_element(this);
return;
}
oox::_docx_drawing drawing = oox::_docx_drawing();
drawing.id = Context.get_drawing_context().get_current_shape_id();
drawing.type = oox::mediaitems::typeGroup;
drawing.inGroup = Context.get_drawing_context().in_group();
drawing.type = oox::mediaitems::typeGroup;
Context.get_drawing_context().start_group();
/////////
const _CP_OPT(std::wstring) name =
common_draw_attlists_.shape_with_text_and_styles_.
common_draw_shape_with_styles_attlist_.
common_draw_name_attlist_.draw_name_;
Context.get_drawing_context().add_name_object(name.get_value_or(L"Group"));
drawing.id = Context.get_drawing_context().get_current_shape_id();
drawing.name = Context.get_drawing_context().get_current_object_name();
//--------------------------------------------------
common_draw_docx_convert(Context, common_draw_attlists_, drawing);
/////////
//--------------------------------------------------
oox::docx_conversion_context::StreamsManPtr prev = Context.get_stream_man();
std::wstringstream temp_stream(drawing.content_group_);
......@@ -1237,35 +1263,56 @@ void draw_g::docx_convert(oox::docx_conversion_context & Context)
ElementType type = elm->get_type();
elm->docx_convert(Context);
}
drawing.content_group_ = temp_stream.str();
Context.set_stream_man(prev);
Context.set_run_state(runState);
Context.set_paragraph_state(pState);
//--------------------------------------------------
Context.get_drawing_context().get_size_group (drawing.cx , drawing.cy);
Context.get_drawing_context().get_position_group(drawing.x , drawing.y);
if (drawing.cx < 1 || drawing.cy < 1 && content_.size() > 0)
{// - ...
draw_frame* frame = dynamic_cast<draw_frame*>(content_[0].get());
if (frame)
drawing.cx -= drawing.x;
drawing.cy -= drawing.y;
Context.get_drawing_context().stop_group();
if (drawing.inGroup)
{
drawing.cx = get_value_emu(frame->common_draw_attlists_.rel_size_.common_draw_size_attlist_.svg_width_);
drawing.cy = get_value_emu(frame->common_draw_attlists_.rel_size_.common_draw_size_attlist_.svg_height_);
Context.get_drawing_context().set_position_child_group (drawing.x, drawing.y);
Context.get_drawing_context().set_size_child_group (drawing.cx + drawing.x, drawing.cy + drawing.y);
// "" ... ..
INT32 x_group_offset, y_group_offset;
Context.get_drawing_context().get_position_group(x_group_offset, y_group_offset);
drawing.x -= x_group_offset;
drawing.y -= y_group_offset;
}
else
{
draw_shape* shape = dynamic_cast<draw_shape*>(content_[0].get());
if (shape)
{
drawing.cx = get_value_emu(shape->common_draw_attlists_.rel_size_.common_draw_size_attlist_.svg_width_);
drawing.cy = get_value_emu(shape->common_draw_attlists_.rel_size_.common_draw_size_attlist_.svg_height_);
}
}
drawing.posOffsetH = drawing.x;
drawing.posOffsetV = drawing.y;
drawing.x = drawing.y = 0;
}
drawing.content_group_ = temp_stream.str();
//--------------------------------------------------
std::wostream & strm = Context.output_stream();
Context.set_stream_man(prev);
Context.set_run_state(runState);
Context.set_paragraph_state(pState);
pState = Context.get_paragraph_state();
Context.set_paragraph_state(false);
docx_serialize(Context.output_stream(), drawing);
if (!Context.get_drawing_context().in_group())
Context.add_new_run(_T(""));
Context.get_drawing_context().stop_group();
docx_serialize(strm, drawing);
if (!Context.get_drawing_context().in_group())
Context.finish_run();
Context.set_paragraph_state(pState);
//--------------------------------------------------
}
void draw_frame::docx_convert(oox::docx_conversion_context & Context)
{
......@@ -1286,7 +1333,7 @@ void draw_frame::docx_convert(oox::docx_conversion_context & Context)
BOOST_FOREACH(const office_element_ptr & elm, content_)
{
ElementType type = elm->get_type();
Context.get_drawing_context().add_name_object(name.get_value_or(L""));
Context.get_drawing_context().add_name_object(name.get_value_or(L"Object"));
elm->docx_convert(Context);
}
......
......@@ -40,7 +40,7 @@ void draw_shape::common_docx_convert(oox::docx_conversion_context & Context)
common_draw_shape_with_styles_attlist_.
common_draw_name_attlist_.draw_name_;
Context.get_drawing_context().add_name_object(name.get_value_or(L""));
Context.get_drawing_context().add_name_object(name.get_value_or(L"Shape"));
//////////////////////////////
......
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