Commit f3c66cab authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatWriter

parent 11e6fc3e
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Version="8.00"
Name="OdfFileReaderTest"
ProjectGUID="{C2882DDD-07E6-4314-AD4B-48F43F38D722}"
RootNamespace="ASCOfficeOdfFileTest"
......
......@@ -136,6 +136,7 @@ void xlsx_text_context::Impl::serialize_shared_strings(std::wostream & strm)
xlsx_text_context::Impl::Impl(odf_reader::styles_container & styles): paragraphs_cout_(0),styles_(styles),
in_comment(false),in_draw(false),in_paragraph(false),in_span(false),in_cell_content(false)
{
local_styles_ptr_ = NULL;
text_properties_cell_ = NULL;
}
......
......@@ -403,9 +403,11 @@ int draw_enhanced_geometry::parsing(_CP_OPT(std::wstring) val)
void draw_enhanced_geometry_attlist::serialize(CP_ATTR_NODE)
{
CP_XML_ATTR_OPT(L"draw:type", draw_type_);
CP_XML_ATTR_OPT(L"drawooo:sub-view-size", draw_sub_view_size_);
CP_XML_ATTR_OPT(L"draw:text-areas", draw_text_areas_);
CP_XML_ATTR_OPT(L"draw:modifiers", draw_modifiers_);
CP_XML_ATTR_OPT(L"draw:enhanced-path", draw_enhanced_path_);
CP_XML_ATTR_OPT(L"drawooo:enhanced-path", draw_enhanced_path_);
//CP_XML_ATTR_OPT(L"draw:enhanced-path", draw_enhanced_path_);
CP_XML_ATTR_OPT(L"draw:glue-points", draw_glue_points_);
CP_XML_ATTR_OPT(L"draw:mirror-vertical", draw_mirror_vertical_);
CP_XML_ATTR_OPT(L"draw:mirror-horizontal", draw_mirror_horizontal_);
......
......@@ -322,6 +322,8 @@ public:
_CP_OPT(std::wstring) draw_text_areas_;
_CP_OPT(std::wstring) draw_glue_points_;
_CP_OPT(std::wstring) draw_sub_view_size_;
_CP_OPT(odf_types::Bool) draw_mirror_vertical_;
_CP_OPT(odf_types::Bool) draw_mirror_horizontal_;
......
......@@ -139,6 +139,7 @@ public:
void start_object(std::wstring name);
void end_object();
bool isLineShape();
void corrected_line_fill();
office_element_ptr & get_root_element();
......@@ -149,8 +150,12 @@ public:
bool is_exist_content();
//////////////////////////////////////////////////////////////////////////////////////
void set_path (std::wstring path_string);
void add_path_element (std::wstring command, const std::wstring & elm);
void add_path_element (std::wstring command, std::wstring elm);
void add_modifier (std::wstring modifier);
void add_formula (std::wstring name, std::wstring fmla);
void set_textarea (std::wstring l, std::wstring t, std::wstring r, std::wstring b);
void add_handle (std::wstring x, std::wstring y, std::wstring refX, std::wstring refY,
std::wstring minX, std::wstring maxX, std::wstring minY, std::wstring maxY);
void set_viewBox (double W, double H);
......
......@@ -238,11 +238,11 @@ void ods_conversion_context::end_row()
//////////////////////
void ods_conversion_context::start_comment(int col, int row, std::wstring & author)
{
current_table().start_comment(col,row,author);
current_table().start_comment(col, row, author);
start_text_context();
////////////////
office_element_ptr paragr_elm;
create_element(L"text", L"p",paragr_elm,this);
create_element(L"text", L"p", paragr_elm, this);
current_text_context_->start_paragraph(paragr_elm);
}
......@@ -309,7 +309,7 @@ void ods_conversion_context::add_merge_cells(const std::wstring & ref)
void ods_conversion_context::start_cell(std::wstring & ref, int xfd_style)
{
int col=0, row=0;
int col = 0, row = 0;
utils::parsing_ref ( ref, col,row);
if (col > current_table().current_column()+1)
......@@ -389,11 +389,31 @@ void ods_conversion_context::start_rows()
void ods_conversion_context::end_rows()
{
//add default last row
int repeat = (std::max)(current_table().dimension_row,64) - current_table().current_row();
if (repeat < 0) repeat = 1;
int repeated = (std::max)(current_table().dimension_row, 64) - current_table().current_row();
if (repeated < 0) repeated = 1;
while(true)
{
//делим на 3 - до, с комметом, после;
int comment_idx = current_table().is_row_comment(current_table().current_row() + 1, repeated);
if (comment_idx < 0) break;
int rows = current_table().comments_[comment_idx].row - current_table().current_row() - 1;
start_row(current_table().current_row() + 1, rows, 0, true);
end_row();
start_row(current_table().current_row()+1,repeat,0,true);
start_row(current_table().current_row() + 1, 1, 0, true);
end_row();
repeated -= (1 + rows);
}
if (repeated > 0)
{
start_row(current_table().current_row() + 1, repeated, 0, true);
end_row();
}
}
void ods_conversion_context::add_column(int start_column, int repeated, int level, bool _default)
......
......@@ -136,8 +136,8 @@ ods_table_state::ods_table_state(odf_conversion_context * Context, office_elemen
{
office_table_ = elm;
current_table_row_ =0;
current_table_column_ =0;
current_table_row_ = 0;
current_table_column_ = 0;
current_level_.push_back(office_table_);
......@@ -395,7 +395,7 @@ bool ods_table_state::is_cell_hyperlink()
bool ods_table_state::is_cell_comment()
{
if (cells_size_ <1)return false;
return cells_.back().comment_idx >=0 ? true : false;
return cells_.back().comment_idx >= 0 ? true : false;
}
int ods_table_state::is_cell_hyperlink(int col, int row)
......@@ -413,7 +413,18 @@ int ods_table_state::is_cell_comment(int col, int row, short repeate_col)
{
for (size_t i = 0; i < comments_.size(); i++)
{
if ((comments_[i].col < col+repeate_col && comments_[i].col >= col) && comments_[i].row == row)
if ((comments_[i].col < col + repeate_col && comments_[i].col >= col) && comments_[i].row == row)
{
return i;
}
}
return -1;
}
int ods_table_state::is_row_comment(int row, int repeate_row)
{
for (size_t i = 0; i < comments_.size(); i++)
{
if (comments_[i].row < row + repeate_row && comments_[i].row >= row)
{
return i;
}
......@@ -489,7 +500,7 @@ void ods_table_state::start_cell(office_element_ptr & elm, office_element_ptr &
state.empty = true;
state.elm = elm; state.repeated = 1; state.style_name = style_name; state.style_elm = style_elm;
state.row=current_table_row_; state.col =current_table_column_+1;
state.row = current_table_row_; state.col =current_table_column_ + 1;
state.hyperlink_idx = is_cell_hyperlink(state.col, state.row);
state.comment_idx = is_cell_comment(state.col, state.row);
......@@ -1016,8 +1027,8 @@ void ods_table_state::end_cell()
void ods_table_state::add_default_cell( short repeated)
{
int comment_idx = is_cell_comment(current_table_column_+1 , current_table_row_, repeated);
if (comment_idx >=0 && repeated >1)
int comment_idx = is_cell_comment(current_table_column_ + 1 , current_table_row_, repeated);
if (comment_idx >= 0 && repeated > 1)
{
//делим на 3 - до, с комметом, после;
int c = current_table_column_;
......
......@@ -300,6 +300,7 @@ public:
int is_cell_hyperlink (int col, int row);
bool is_cell_comment ();
int is_cell_comment (int col, int row, short repeate_col = 1);
int is_row_comment (int row, int repeate_row = 1);
ods_hyperlink_state & current_hyperlink();
......@@ -317,6 +318,7 @@ public:
odf_drawing_context * drawing_context(){return &drawing_context_;}
std::wstring office_table_name_;
std::vector<ods_comment_state> comments_;
private:
odf_conversion_context * context_;
......@@ -343,8 +345,6 @@ private:
long cells_size_;
std::vector<ods_hyperlink_state> hyperlinks_;
std::vector<ods_comment_state> comments_;
std::vector<ods_shared_formula_state> shared_formulas_;
odf_drawing_context drawing_context_;
......
......@@ -50,6 +50,12 @@
namespace cpdoccore
{
oox_shape::oox_shape()
{
odf_type_name = L"ooxml-non-primitive";
view_box = L"0 0 0 0";
}
oox_shape_ptr oox_shape::create(int ooxPrstGeomType)
{
switch (ooxPrstGeomType)
......@@ -127,7 +133,7 @@ oox_shape_ptr oox_shape::create(int ooxPrstGeomType)
default:
if (ooxPrstGeomType > 2000) return boost::make_shared<oox_shape_textPlain>();
else return boost::make_shared<oox_shape>();
else return oox_shape_ptr();
}
}
......
......@@ -48,6 +48,8 @@ namespace cpdoccore
public:
static oox_shape_ptr create(int ooxPrstGeomType);
oox_shape();
struct _equation
{
std::wstring name;
......@@ -66,7 +68,7 @@ namespace cpdoccore
void add(std::wstring name,std::wstring frmla)
{
_equation q = {name,frmla};
_equation q = {name, frmla};
equations.push_back(q);
}
......@@ -77,9 +79,9 @@ namespace cpdoccore
std::wstring modifiers;
std::wstring text_areas;
std::wstring view_box;
_CP_OPT(std::wstring) sub_view_size;
_CP_OPT(std::wstring) glue_points;
std::wstring odf_type_name;
_CP_OPT(std::wstring) glue_points;
};
};
\ No newline at end of file
......@@ -372,7 +372,17 @@ void OoxConverter::convert(PPTX::Logic::CxnSp *oox_connect)
odf_context()->drawing_context()->start_drawing();
odf_context()->drawing_context()->start_shape(SimpleTypes::shapetypeLine);
int type = SimpleTypes::shapetypeLine;
if ( oox_connect->spPr.Geometry.is<PPTX::Logic::PrstGeom>() )
{
const PPTX::Logic::PrstGeom& prstGeom = oox_connect->spPr.Geometry.as<PPTX::Logic::PrstGeom>();
SimpleTypes::CShapeType<> preset;
preset.FromString(prstGeom.prst.get());
type = preset.GetValue();
}
odf_context()->drawing_context()->start_shape(type);
convert(&oox_connect->spPr, oox_connect->style.GetPointer());
convert(&oox_connect->nvCxnSpPr);
......@@ -462,7 +472,7 @@ void OoxConverter::convert(PPTX::Logic::SpPr *oox_spPr, PPTX::Logic::ShapeStyle*
convert(prstGeom);
convert(custGeom);
bool bLine = prstGeom ? (prstGeom->prst.get() == L"line") : false;
bool bLine = odf_context()->drawing_context()->isLineShape();
if (!bLine)
{
......@@ -526,19 +536,52 @@ void OoxConverter::convert(PPTX::Logic::PrstGeom *oox_geom)
for (size_t i = 0; i < oox_geom->avLst.size(); i++)
{
if (oox_geom->avLst[i].fmla.IsInit())
odf_context()->drawing_context()->add_modifier(oox_geom->avLst[i].fmla.get());
odf_context()->drawing_context()->add_modifier(oox_geom->avLst[i].fmla.get_value_or(L"0"));
}
}
void OoxConverter::convert(PPTX::Logic::CustGeom *oox_cust_geom)
{
if (!oox_cust_geom) return;
for (size_t i = 0; i < oox_cust_geom->gdLst.size(); i++)
{
odf_context()->drawing_context()->add_formula(oox_cust_geom->gdLst[i].name.get_value_or(L""), oox_cust_geom->gdLst[i].fmla.get_value_or(L""));
}
for (size_t i = 0; i < oox_cust_geom->pathLst.size(); i++)
{
convert(&oox_cust_geom->pathLst[i]);
}
for (size_t i = 0; i < oox_cust_geom->avLst.size(); i++)
{
odf_context()->drawing_context()->add_modifier(oox_cust_geom->avLst[i].fmla.get_value_or(L"0"));
}
for (size_t i = 0; i < oox_cust_geom->ahLst.size(); i++)
{
convert(oox_cust_geom->ahLst[i].ah.operator->());
}
if (oox_cust_geom->rect.IsInit())
{
odf_context()->drawing_context()->set_textarea (oox_cust_geom->rect->l.get_value_or(L"0"),
oox_cust_geom->rect->t.get_value_or(L"0"),
oox_cust_geom->rect->r.get_value_or(L"0"),
oox_cust_geom->rect->b.get_value_or(L"0"));
}
}
void OoxConverter::convert(PPTX::Logic::AhXY *oox_handle)
{
if (!oox_handle) return;
odf_context()->drawing_context()->add_handle(oox_handle->x, oox_handle->y,
oox_handle->gdRefX.get_value_or(L""), oox_handle->gdRefY.get_value_or(L""),
oox_handle->minX.get_value_or(L""), oox_handle->maxX.get_value_or(L""),
oox_handle->minX.get_value_or(L""), oox_handle->maxY.get_value_or(L""));
}
void OoxConverter::convert(PPTX::Logic::AhPolar *oox_handle)
{
if (!oox_handle) return;
}
void OoxConverter::convert(PPTX::Logic::EffectLst *oox_effect_list)
{
if (!oox_effect_list) return;
......@@ -618,42 +661,18 @@ void OoxConverter::convert(PPTX::Logic::PathBase *oox_path)
PPTX::Logic::MoveTo* moveTo = dynamic_cast<PPTX::Logic::MoveTo*> (oox_path);
PPTX::Logic::LineTo* lineTo = dynamic_cast<PPTX::Logic::LineTo*> (oox_path);
PPTX::Logic::CubicBezTo* cubicBezTo = dynamic_cast<PPTX::Logic::CubicBezTo*> (oox_path);
PPTX::Logic::CubicBezTo* cubicBezTo = dynamic_cast<PPTX::Logic::CubicBezTo*>(oox_path);
PPTX::Logic::Close* close = dynamic_cast<PPTX::Logic::Close*> (oox_path);
PPTX::Logic::ArcTo* arcTo = dynamic_cast<PPTX::Logic::ArcTo*> (oox_path);
PPTX::Logic::QuadBezTo* quadBezTo = dynamic_cast<PPTX::Logic::QuadBezTo*> (oox_path);
if (moveTo)
{
std::wstring path_elm = moveTo->x + L" " + moveTo->y;
odf_context()->drawing_context()->add_path_element(std::wstring(L"M"), path_elm);
}
if (lineTo)
{
std::wstring path_elm = lineTo->x + L" " + lineTo->y;
odf_context()->drawing_context()->add_path_element(std::wstring(L"L"), path_elm);
}
if (cubicBezTo)
{
std::wstring path_elm = cubicBezTo->x[0] + L" " + cubicBezTo->y[0] + L" " +
cubicBezTo->x[1] + L" " + cubicBezTo->y[1] + L" " +
cubicBezTo->x[2] + L" " + cubicBezTo->y[2];
odf_context()->drawing_context()->add_path_element(std::wstring(L"C"), path_elm);
}
if (quadBezTo)
{
std::wstring path_elm = quadBezTo->x[0] + L" " + quadBezTo->y[0] + L" " +
quadBezTo->x[1] + L" " + quadBezTo->y[1];
odf_context()->drawing_context()->add_path_element(std::wstring(L"S"), path_elm);
}
if (arcTo)
{
}
if (close)
{
std::wstring path_elm ;
odf_context()->drawing_context()->add_path_element(std::wstring(L"Z"), path_elm);
}
if (moveTo) convert(moveTo);
if (lineTo) convert(lineTo);
if (cubicBezTo) convert(cubicBezTo);
if (quadBezTo) convert(quadBezTo);
if (arcTo) convert(arcTo);
if (close) convert(close);
}
......@@ -810,7 +829,7 @@ void OoxConverter::convert(PPTX::Logic::GradFill *oox_grad_fill, DWORD nARGB)
}
void OoxConverter::convert(PPTX::Logic::UniColor * color, std::wstring & hexString, _CP_OPT(double) & opacity, DWORD nARGB)
void OoxConverter::convert(PPTX::Logic::UniColor * color, DWORD & nARGB)
{
if (!color) return;
......@@ -818,6 +837,13 @@ void OoxConverter::convert(PPTX::Logic::UniColor * color, std::wstring & hexStri
smart_ptr<PPTX::Theme> theme(oox_theme()); theme.AddRef();
nARGB = color->GetRGBColor(theme, clrMap, nARGB);
}
void OoxConverter::convert(PPTX::Logic::UniColor * color, std::wstring & hexString, _CP_OPT(double) & opacity, DWORD nARGB)
{
if (!color) return;
convert(color, nARGB);
hexString = XmlUtils::IntToString(nARGB & 0x00FFFFFF, L"#%06X");
......@@ -896,7 +922,7 @@ void OoxConverter::convert(PPTX::Logic::Ln *oox_line_prop, DWORD ARGB, PPTX::Log
{
if (oox_line_prop->headEnd->len.IsInit() || oox_line_prop->headEnd->type.IsInit() || oox_line_prop->headEnd->w.IsInit())
{
int type = 0, w=1, len =1;//medium arrow
int type = 0, w = 1, len = 1;//medium arrow
if (oox_line_prop->headEnd->len.IsInit()) len = oox_line_prop->headEnd->len->GetBYTECode();
if (oox_line_prop->headEnd->type.IsInit()) type = oox_line_prop->headEnd->type->GetBYTECode();
if (oox_line_prop->headEnd->w.IsInit()) w = oox_line_prop->headEnd->w->GetBYTECode();
......@@ -908,7 +934,7 @@ void OoxConverter::convert(PPTX::Logic::Ln *oox_line_prop, DWORD ARGB, PPTX::Log
{
if (oox_line_prop->tailEnd->len.IsInit() || oox_line_prop->tailEnd->type.IsInit() || oox_line_prop->tailEnd->w.IsInit())
{
int type =0, w=1, len =1;//medium arrow
int type = 0, w = 1, len = 1;//medium arrow
if (oox_line_prop->tailEnd->len.IsInit()) len = oox_line_prop->tailEnd->len->GetBYTECode();
if (oox_line_prop->tailEnd->type.IsInit()) type = oox_line_prop->tailEnd->type->GetBYTECode();
if (oox_line_prop->tailEnd->w.IsInit()) w = oox_line_prop->tailEnd->w->GetBYTECode();
......@@ -1487,10 +1513,9 @@ void OoxConverter::convert(PPTX::Logic::ArcTo *oox_geom_path)
{
if (!oox_geom_path) return;
//std::wstring path_elm = std::to_wstring ((int)pt2emu(oox_geom_path->m_oPt.m_oX.GetValue())) +
// std::wstring(L" ")+ std::to_wstring ((int)pt2emu(oox_geom_path->m_oPt.m_oY.GetValue()));
//
//odf_context()->drawing_context()->add_path_element(std::wstring(L"A"), path_elm);
std::wstring path_elm = oox_geom_path->hR + L" " + oox_geom_path->wR + L" " + oox_geom_path->swAng + L" " + oox_geom_path->stAng;
odf_context()->drawing_context()->add_path_element(std::wstring(L"G"), path_elm);
}
void OoxConverter::convert(PPTX::Logic::QuadBezTo *oox_geom_path)
{
......@@ -1522,13 +1547,18 @@ void OoxConverter::convert(PPTX::Logic::StyleRef *style_ref, int type)
{
if (!style_ref) return;
DWORD nARGB = 0;
convert(&style_ref->Color, nARGB);
if (style_ref->idx.IsInit() == false)
{
std::wstring hexColor;
std::wstring hexColor = XmlUtils::IntToString(nARGB & 0x00FFFFFF, L"#%06X");
_CP_OPT(double) opacity;
convert(&style_ref->Color, hexColor, opacity);
if ((nARGB >> 24) != 0xff)
{
opacity = ((nARGB >> 24) /255.) * 100.;
}
if (type != 3) //?? todooo
{
......@@ -1568,14 +1598,14 @@ void OoxConverter::convert(PPTX::Logic::StyleRef *style_ref, int type)
}
}
convert(fill, style_ref->Color.GetARGB());
convert(fill, nARGB);
}
else if (type == 2)
{
index -= 1;
if ((index >= 0) || (index < theme->themeElements.fmtScheme.lnStyleLst.size()))
{
convert(&theme->themeElements.fmtScheme.lnStyleLst[index], style_ref->Color.GetARGB());
convert(&theme->themeElements.fmtScheme.lnStyleLst[index], nARGB);
}
}
else if (type == 3)
......
......@@ -181,6 +181,14 @@ void OoxConverter::convert(OOX::WritingElement *oox_unknown)
{
convert(dynamic_cast<PPTX::Logic::CustGeom*>(oox_unknown));
}break;
case OOX::et_a_ahXY:
{
convert(dynamic_cast<PPTX::Logic::AhXY*>(oox_unknown));
}break;
case OOX::et_a_ahPolar:
{
convert(dynamic_cast<PPTX::Logic::AhPolar*>(oox_unknown));
}break;
case OOX::et_a_lnTo:
{
convert(dynamic_cast<PPTX::Logic::LineTo*>(oox_unknown));
......
......@@ -322,6 +322,8 @@ namespace PPTX
class InnerShdw;
class OuterShdw;
class PrstShdw;
class AhXY;
class AhPolar;
}
}
......@@ -390,6 +392,7 @@ public:
void convert(PPTX::Logic::PathBase *oox_path);
void convert(PPTX::Logic::BodyPr *oox_bodyPr);
void convert(PPTX::Logic::UniFill *oox_fill, DWORD ARGB = 0);
void convert(PPTX::Logic::UniColor *color, DWORD & nARGB);
void convert(PPTX::Logic::UniColor *color, std::wstring & hexString, _CP_OPT(double) & opacity, DWORD ARGB = 0);
void convert(PPTX::Logic::NvSpPr *oox_nvSpPr);
void convert(PPTX::Logic::CNvPr *oox_cnvPr);
......@@ -417,6 +420,8 @@ public:
void convert(PPTX::Logic::QuadBezTo *oox_geom_path);
void convert(PPTX::Logic::CubicBezTo *oox_geom_path);
void convert(PPTX::Logic::Close *oox_geom_path);
void convert(PPTX::Logic::AhXY *oox_handle);
void convert(PPTX::Logic::AhPolar *oox_handle);
void convert(PPTX::Logic::EffectStyle *oox_effect);
void convert(PPTX::Logic::EffectLst *oox_effect_list);
void convert(PPTX::Logic::InnerShdw *oox_effect);
......
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Version="8.00"
Name="Oox2OdfConverter"
ProjectGUID="{BEE01B53-244A-44E6-8947-ED9342D9247E}"
RootNamespace="Oox2OdfConverter"
......
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