Compare commits

..

6 Commits

Author SHA1 Message Date
8925ddeee5 big integer from buffer bug 2017-04-21 10:24:17 +03:00
84824631b2 OdfFormatWriter - presentation styled list 2017-04-20 19:55:18 +03:00
dc3ecb1fc0 BigInteger as string realization 2017-04-20 18:13:10 +03:00
266cef8c49 tests windows 2017-04-20 14:10:38 +03:00
a5e821cd21 . 2017-04-19 20:06:58 +03:00
cb5d92334e OdfFormatWriter - presentation ... 2017-04-18 16:40:03 +03:00
26 changed files with 1459 additions and 511 deletions

View File

@ -72,8 +72,8 @@ public:
void start_base_style(const std::wstring baseStyleName, const odf_types::style_family::type baseStyleType);
void end_base_style();
void ApplyTextProperties (std::wstring style,odf_reader::text_format_properties_content & propertiesOut, odf_types::style_family::type Type);
void ApplyParagraphProperties (std::wstring style,odf_reader::paragraph_format_properties & propertiesOut, odf_types::style_family::type Type);
void ApplyTextProperties (std::wstring style, std::wstring para_style, odf_reader::text_format_properties_content & propertiesOut);
void ApplyParagraphProperties (std::wstring para_style, odf_reader::paragraph_format_properties & propertiesOut);
void ApplyListProperties (odf_reader::paragraph_format_properties & propertiesOut, int Level);
void set_local_styles_container(odf_reader::styles_container* local_styles_);//это если стили объектов содержатся в другом документе
@ -239,32 +239,37 @@ void pptx_text_context::Impl::end_hyperlink(std::wstring hId)
dump_run();
hyperlink_hId = L"";
}
void pptx_text_context::Impl::ApplyTextProperties(std::wstring style_name,odf_reader::text_format_properties_content & propertiesOut, odf_types::style_family::type Type)
void pptx_text_context::Impl::ApplyTextProperties(std::wstring style_name, std::wstring para_style_name, odf_reader::text_format_properties_content & propertiesOut)
{
std::vector<const odf_reader::style_instance *> instances;
odf_reader::style_instance* defaultStyle = NULL;
odf_reader::style_instance* style = NULL;
odf_reader::style_instance* baseStyle = NULL;
odf_reader::style_instance* defaultStyle = NULL;
odf_reader::style_instance* para_style = NULL;
odf_reader::style_instance* text_style = NULL;
odf_reader::style_instance* baseStyle = NULL;
if (local_styles_ptr_)
{
style = local_styles_ptr_->style_by_name(style_name, Type,false/*process_headers_footers_*/);
defaultStyle = local_styles_ptr_->style_default_by_type(Type);
baseStyle = local_styles_ptr_->style_by_name(base_style_name_, base_style_family_,false/*process_headers_footers_*/);
para_style = local_styles_ptr_->style_by_name (para_style_name, odf_types::style_family::Paragraph, false/*process_headers_footers_*/);
text_style = local_styles_ptr_->style_by_name (style_name, odf_types::style_family::Text, false/*process_headers_footers_*/);
defaultStyle = local_styles_ptr_->style_default_by_type (odf_types::style_family::Text);
baseStyle = local_styles_ptr_->style_by_name (base_style_name_, base_style_family_, false/*process_headers_footers_*/);
}
else
{
style = odf_context_.styleContainer().style_by_name(style_name, Type,false/*process_headers_footers_*/);
defaultStyle = odf_context_.styleContainer().style_default_by_type(Type);
baseStyle = odf_context_.styleContainer().style_by_name(base_style_name_, base_style_family_,false/*process_headers_footers_*/);
para_style = odf_context_.styleContainer().style_by_name (para_style_name, odf_types::style_family::Paragraph, false/*process_headers_footers_*/);
text_style = odf_context_.styleContainer().style_by_name (style_name, odf_types::style_family::Text, false/*process_headers_footers_*/);
defaultStyle = odf_context_.styleContainer().style_default_by_type (odf_types::style_family::Text);
baseStyle = odf_context_.styleContainer().style_by_name (base_style_name_, base_style_family_, false/*process_headers_footers_*/);
}
if (defaultStyle) instances.push_back(defaultStyle);
if (baseStyle) instances.push_back(baseStyle);
if (style) instances.push_back(style);
if (para_style) instances.push_back(para_style);
if (text_style) instances.push_back(text_style);
if (style)get_styles_context().start_process_style(style);
else get_styles_context().start_process_style(baseStyle);
if (text_style) get_styles_context().start_process_style(text_style);
else if (para_style) get_styles_context().start_process_style(para_style);
else get_styles_context().start_process_style(baseStyle);
propertiesOut.apply_from(calc_text_properties_content(instances));
}
@ -323,33 +328,33 @@ void pptx_text_context::Impl::ApplyListProperties(odf_reader::paragraph_format_p
}
void pptx_text_context::Impl::ApplyParagraphProperties(std::wstring style_name,odf_reader::paragraph_format_properties & propertiesOut, odf_types::style_family::type Type)
void pptx_text_context::Impl::ApplyParagraphProperties(std::wstring style_name, odf_reader::paragraph_format_properties & propertiesOut)
{
std::vector<const odf_reader::style_instance *> instances;
odf_reader::style_instance* style = NULL;
odf_reader::style_instance * defaultStyle = NULL;
odf_reader::style_instance * baseStyle = NULL;
odf_reader::style_instance* style = NULL;
odf_reader::style_instance* defaultStyle = NULL;
odf_reader::style_instance* baseStyle = NULL;
if (local_styles_ptr_)
{
style = local_styles_ptr_->style_by_name(style_name, Type,false/*process_headers_footers_*/);
defaultStyle = local_styles_ptr_->style_default_by_type(Type);
baseStyle = local_styles_ptr_->style_by_name(base_style_name_, base_style_family_,false/*process_headers_footers_*/);
style = local_styles_ptr_->style_by_name (style_name, odf_types::style_family::Paragraph, false/*process_headers_footers_*/);
defaultStyle = local_styles_ptr_->style_default_by_type (odf_types::style_family::Paragraph);
baseStyle = local_styles_ptr_->style_by_name (base_style_name_, base_style_family_, false/*process_headers_footers_*/);
}
else
{
style = odf_context_.styleContainer().style_by_name(style_name, Type,false/*process_headers_footers_*/);
defaultStyle = odf_context_.styleContainer().style_default_by_type(Type);
baseStyle= odf_context_.styleContainer().style_by_name(base_style_name_, base_style_family_,false/*process_headers_footers_*/);
style = odf_context_.styleContainer().style_by_name (style_name, odf_types::style_family::Paragraph, false/*process_headers_footers_*/);
defaultStyle = odf_context_.styleContainer().style_default_by_type (odf_types::style_family::Paragraph);
baseStyle = odf_context_.styleContainer().style_by_name (base_style_name_, base_style_family_,false/*process_headers_footers_*/);
}
if (defaultStyle) instances.push_back(defaultStyle);
if (baseStyle) instances.push_back(baseStyle);
if (style) instances.push_back(style);
if (style)get_styles_context().start_process_style(style);
else get_styles_context().start_process_style(baseStyle);
if (style) get_styles_context().start_process_style(style);
else get_styles_context().start_process_style(baseStyle);
propertiesOut.apply_from(calc_paragraph_properties_content(instances));
}
@ -360,9 +365,9 @@ void pptx_text_context::Impl::write_pPr(std::wostream & strm)
int level = list_style_stack_.size()-1;
odf_reader::paragraph_format_properties paragraph_properties_;
odf_reader::paragraph_format_properties paragraph_properties_;
ApplyParagraphProperties (paragraph_style_name_, paragraph_properties_,odf_types::style_family::Paragraph);
ApplyParagraphProperties (paragraph_style_name_, paragraph_properties_);
ApplyListProperties (paragraph_properties_, level);//выравнивания листа накатим на свойства параграфа
paragraph_properties_.pptx_convert(pptx_context_);
@ -403,16 +408,9 @@ void pptx_text_context::Impl::write_rPr(std::wostream & strm)
if (paragraph_style_name_.empty() && span_style_name_.empty() && !(!hyperlink_hId.empty()) && base_style_name_.empty())
return;
odf_reader::text_format_properties_content text_properties_paragraph_;
ApplyTextProperties (paragraph_style_name_, text_properties_paragraph_,odf_types::style_family::Paragraph);
odf_reader::text_format_properties_content text_properties_span_;
ApplyTextProperties(span_style_name_, text_properties_span_,odf_types::style_family::Text);
odf_reader::text_format_properties_content text_properties_;
text_properties_.apply_from(text_properties_paragraph_);
text_properties_.apply_from(text_properties_span_);
ApplyTextProperties(span_style_name_, paragraph_style_name_, text_properties_);
get_styles_context().start();

View File

@ -84,10 +84,10 @@ public:
void serialize_shared_strings(std::wostream & strm);
void ApplyTextProperties (std::wstring style, odf_reader::text_format_properties_content & propertiesOut, odf_types::style_family::type Type);
void ApplyParagraphProperties (std::wstring style, odf_reader::paragraph_format_properties & propertiesOut, odf_types::style_family::type Type);
void ApplyTextProperties (std::wstring style, std::wstring para_style, odf_reader::text_format_properties_content & propertiesOut);
void ApplyParagraphProperties (std::wstring style, odf_reader::paragraph_format_properties & propertiesOut);
void set_local_styles_container(odf_reader::styles_container* local_styles_);//это если стили объектов содержатся в другом документе
void set_local_styles_container (odf_reader::styles_container* local_styles_);//это если стили объектов содержатся в другом документе
bool is_drawing_context(){return in_draw;}
@ -237,48 +237,54 @@ void xlsx_text_context::Impl::end_hyperlink(std::wstring hId)
hyperlink_hId = hId;
}
void xlsx_text_context::Impl::ApplyParagraphProperties (std::wstring style, odf_reader::paragraph_format_properties & propertiesOut, odf_types::style_family::type Type)
void xlsx_text_context::Impl::ApplyParagraphProperties (std::wstring style, odf_reader::paragraph_format_properties & propertiesOut)
{
std::vector<const odf_reader::style_instance *> instances;
odf_reader::style_instance* defaultStyle = NULL;
odf_reader::style_instance* paraStyle = NULL;
if (local_styles_ptr_)
{
odf_reader::style_instance * defaultStyle = local_styles_ptr_->style_default_by_type(Type);
if (defaultStyle)instances.push_back(defaultStyle);
odf_reader::style_instance* styleInst = local_styles_ptr_->style_by_name(style, Type,false/*process_headers_footers_*/);
if(styleInst)instances.push_back(styleInst);
defaultStyle = local_styles_ptr_->style_default_by_type(odf_types::style_family::Paragraph);
paraStyle = local_styles_ptr_->style_by_name(style, odf_types::style_family::Paragraph, false/*process_headers_footers_*/);
}
else
{
odf_reader::style_instance * defaultStyle = styles_.style_default_by_type(Type);
if (defaultStyle)instances.push_back(defaultStyle);
odf_reader::style_instance* styleInst = styles_.style_by_name(style, Type,false/*process_headers_footers_*/);
if(styleInst)instances.push_back(styleInst);
defaultStyle = styles_.style_default_by_type(odf_types::style_family::Paragraph);
paraStyle = styles_.style_by_name(style, odf_types::style_family::Paragraph, false/*process_headers_footers_*/);
}
if (defaultStyle) instances.push_back(defaultStyle);
if (paraStyle) instances.push_back(paraStyle);
propertiesOut.apply_from(calc_paragraph_properties_content(instances));
}
void xlsx_text_context::Impl::ApplyTextProperties(std::wstring style, odf_reader::text_format_properties_content & propertiesOut, odf_types::style_family::type Type)
void xlsx_text_context::Impl::ApplyTextProperties(std::wstring style, std::wstring para_style, odf_reader::text_format_properties_content & propertiesOut)
{
std::vector<const odf_reader::style_instance *> instances;
odf_reader::style_instance* defaultStyle = NULL;
odf_reader::style_instance* textStyle = NULL;
odf_reader::style_instance* paraStyle = NULL;
if (local_styles_ptr_)
{
odf_reader::style_instance * defaultStyle = local_styles_ptr_->style_default_by_type(Type);
if (defaultStyle)instances.push_back(defaultStyle);
odf_reader::style_instance* styleInst = local_styles_ptr_->style_by_name(style, Type,false/*process_headers_footers_*/);
if(styleInst)instances.push_back(styleInst);
defaultStyle = local_styles_ptr_->style_default_by_type(odf_types::style_family::Text);
paraStyle = local_styles_ptr_->style_by_name(para_style, odf_types::style_family::Paragraph, false/*process_headers_footers_*/);
textStyle = local_styles_ptr_->style_by_name(style, odf_types::style_family::Text, false/*process_headers_footers_*/);
}
else
{
odf_reader::style_instance * defaultStyle = styles_.style_default_by_type(Type);
if (defaultStyle)instances.push_back(defaultStyle);
odf_reader::style_instance* styleInst = styles_.style_by_name(style, Type,false/*process_headers_footers_*/);
if(styleInst)instances.push_back(styleInst);
defaultStyle = styles_.style_default_by_type(odf_types::style_family::Text);
paraStyle = styles_.style_by_name(para_style, odf_types::style_family::Paragraph, false/*process_headers_footers_*/);
textStyle = styles_.style_by_name(style, odf_types::style_family::Text, false/*process_headers_footers_*/);
}
if (defaultStyle) instances.push_back(defaultStyle);
if (paraStyle) instances.push_back(paraStyle);
if (textStyle) instances.push_back(textStyle);
propertiesOut.apply_from(calc_text_properties_content(instances));
}
@ -291,10 +297,10 @@ void xlsx_text_context::Impl::write_pPr (std::wostream & strm)
{
if (paragraph_style_name_.empty())return;
odf_reader::paragraph_format_properties paragraph_format_properties_;
odf_reader::paragraph_format_properties paragraph_format_properties_;
ApplyParagraphProperties (paragraph_style_name_, paragraph_format_properties_ , odf_types::style_family::Paragraph);
paragraph_format_properties_.xlsx_convert(strm, in_draw);
ApplyParagraphProperties (paragraph_style_name_, paragraph_format_properties_);
paragraph_format_properties_.xlsx_convert (strm, in_draw);
}
void xlsx_text_context::Impl::write_rPr(std::wostream & strm)
@ -303,20 +309,13 @@ void xlsx_text_context::Impl::write_rPr(std::wostream & strm)
&& !(!hyperlink_hId.empty() && in_draw)
&& !(text_properties_cell_ && in_cell_content))return;
odf_reader::text_format_properties_content text_properties_paragraph_;
odf_reader::text_format_properties_content text_properties_span_;
ApplyTextProperties (paragraph_style_name_, text_properties_paragraph_ , odf_types::style_family::Paragraph);
ApplyTextProperties (span_style_name_, text_properties_span_ , odf_types::style_family::Text);
odf_reader::text_format_properties_content text_properties_;
if (in_cell_content && text_properties_cell_)
{
text_properties_.apply_from(*text_properties_cell_);
}
text_properties_.apply_from(text_properties_paragraph_);
text_properties_.apply_from(text_properties_span_);
}
ApplyTextProperties (span_style_name_, paragraph_style_name_, text_properties_);
_CP_OPT(double) dValFontSize;
if (text_properties_.fo_font_size_)

View File

@ -41,22 +41,22 @@ std::wostream & operator << (std::wostream & _Wostream, const presentation_class
std::wstring res = L"";
switch(_Val.get_type())
{
case presentation_class::title: _Wostream << L"title" ; break;
case presentation_class::subtitle: _Wostream << L"subtitle" ; break;
case presentation_class::graphic: _Wostream << L"graphic" ; break;
case presentation_class::object: _Wostream << L"object" ; break;
case presentation_class::chart: _Wostream << L"chart" ; break;
case presentation_class::table: _Wostream << L"table" ; break;
case presentation_class::orgchart: _Wostream << L"orgchart" ; break;
case presentation_class::header: _Wostream << L"header" ; break;
case presentation_class::footer: _Wostream << L"footer" ; break;
case presentation_class::date_time: _Wostream << L"date_time" ; break;
case presentation_class::page_number: _Wostream << L"page_number" ; break;
case presentation_class::page: _Wostream << L"page" ; break;
case presentation_class::notes: _Wostream << L"notes" ; break;
case presentation_class::handout: _Wostream << L"handout" ; break;
case presentation_class::outline: _Wostream << L"outline" ; break;
case presentation_class::text: _Wostream << L"text" ; break;
case presentation_class::title: _Wostream << L"title"; break;
case presentation_class::subtitle: _Wostream << L"subtitle"; break;
case presentation_class::graphic: _Wostream << L"graphic"; break;
case presentation_class::object: _Wostream << L"object"; break;
case presentation_class::chart: _Wostream << L"chart"; break;
case presentation_class::table: _Wostream << L"table"; break;
case presentation_class::orgchart: _Wostream << L"orgchart"; break;
case presentation_class::header: _Wostream << L"header"; break;
case presentation_class::footer: _Wostream << L"footer"; break;
case presentation_class::date_time: _Wostream << L"date-time"; break;
case presentation_class::page_number: _Wostream << L"page-number";break;
case presentation_class::page: _Wostream << L"page"; break;
case presentation_class::notes: _Wostream << L"notes"; break;
case presentation_class::handout: _Wostream << L"handout"; break;
case presentation_class::outline: _Wostream << L"outline"; break;
case presentation_class::text: _Wostream << L"text"; break;
}
return _Wostream;
}
@ -65,41 +65,24 @@ presentation_class presentation_class::parse(const std::wstring & Str)
std::wstring tmp = Str;
boost::algorithm::to_lower(tmp);
if (tmp == L"page")
return presentation_class( page );
else if (tmp == L"title")
return presentation_class( title);
else if (tmp == L"outline")
return presentation_class( outline );
else if (tmp == L"subtitle")
return presentation_class( subtitle);
else if (tmp == L"text")
return presentation_class( text);
else if (tmp == L"graphic")
return presentation_class( graphic );
else if (tmp == L"object")
return presentation_class( object );
else if (tmp == L"chart")
return presentation_class( chart );
else if (tmp == L"table")
return presentation_class( table );
else if (tmp == L"orgchart")
return presentation_class( orgchart );
else if (tmp == L"notes")
return presentation_class( notes );
else if (tmp == L"handout")
return presentation_class( handout );
else if (tmp == L"header")
return presentation_class( header );
else if (tmp == L"footer")
return presentation_class( footer );
else if (tmp == L"date-time")
return presentation_class( date_time );
else if (tmp == L"page-number")
return presentation_class( page_number );
else
if (tmp == L"page") return presentation_class( page );
else if (tmp == L"title") return presentation_class( title);
else if (tmp == L"outline") return presentation_class( outline );
else if (tmp == L"subtitle") return presentation_class( subtitle);
else if (tmp == L"text") return presentation_class( text);
else if (tmp == L"graphic") return presentation_class( graphic );
else if (tmp == L"object") return presentation_class( object );
else if (tmp == L"chart") return presentation_class( chart );
else if (tmp == L"table") return presentation_class( table );
else if (tmp == L"orgchart") return presentation_class( orgchart );
else if (tmp == L"notes") return presentation_class( notes );
else if (tmp == L"handout") return presentation_class( handout );
else if (tmp == L"header") return presentation_class( header );
else if (tmp == L"footer") return presentation_class( footer );
else if (tmp == L"date-time") return presentation_class( date_time );
else if (tmp == L"page-number") return presentation_class( page_number );
else
{
BOOST_THROW_EXCEPTION( errors::invalid_attribute() );
return presentation_class( page );
}
}

View File

@ -458,7 +458,7 @@ void paragraph_format_properties::pptx_convert(oox::pptx_conversion_context & Co
{
CP_XML_NODE(L"a:spcBef")
{
if (fo_margin_bottom_->get_type() == length_or_percent::Length)
if (fo_margin_top_->get_type() == length_or_percent::Length)
{
std::wstring w_before = pptx_process_margin(fo_margin_top_, length::pt, 100.0);
CP_XML_NODE(L"a:spcPts")

View File

@ -262,6 +262,7 @@ void odf_conversion_context::process_settings(_object & object, bool isRoot)
void odf_conversion_context::process_styles(_object & object, bool isRoot)
{
create_element(L"office", L"styles", object.styles, this, true);//общие стили
object.style_context->process_office_styles(object.styles.back());
page_layout_context()->process_office_styles(object.styles.back());

View File

@ -76,7 +76,7 @@ struct odf_group_state
scale_cx = scale_cy = 1.;
flipH = flipV = false;
elm = elm_;
elm = elm_;
level = level_;
prev_group = prev;
@ -185,19 +185,19 @@ struct odf_drawing_state
presentation_class_ = boost::none;
presentation_placeholder_ = boost::none;
rotateAngle = boost::none;
rotateAngle_ = boost::none;
path_ = L"";
view_box_ = L"";
path_last_command_ = L"";
oox_shape_preset = -1;
oox_shape_preset_ = -1;
oox_shape_.reset();
in_group = false;
text_box_tableframe = false;
in_group_ = false;
text_box_tableframe_= false;
flipH = flipV = false;
flipH_ = flipV_ = false;
}
std::vector<odf_element_state> elements_;
@ -207,28 +207,29 @@ struct odf_drawing_state
_CP_OPT(length) svg_height_;
_CP_OPT(length) svg_width_;
bool flipH_;
bool flipV_;
std::wstring name_;
std::wstring description_;
int z_order_;
bool hidden_;
_CP_OPT(double) rotateAngle;
_CP_OPT(double) rotateAngle_;
_CP_OPT(unsigned int) fill_color_;
_CP_OPT(presentation_class) presentation_class_;
_CP_OPT(std::wstring) presentation_placeholder_;
bool flipH;
bool flipV;
std::wstring path_;
std::wstring view_box_;
std::wstring path_last_command_;
oox_shape_ptr oox_shape_;
///////////////////////
int oox_shape_preset;
bool in_group;
bool text_box_tableframe;
int oox_shape_preset_;
bool in_group_;
bool text_box_tableframe_;
};
class odf_drawing_context::Impl
@ -461,7 +462,7 @@ void odf_drawing_context::start_drawing()
//else
if (impl_->current_level_.size() > 0)
{
impl_->current_drawing_state_.in_group = true;
impl_->current_drawing_state_.in_group_ = true;
}
}
@ -509,20 +510,20 @@ void odf_drawing_context::end_drawing()
std::wstring strTransform;
if (impl_->current_drawing_state_.in_group && impl_->current_group_)
if (impl_->current_drawing_state_.in_group_ && impl_->current_group_)
{
double rotate = impl_->current_group_->rotate;
if (impl_->current_drawing_state_.rotateAngle )
rotate += *impl_->current_drawing_state_.rotateAngle;
if (impl_->current_drawing_state_.rotateAngle_)
rotate += *impl_->current_drawing_state_.rotateAngle_;
if (fabs(rotate)>0.001)impl_->current_drawing_state_.rotateAngle = rotate;
if (fabs(rotate)>0.001)impl_->current_drawing_state_.rotateAngle_ = rotate;
}
double x = impl_->current_drawing_state_.svg_x_ ? impl_->current_drawing_state_.svg_x_->get_value() : 0;
double y = impl_->current_drawing_state_.svg_y_ ? impl_->current_drawing_state_.svg_y_->get_value() : 0;
if (impl_->current_drawing_state_.rotateAngle)
if (impl_->current_drawing_state_.rotateAngle_)
{
if (impl_->current_drawing_state_.in_group)
if (impl_->current_drawing_state_.in_group_)
{
if (impl_->current_drawing_state_.svg_width_ && impl_->current_drawing_state_.svg_height_)
{
@ -532,7 +533,7 @@ void odf_drawing_context::end_drawing()
}
}
strTransform += std::wstring(L"rotate(") + boost::lexical_cast<std::wstring>(impl_->current_drawing_state_.rotateAngle.get()) + std::wstring(L")");
strTransform += std::wstring(L"rotate(") + boost::lexical_cast<std::wstring>(impl_->current_drawing_state_.rotateAngle_.get()) + std::wstring(L")");
//так как вращения все в мс относительно центра фигуры, а не от начала координат - убираем смещение
if (impl_->current_drawing_state_.svg_x_ && impl_->current_drawing_state_.svg_y_)
@ -576,14 +577,14 @@ void odf_drawing_context::end_drawing()
placeholder->svg_height_ = impl_->current_drawing_state_.svg_height_;
placeholder->svg_width_ = impl_->current_drawing_state_.svg_width_;
}
if (impl_->current_drawing_state_.in_group)
if (impl_->current_drawing_state_.in_group_)
{
odf_group_state_ptr gr = impl_->current_group_;
while(gr)
{
impl_->current_drawing_state_.flipH = impl_->current_drawing_state_.flipH ^ gr->flipH;
impl_->current_drawing_state_.flipV = impl_->current_drawing_state_.flipV ^ gr->flipV;
impl_->current_drawing_state_.flipH_ = impl_->current_drawing_state_.flipH_ ^ gr->flipH;
impl_->current_drawing_state_.flipV_ = impl_->current_drawing_state_.flipV_ ^ gr->flipV;
gr = gr->prev_group;
}
@ -594,8 +595,8 @@ void odf_drawing_context::end_drawing()
draw_enhanced_geometry* enhan = dynamic_cast<draw_enhanced_geometry*>(custom->draw_enhanced_geometry_.get());
if(enhan)
{
if (impl_->current_drawing_state_.flipV) enhan->draw_enhanced_geometry_attlist_.draw_mirror_vertical_ = true;
if (impl_->current_drawing_state_.flipH) enhan->draw_enhanced_geometry_attlist_.draw_mirror_horizontal_ = true;
if (impl_->current_drawing_state_.flipV_) enhan->draw_enhanced_geometry_attlist_.draw_mirror_vertical_ = true;
if (impl_->current_drawing_state_.flipH_) enhan->draw_enhanced_geometry_attlist_.draw_mirror_horizontal_ = true;
}
}else
{
@ -615,7 +616,7 @@ void odf_drawing_context::end_drawing()
impl_->current_graphic_properties->common_horizontal_margin_attlist_.fo_margin_right_ = impl_->anchor_settings_.fo_margin_right_;
impl_->current_graphic_properties->common_vertical_margin_attlist_.fo_margin_bottom_ = impl_->anchor_settings_.fo_margin_bottom_;
if (draw && !impl_->current_drawing_state_.in_group)
if (draw && !impl_->current_drawing_state_.in_group_)
draw->common_draw_attlists_.shape_with_text_and_styles_.common_text_anchor_attlist_.type_ = impl_->anchor_settings_.anchor_type_;
impl_->current_graphic_properties->style_wrap_ = impl_->anchor_settings_.style_wrap_;
@ -728,7 +729,7 @@ void odf_drawing_context::Impl::create_draw_base(int type)
void odf_drawing_context::start_shape(int type)
{
impl_->current_drawing_state_.oox_shape_preset = type;
impl_->current_drawing_state_.oox_shape_preset_ = type;
if (type < sizeof(Shape_Types_Mapping)/sizeof(_sh_typ))
{
@ -756,12 +757,21 @@ void odf_drawing_context::start_shape(int type)
}
}
bool odf_drawing_context::change_text_box_2_wordart()
bool odf_drawing_context::is_wordart()
{
if (impl_->current_drawing_state_.oox_shape_preset > 2000 && impl_->current_drawing_state_.oox_shape_preset < 3000)
if (impl_->current_drawing_state_.oox_shape_preset_ > 2000 && impl_->current_drawing_state_.oox_shape_preset_ < 3000)
return true;
if (impl_->current_drawing_state_.text_box_tableframe) return false;
return false;
}
bool odf_drawing_context::change_text_box_2_wordart()
{
if (impl_->current_drawing_state_.oox_shape_preset_ > 2000 && impl_->current_drawing_state_.oox_shape_preset_ < 3000)
return true;
if (impl_->current_drawing_state_.presentation_class_) return false;
if (impl_->current_drawing_state_.text_box_tableframe_) return false;
if (impl_->current_drawing_state_.elements_.empty()) return false;
draw_text_box* t = dynamic_cast<draw_text_box*>(impl_->current_drawing_state_.elements_.back().elm.get());
@ -799,7 +809,7 @@ bool odf_drawing_context::change_text_box_2_wordart()
impl_->current_drawing_state_.elements_.erase(impl_->current_drawing_state_.elements_.end() - 2, impl_->current_drawing_state_.elements_.end());
impl_->current_drawing_state_.elements_.push_back( state);
impl_->current_drawing_state_.oox_shape_preset = 2031;//plain text
impl_->current_drawing_state_.oox_shape_preset_ = 2031;//plain text
if (sz == 2) impl_->root_element_ = draw_elm;
return true;
@ -810,8 +820,8 @@ void odf_drawing_context::end_shape()
if (impl_->current_drawing_state_.elements_.empty())
return;
if (impl_->current_drawing_state_.oox_shape_preset == 2000) return end_text_box();
if (impl_->current_drawing_state_.oox_shape_preset == 3000) return end_image();
if (impl_->current_drawing_state_.oox_shape_preset_ == 2000) return end_text_box();
if (impl_->current_drawing_state_.oox_shape_preset_ == 3000) return end_image();
//вторичные, вычисляемые свойства шейпов
if (isLineShape())
@ -848,7 +858,7 @@ void odf_drawing_context::end_shape()
impl_->current_drawing_state_.svg_x_ = boost::none;
impl_->current_drawing_state_.svg_y_ = boost::none;
if (impl_->current_drawing_state_.flipV)
if (impl_->current_drawing_state_.flipV_)
{
_CP_OPT(length) tmp;
@ -856,7 +866,7 @@ void odf_drawing_context::end_shape()
line->draw_line_attlist_.svg_y1_ = line->draw_line_attlist_.svg_y2_;
line->draw_line_attlist_.svg_y2_ = tmp;
}
if (impl_->current_drawing_state_.flipH)
if (impl_->current_drawing_state_.flipH_)
{
_CP_OPT(length) tmp;
@ -881,11 +891,11 @@ void odf_drawing_context::end_shape()
std::wstring sub_type;
bool text_shape = false;
if (impl_->current_drawing_state_.oox_shape_preset < sizeof(Shape_Types_Mapping)/sizeof(_sh_typ))
if (impl_->current_drawing_state_.oox_shape_preset_ < sizeof(Shape_Types_Mapping)/sizeof(_sh_typ))
{
sub_type = Shape_Types_Mapping[impl_->current_drawing_state_.oox_shape_preset].first;
sub_type = Shape_Types_Mapping[impl_->current_drawing_state_.oox_shape_preset_].first;
}
else if (impl_->current_drawing_state_.oox_shape_preset > 2000 && impl_->current_drawing_state_.oox_shape_preset < 3000)// 3000 - все равно сюда не попадет
else if (impl_->current_drawing_state_.oox_shape_preset_ > 2000 && impl_->current_drawing_state_.oox_shape_preset_ < 3000)// 3000 - все равно сюда не попадет
{
text_shape = true;
}
@ -925,7 +935,7 @@ void odf_drawing_context::end_shape()
}
else
{
oox_shape_ptr shape_define = oox_shape::create(impl_->current_drawing_state_.oox_shape_preset);
oox_shape_ptr shape_define = oox_shape::create(impl_->current_drawing_state_.oox_shape_preset_);
if (!shape_define) shape_define = impl_->current_drawing_state_.oox_shape_;
@ -1001,7 +1011,7 @@ bool odf_drawing_context::isLineShape()
draw_path* path = dynamic_cast<draw_path*>(impl_->current_level_.back().get());
if (path) return true;
switch(impl_->current_drawing_state_.oox_shape_preset)
switch(impl_->current_drawing_state_.oox_shape_preset_)
{
case 20: //SimpleTypes::shapetypeBentConnector2:
case 21: //SimpleTypes::shapetypeBentConnector3:
@ -1453,11 +1463,11 @@ void odf_drawing_context::add_formula (std::wstring name, std::wstring fmla)
break;
}
XmlUtils::replace_all(odf_fmla, L"gd", L"?f");
//XmlUtils::replace_all(odf_fmla, L"gd", L"?f");
XmlUtils::replace_all(odf_fmla, L"h", L"logheight");
XmlUtils::replace_all(odf_fmla, L"w", L"logwidth");
XmlUtils::replace_all(odf_fmla, L"adj", L"$");
XmlUtils::replace_all(name, L"gd", L"f");
//XmlUtils::replace_all(name, L"gd", L"f");
impl_->current_drawing_state_.oox_shape_->add(name, odf_fmla);
}
@ -1486,7 +1496,7 @@ void odf_drawing_context::set_viewBox (double W, double H)
}
void odf_drawing_context::set_flip_H(bool bVal)
{
impl_->current_drawing_state_.flipH = bVal;
impl_->current_drawing_state_.flipH_ = bVal;
if (impl_->current_graphic_properties == NULL) return;
if (bVal == false)return;
@ -1498,7 +1508,7 @@ void odf_drawing_context::set_flip_H(bool bVal)
}
void odf_drawing_context::set_flip_V(bool bVal)
{
impl_->current_drawing_state_.flipV = bVal;
impl_->current_drawing_state_.flipV_ = bVal;
if (impl_->current_graphic_properties == NULL) return;
if (bVal == false)return;
@ -1513,7 +1523,7 @@ void odf_drawing_context::set_rotate(double dVal)
{
if (dVal > 180) dVal = dVal - 360;
double dRotate = dVal / 180. * 3.14159265358979323846;
impl_->current_drawing_state_.rotateAngle = dRotate;
impl_->current_drawing_state_.rotateAngle_ = dRotate;
}
void odf_drawing_context::set_drawings_rect(_CP_OPT(double) x_pt, _CP_OPT(double) y_pt, _CP_OPT(double) width_pt, _CP_OPT(double) height_pt)// "- 1" не задано
@ -1742,7 +1752,7 @@ void odf_drawing_context::set_group_flip_V(bool bVal)
{
if ( impl_->group_list_.empty() )return;
impl_->current_group_->flipV= bVal;
impl_->current_group_->flipV = bVal;
}
void odf_drawing_context::set_group_z_order(int Val)
{
@ -1767,7 +1777,7 @@ void odf_drawing_context::set_group_flip_H(bool bVal)
{
if ( impl_->group_list_.empty() )return;
impl_->current_group_->flipH= bVal;
impl_->current_group_->flipH = bVal;
}
void odf_drawing_context::set_group_rotate(int iVal)
@ -1794,14 +1804,14 @@ void odf_drawing_context::set_position_line(_CP_OPT(double) & x_pt, _CP_OPT(doub
draw_line* line = dynamic_cast<draw_line*>(impl_->current_level_.back().get());
if (line == NULL) return;
if (impl_->current_drawing_state_.in_group && impl_->current_group_ && x_pt)
if (impl_->current_drawing_state_.in_group_ && impl_->current_group_ && x_pt)
x_pt = *x_pt * impl_->current_group_->scale_cx + impl_->current_group_->shift_x ;
// + (impl_->current_group_->flipH ? (impl_->current_group_->cx - 2 * x_pt): 0);
if (x_pt && !line->draw_line_attlist_.svg_x1_)
line->draw_line_attlist_.svg_x1_ = length(length(*x_pt,length::pt).get_value_unit(length::cm),length::cm);
if (impl_->current_drawing_state_.in_group && impl_->current_group_ && y_pt)
if (impl_->current_drawing_state_.in_group_ && impl_->current_group_ && y_pt)
y_pt = *y_pt * impl_->current_group_->scale_cy + impl_->current_group_->shift_y;
//+ (impl_->current_group_->flipV ? (impl_->current_group_->cy - 2 * y_pt): 0);
@ -1809,13 +1819,13 @@ void odf_drawing_context::set_position_line(_CP_OPT(double) & x_pt, _CP_OPT(doub
line->draw_line_attlist_.svg_y1_ = length(length(*y_pt,length::pt).get_value_unit(length::cm),length::cm);
///////////////////////////////////////
if (impl_->current_drawing_state_.in_group && impl_->current_group_ && x2_pt)
if (impl_->current_drawing_state_.in_group_ && impl_->current_group_ && x2_pt)
x2_pt = *x2_pt * impl_->current_group_->scale_cx + impl_->current_group_->shift_x ;
// + (impl_->current_group_->flipH ? (impl_->current_group_->cx - 2 * x_pt): 0);
if (x2_pt && !line->draw_line_attlist_.svg_x2_) line->draw_line_attlist_.svg_x2_ = length(length(*x2_pt,length::pt).get_value_unit(length::cm),length::cm);
if (impl_->current_drawing_state_.in_group && impl_->current_group_ && y2_pt)
if (impl_->current_drawing_state_.in_group_ && impl_->current_group_ && y2_pt)
y2_pt = *y2_pt * impl_->current_group_->scale_cy + impl_->current_group_->shift_y;
//+ (impl_->current_group_->flipV ? (impl_->current_group_->cy - 2 * y_pt): 0);
@ -1841,14 +1851,14 @@ void odf_drawing_context::set_position(_CP_OPT(double) & x_pt, _CP_OPT(double) &
{
double x = *x_pt;
if (impl_->current_drawing_state_.in_group)
if (impl_->current_drawing_state_.in_group_)
{
for( int i = impl_->group_list_.size() - 1; i >= 0 ; i--)
{
x = (x + impl_->group_list_[i]->shift_x) * impl_->group_list_[i]->scale_cx ;
}
}
if (!impl_->current_drawing_state_.svg_x_ || impl_->current_drawing_state_.in_group)
if (!impl_->current_drawing_state_.svg_x_ || impl_->current_drawing_state_.in_group_)
{
impl_->current_drawing_state_.svg_x_ = length(length(x , length::pt).get_value_unit(length::cm), length::cm);
}
@ -1858,7 +1868,7 @@ void odf_drawing_context::set_position(_CP_OPT(double) & x_pt, _CP_OPT(double) &
{
double y = *y_pt;
if (impl_->current_drawing_state_.in_group)
if (impl_->current_drawing_state_.in_group_)
{
for( int i = impl_->group_list_.size() - 1; i >= 0 ; i--)
{
@ -1866,7 +1876,7 @@ void odf_drawing_context::set_position(_CP_OPT(double) & x_pt, _CP_OPT(double) &
}
}
if (!impl_->current_drawing_state_.svg_y_ || impl_->current_drawing_state_.in_group)
if (!impl_->current_drawing_state_.svg_y_ || impl_->current_drawing_state_.in_group_)
{
impl_->current_drawing_state_.svg_y_ = length(length(y, length::pt).get_value_unit(length::cm),length::cm);
}
@ -1887,7 +1897,7 @@ void odf_drawing_context::get_size( _CP_OPT(double) & width_pt, _CP_OPT(double)
}
void odf_drawing_context::set_size( _CP_OPT(double) & width_pt, _CP_OPT(double) & height_pt)
{
if (impl_->current_drawing_state_.in_group)
if (impl_->current_drawing_state_.in_group_)
{
if (width_pt)
{
@ -2129,7 +2139,7 @@ void odf_drawing_context::set_textarea_writing_mode(int mode)
style* style_ = NULL;
if(!draw->common_draw_attlists_.shape_with_text_and_styles_.common_shape_draw_attlist_.draw_text_style_name_)
{
impl_->styles_context_->create_style(L"",style_family::Paragraph, true, false, -1);
impl_->styles_context_->create_style(L"", style_family::Paragraph, true, false, -1);
office_element_ptr & style_shape_elm = impl_->styles_context_->last_state()->get_office_element();
style_ = dynamic_cast<style*>(style_shape_elm.get());
@ -2168,10 +2178,37 @@ void odf_drawing_context::set_textarea_writing_mode(int mode)
impl_->current_paragraph_properties->content_.style_writing_mode_ = odf_types::writing_mode(odf_types::writing_mode::LrTb);
break;
}
}
void odf_drawing_context::set_paragraph_properties(style_paragraph_properties *paragraph_properties)
{
if (impl_->current_drawing_state_.elements_.empty()) return;
if (!impl_->current_paragraph_properties)
{
draw_base* draw = dynamic_cast<draw_base*>(impl_->current_drawing_state_.elements_[0].elm.get());
if (draw)
{
if(!draw->common_draw_attlists_.shape_with_text_and_styles_.common_shape_draw_attlist_.draw_text_style_name_)
{
impl_->styles_context_->create_style(L"", style_family::Paragraph, true, false, -1);
office_element_ptr & style_shape_elm = impl_->styles_context_->last_state()->get_office_element();
style* style_ = dynamic_cast<style*>(style_shape_elm.get());
if (style_)
{
impl_->current_paragraph_properties = style_->content_.get_style_paragraph_properties();
draw->common_draw_attlists_.shape_with_text_and_styles_.common_shape_draw_attlist_.draw_text_style_name_ = style_->style_name_;
}
}
else
{
//??? find by name
}
}
}
if (impl_->current_paragraph_properties)
impl_->current_paragraph_properties ->apply_from(paragraph_properties);
}
void odf_drawing_context::set_textarea_padding(_CP_OPT(double) & left, _CP_OPT(double) & top, _CP_OPT(double) & right, _CP_OPT(double) & bottom)//in pt
{
if (!impl_->current_graphic_properties)return;
@ -2200,7 +2237,7 @@ void odf_drawing_context::start_image(std::wstring odf_path)
return;
}
impl_->current_drawing_state_.oox_shape_preset = 3000;
impl_->current_drawing_state_.oox_shape_preset_ = 3000;
start_frame();
@ -2247,7 +2284,7 @@ void odf_drawing_context::start_object(std::wstring name)
void odf_drawing_context::start_text_box()
{
impl_->current_drawing_state_.oox_shape_preset = 2000;
impl_->current_drawing_state_.oox_shape_preset_ = 2000;
start_frame();
@ -2292,7 +2329,7 @@ void odf_drawing_context::set_text_box_tableframe(bool val)
{
if (impl_->current_drawing_state_.elements_.empty()) return;
impl_->current_drawing_state_.text_box_tableframe = val;
impl_->current_drawing_state_.text_box_tableframe_ = val;
}
void odf_drawing_context::set_text_box_parent_style(std::wstring style_name)
@ -2437,7 +2474,7 @@ void odf_drawing_context::set_text(odf_text_context* text_context)
}
if (impl_->current_drawing_state_.oox_shape_preset > 2000 && impl_->current_drawing_state_.oox_shape_preset < 3000)
if (impl_->current_drawing_state_.oox_shape_preset_ > 2000 && impl_->current_drawing_state_.oox_shape_preset_ < 3000)
{
//настройки цвета - перетащить в линии и заливки - так уж нужно wordart-у оо
style_text_properties *text_properties_ = text_context->get_text_properties();
@ -2947,7 +2984,7 @@ void odf_drawing_context::end_hatch_style()
void odf_drawing_context::start_bitmap_style()
{
if (!impl_->current_graphic_properties) return;
if (impl_->current_drawing_state_.oox_shape_preset == 3000) return;
if (impl_->current_drawing_state_.oox_shape_preset_ == 3000) return;
odf_writer::office_element_ptr fill_image_element;
@ -3043,7 +3080,7 @@ void odf_drawing_context::set_bitmap_link(std::wstring file_path)
std::wstring odf_ref_name ;
impl_->odf_context_->mediaitems()->add_or_find(file_path, _mediaitems::typeImage, odf_ref_name);
if (impl_->current_drawing_state_.oox_shape_preset == 3000)
if (impl_->current_drawing_state_.oox_shape_preset_ == 3000)
{
if (impl_->current_level_.size() < 1) return;

View File

@ -52,6 +52,7 @@ namespace odf_writer
class odf_conversion_context;
class odf_style_context;
class odf_text_context;
class style_paragraph_properties;
class odf_drawing_context
{
@ -124,16 +125,18 @@ public:
void start_frame ();
void end_frame ();
bool change_text_box_2_wordart();
void start_image (std::wstring file_path);
void end_image ();
bool change_text_box_2_wordart ();
bool is_wordart ();
void set_paragraph_properties (style_paragraph_properties *paragraph_properties);
void start_text_box ();
void set_text_box_min_size (bool val);
void set_text_box_min_size (double w_pt, double h_pt);
void set_text_box_parent_style (std::wstring style_name);
void set_text_box_tableframe (bool val);
void set_text_box_tableframe (bool val);
void end_text_box ();
void start_object(std::wstring name);

View File

@ -54,11 +54,12 @@ void odf_lists_styles_context::set_odf_context(odf_conversion_context * Context)
odf_context_ = Context;
}
void odf_lists_styles_context::process_styles(office_element_ptr root )
void odf_lists_styles_context::process_styles(office_element_ptr root, bool automatic)
{
for (size_t i = 0; i < lists_format_array_.size(); i++)
{
if (lists_format_array_[i].elements.size() < 1) continue;
if (lists_format_array_[i].elements.size() < 1) continue;
if (lists_format_array_[i].automatic != automatic) continue;
root->add_child_element(lists_format_array_[i].elements[0]);
}
@ -92,7 +93,13 @@ std::wstring odf_lists_styles_context::get_style_name1(int oox_style_num)
}
std::wstring odf_lists_styles_context::get_style_name(int oox_style_num)
{
if (link_format_map_.count(oox_style_num) > 0)
if (lists_format_array_.empty()) return L"";
if (oox_style_num < 0)
{
return lists_format_array_.back().odf_list_style_name;
}
else if (link_format_map_.count(oox_style_num) > 0)
{
return link_format_map_.at(oox_style_num);
}
@ -109,21 +116,30 @@ void odf_lists_styles_context::start_style(int based_number)
create_element(L"text", L"list-style", elm, odf_context_);
state.elements.push_back(elm);
state.oox_based_number = based_number;
state.odf_list_style_name = std::wstring(L"WWNum") + boost::lexical_cast<std::wstring>(based_number + 1);
if (based_number < 0)
{
state.oox_based_number = lists_format_array_.size();
state.odf_list_style_name = std::wstring(L"L") + boost::lexical_cast<std::wstring>(state.oox_based_number + 1);
state.automatic = true; //document automatic style
}
else
{
state.oox_based_number = based_number;
state.odf_list_style_name = std::wstring(L"WWNum") + boost::lexical_cast<std::wstring>(state.oox_based_number + 1);
state.automatic = false; //office style
}
text_list_style *style = dynamic_cast<text_list_style *>(elm.get());
if (style == NULL)return;
style->text_list_style_attr_.style_name_ = state.odf_list_style_name;
lists_format_array_.push_back(state); //перенести в end??
}
style_list_level_properties * odf_lists_styles_context::get_list_level_properties()
{
if (lists_format_array_.size() < 1) return NULL;
if (lists_format_array_.back().elements.size() <1) return NULL;
if (lists_format_array_.empty()) return NULL;
if (lists_format_array_.back().elements.empty()) return NULL;
text_list_level_style_number *style_number_ = dynamic_cast<text_list_level_style_number *>(lists_format_array_.back().elements.back().get());
text_list_level_style_bullet *style_bullet_ = dynamic_cast<text_list_level_style_bullet *>(lists_format_array_.back().elements.back().get());
@ -156,8 +172,8 @@ style_list_level_properties * odf_lists_styles_context::get_list_level_propertie
}
style_text_properties * odf_lists_styles_context::get_text_properties()
{
if (lists_format_array_.size() < 1) return NULL;
if (lists_format_array_.back().elements.size() <1) return NULL;
if (lists_format_array_.empty()) return NULL;
if (lists_format_array_.back().elements.empty()) return NULL;
text_list_level_style_number *style_number_ = dynamic_cast<text_list_level_style_number *>(lists_format_array_.back().elements.back().get());
text_list_level_style_bullet *style_bullet_ = dynamic_cast<text_list_level_style_bullet *>(lists_format_array_.back().elements.back().get());
@ -167,14 +183,14 @@ style_text_properties * odf_lists_styles_context::get_text_properties()
if (style_number_)
{
if (!style_number_->style_text_properties_)
create_element(L"style", L"text-properties",style_number_->style_text_properties_,odf_context_);
create_element(L"style", L"text-properties", style_number_->style_text_properties_, odf_context_);
props = dynamic_cast<style_text_properties *>(style_number_->style_text_properties_.get());
}
if (style_bullet_)
{
if (!style_bullet_->style_text_properties_)
create_element(L"style", L"text-properties",style_bullet_->style_text_properties_,odf_context_);
create_element(L"style", L"text-properties", style_bullet_->style_text_properties_, odf_context_);
props = dynamic_cast<style_text_properties *>(style_bullet_->style_text_properties_.get());
}
@ -190,8 +206,8 @@ style_text_properties * odf_lists_styles_context::get_text_properties()
style_list_level_label_alignment * odf_lists_styles_context::get_list_level_alignment_properties()
{
if (lists_format_array_.size() < 1) return NULL;
if (lists_format_array_.back().elements.size() <1) return NULL;
if (lists_format_array_.empty()) return NULL;
if (lists_format_array_.back().elements.empty()) return NULL;
text_list_level_style_number *style_number_ = dynamic_cast<text_list_level_style_number *>(lists_format_array_.back().elements.back().get());
text_list_level_style_bullet *style_bullet_ = dynamic_cast<text_list_level_style_bullet *>(lists_format_array_.back().elements.back().get());
@ -201,21 +217,21 @@ style_list_level_label_alignment * odf_lists_styles_context::get_list_level_alig
if (style_number_)
{
if (!style_number_->style_list_level_properties_)
create_element(L"style", L"list-level-properties",style_number_->style_list_level_properties_,odf_context_);
create_element(L"style", L"list-level-properties", style_number_->style_list_level_properties_, odf_context_);
props = dynamic_cast<style_list_level_properties *>(style_number_->style_list_level_properties_.get());
}
if (style_bullet_)
{
if (!style_bullet_->style_list_level_properties_)
create_element(L"style", L"list-level-properties",style_bullet_->style_list_level_properties_,odf_context_);
create_element(L"style", L"list-level-properties", style_bullet_->style_list_level_properties_, odf_context_);
props = dynamic_cast<style_list_level_properties *>(style_bullet_->style_list_level_properties_.get());
}
if (style_image_)
{
if (!style_image_->style_list_level_properties_)
create_element(L"style", L"list-level-properties",style_image_->style_list_level_properties_,odf_context_);
create_element(L"style", L"list-level-properties", style_image_->style_list_level_properties_, odf_context_);
props = dynamic_cast<style_list_level_properties *>(style_image_->style_list_level_properties_.get());
}
@ -223,14 +239,15 @@ style_list_level_label_alignment * odf_lists_styles_context::get_list_level_alig
if (!props->style_list_level_label_alignment_)
{
create_element(L"style", L"list-level-label-alignment" ,props->style_list_level_label_alignment_,odf_context_);
create_element(L"style", L"list-level-label-alignment" , props->style_list_level_label_alignment_, odf_context_);
}
return dynamic_cast<style_list_level_label_alignment *>(props->style_list_level_label_alignment_.get());
}
int odf_lists_styles_context::start_style_level(int level, int type)
{
if (lists_format_array_.size() < 1) return -1;
if (lists_format_array_.empty()) return -1;
int odf_type =1;
int format_type = -1;
@ -451,10 +468,10 @@ wchar_t convert_bullet_char(wchar_t c)
}
void odf_lists_styles_context::set_numeric_format(std::wstring val)
{
if (lists_format_array_.size() < 1) return;
if (lists_format_array_.back().elements.size() <1) return ;
if ( val.length() <1 )
return;
if ( lists_format_array_.empty() ) return;
if ( lists_format_array_.back().elements.empty() ) return;
if ( val.empty() ) return;
text_list_level_style_number *style_number_ = dynamic_cast<text_list_level_style_number *>(lists_format_array_.back().elements.back().get());
if (style_number_)
@ -522,10 +539,10 @@ void odf_lists_styles_context::set_numeric_format(std::wstring val)
}
void odf_lists_styles_context::set_bullet_char(std::wstring val)
{
if (lists_format_array_.size() < 1) return;
if (lists_format_array_.back().elements.size() <1) return ;
if ( val.length() <1 )
return;
if ( lists_format_array_.empty() ) return;
if ( lists_format_array_.back().elements.empty() ) return ;
if ( val.empty() ) return;
text_list_level_style_bullet *style_bullet_ = dynamic_cast<text_list_level_style_bullet *>(lists_format_array_.back().elements.back().get());
@ -536,8 +553,8 @@ void odf_lists_styles_context::set_bullet_char(std::wstring val)
void odf_lists_styles_context::set_bullet_image_size(double size)
{
if (size < 0.1) return;
if (lists_format_array_.size() < 1) return;
if (lists_format_array_.back().elements.size() <1) return ;
if (lists_format_array_.empty()) return;
if (lists_format_array_.back().elements.empty()) return ;
style_list_level_properties *props = get_list_level_properties();
@ -548,8 +565,8 @@ void odf_lists_styles_context::set_bullet_image_size(double size)
}
void odf_lists_styles_context::set_bullet_image (std::wstring ref)
{
if (lists_format_array_.size() < 1) return;
if (lists_format_array_.back().elements.size() <1) return ;
if (lists_format_array_.empty()) return;
if (lists_format_array_.back().elements.empty()) return ;
text_list_level_style_image *style_image_ = dynamic_cast<text_list_level_style_image *>(lists_format_array_.back().elements.back().get());
@ -563,8 +580,8 @@ void odf_lists_styles_context::set_bullet_image (std::wstring ref)
}
void odf_lists_styles_context::set_start_number(int val)
{
if (lists_format_array_.size() < 1) return;
if (lists_format_array_.back().elements.size() <1) return ;
if (lists_format_array_.empty()) return;
if (lists_format_array_.back().elements.empty()) return ;
text_list_level_style_number *style_number_ = dynamic_cast<text_list_level_style_number *>(lists_format_array_.back().elements.back().get());
@ -574,8 +591,8 @@ void odf_lists_styles_context::set_start_number(int val)
}
void odf_lists_styles_context::set_text_style_name(std::wstring name)
{
if (lists_format_array_.size() < 1) return;
if (lists_format_array_.back().elements.size() <1) return ;
if (lists_format_array_.empty()) return;
if (lists_format_array_.back().elements.empty()) return ;
text_list_level_style_number *style_number_ = dynamic_cast<text_list_level_style_number *>(lists_format_array_.back().elements.back().get());
text_list_level_style_bullet *style_bullet_ = dynamic_cast<text_list_level_style_bullet *>(lists_format_array_.back().elements.back().get());

View File

@ -55,7 +55,7 @@ struct list_format_state
std::vector<office_element_ptr> elements;
std::wstring odf_list_style_name;
bool automatic;
};
class odf_lists_styles_context
@ -64,7 +64,7 @@ public:
odf_lists_styles_context();
void set_odf_context(odf_conversion_context * Context);
void start_style(int abstract_number);
void start_style(int abstract_number = -1);
int start_style_level(int level, int type);
style_list_level_properties * get_list_level_properties();
style_list_level_label_alignment * get_list_level_alignment_properties();
@ -84,9 +84,9 @@ public:
void add_style(int oox_style_num, int oox_based_num);
void process_styles(office_element_ptr root );
void process_styles(office_element_ptr root, bool automatic);
std::wstring get_style_name(int oox_style_num);
std::wstring get_style_name(int oox_style_num = -1);
std::wstring get_style_name1(int oox_style_num);
private:
std::vector<list_format_state> lists_format_array_;

View File

@ -161,6 +161,7 @@ void odf_style_context::process_automatic_styles(office_element_ptr root )
if (/*it->automatic_== true && */style_state_list_[i]->root_== false && style_state_list_[i]->odf_style_)
root->add_child_element(style_state_list_[i]->odf_style_);
}
lists_styles_context_.process_styles(root, true);
}
void odf_style_context::process_office_styles(office_element_ptr root )
@ -175,7 +176,7 @@ void odf_style_context::process_office_styles(office_element_ptr root )
root->add_child_element(style_state_list_[i]->odf_style_);
}
lists_styles_context_.process_styles(root );
lists_styles_context_.process_styles(root, false);
}
std::wstring odf_style_context::find_odf_style_name(int oox_id_style, style_family::type family, bool root, bool automatic)
{

View File

@ -56,7 +56,26 @@ odp_conversion_context::odp_conversion_context(package::odf_document * outputDoc
: odf_conversion_context (PresentationDocument, outputDocument), slide_context_(*this), text_context_(NULL)
{
}
odf_text_context* odp_conversion_context::text_context()
{
return text_context_;
}
odp_slide_context* odp_conversion_context::slide_context()
{
return &slide_context_;
}
odf_drawing_context* odp_conversion_context::drawing_context()
{
if (slide_context_.page_state_list_.empty()) return NULL;
return slide_context_.state().drawing_context();
}
odf_comment_context* odp_conversion_context::comment_context()
{
if (slide_context_.page_state_list_.empty()) return NULL;
return slide_context_.state().comment_context();
}
void odp_conversion_context::start_document()
{

View File

@ -64,10 +64,10 @@ public:
virtual void start_text_context();
virtual void end_text_context();
virtual odf_drawing_context * drawing_context() {return current_slide().drawing_context();}
virtual odf_text_context * text_context() {return text_context_; }
odp_slide_context * slide_context() {return &slide_context_;}
odf_comment_context * comment_context() {return current_slide().comment_context();}
virtual odf_drawing_context * drawing_context();
virtual odf_text_context * text_context();
odp_slide_context * slide_context();
odf_comment_context * comment_context();
void start_drawings();
void end_drawings();

View File

@ -34,7 +34,6 @@
#include "../../../Common/DocxFormat/Source/DocxFormat/Diagram/DiagramDrawing.h"
#include "../../../Common/DocxFormat/Source/XlsxFormat/Chart/Chart.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Logic/SpTreeElem.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Logic/GraphicFrame.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Logic/Shape.h"
@ -46,6 +45,7 @@
#include "../../../ASCOfficePPTXFile/PPTXFormat/Logic/Colors/SrgbClr.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Logic/Colors/PrstClr.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Logic/Colors/SchemeClr.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Logic/TextFont.h"
#include "../../../Common/DocxFormat/Source/Common/SimpleTypes_Drawing.h"
#include "../../../Common/DocxFormat/Source/Common/SimpleTypes_Word.h"
@ -55,6 +55,7 @@
#include "../OdfFormat/odf_drawing_context.h"
#include "../OdfFormat/style_text_properties.h"
#include "../OdfFormat/style_paragraph_properties.h"
#include "../OdfFormat/styles_list.h"
using namespace cpdoccore;
@ -75,6 +76,22 @@ void OoxConverter::convert(PPTX::Logic::SpTreeElem *oox_element)
convert (elem.operator->());
}
void OoxConverter::convert_font(PPTX::Theme *theme, std::wstring & font)
{
if (font == L"+mj-lt")
font = theme ? theme->themeElements.fontScheme.majorFont.latin.typeface : L"";
else if (font == L"+mn-lt")
font = theme ? theme->themeElements.fontScheme.minorFont.latin.typeface : L"";
else if (font == L"+mj-ea")
font = theme ? theme->themeElements.fontScheme.majorFont.ea.typeface : L"";
else if (font == L"+mn-ea")
font = theme ? theme->themeElements.fontScheme.minorFont.ea.typeface : L"";
else if (font == L"+mj-cs")
font = theme ? theme->themeElements.fontScheme.majorFont.cs.typeface : L"";
else if (font == L"+mn-cs")
font = theme ? theme->themeElements.fontScheme.minorFont.cs.typeface : L"";
}
void OoxConverter::convert(PPTX::Logic::GraphicFrame *oox_graphic_frame)
{
if (!oox_graphic_frame)return;
@ -156,11 +173,42 @@ void OoxConverter::convert(PPTX::Logic::Pic *oox_picture)
{
if (!oox_picture)return;
odf_context()->drawing_context()->start_drawing();
bool bImage = true;
if (oox_picture->spPr.Geometry.is_init())
{
int type = SimpleTypes::shapetypeRect;
if ( oox_picture->spPr.Geometry.is<PPTX::Logic::CustGeom>() )
{
type = 1000;
}
else if ( oox_picture->spPr.Geometry.is<PPTX::Logic::PrstGeom>() )
{
const PPTX::Logic::PrstGeom& prstGeom = oox_picture->spPr.Geometry.as<PPTX::Logic::PrstGeom>();
SimpleTypes::CShapeType<> preset;
preset.FromString(prstGeom.prst.get());
type = preset.GetValue();
}
if (type != SimpleTypes::shapetypeRect)
{
odf_context()->drawing_context()->start_drawing();
odf_context()->drawing_context()->start_shape(type);
convert(&oox_picture->spPr, oox_picture->style.GetPointer());
convert(&oox_picture->nvPicPr);
odf_context()->drawing_context()->start_area_properties();
convert(&oox_picture->blipFill);
odf_context()->drawing_context()->end_area_properties();
odf_context()->drawing_context()->end_shape();
odf_context()->drawing_context()->end_drawing();
return;
}
}
std::wstring pathImage;
double Width=0, Height = 0;
if (oox_picture->blipFill.blip.IsInit())
{
std::wstring sID;
@ -174,10 +222,13 @@ void OoxConverter::convert(PPTX::Logic::Pic *oox_picture)
{
pathImage = oox_picture->blipFill.blip->link->get();
}
_graphics_utils_::GetResolution(pathImage.c_str(), Width, Height);
}
odf_context()->drawing_context()->start_drawing();
odf_context()->start_image(pathImage);
{
double Width = 0, Height = 0;
_graphics_utils_::GetResolution(pathImage.c_str(), Width, Height);
if (oox_picture->blipFill.tile.IsInit())
{
odf_context()->drawing_context()->set_image_style_repeat(2);
@ -196,24 +247,7 @@ void OoxConverter::convert(PPTX::Logic::Pic *oox_picture)
}
OoxConverter::convert(&oox_picture->nvPicPr.cNvPr);
//oox_picture->m_oNvPicPr.m_oCNvPicPr
//oox_picture->m_oNvPicPr.m_oCNvPicPr.m_oPicLocks
{
//if (oox_picture->m_oNvPicPr.m_oCNvPicPr.m_oPicLocks->m_oNoChangeAspect)
//{
//}
//if (oox_picture->m_oNvPicPr.m_oCNvPicPr.m_oPicLocks->m_oNoCrop))
//{
//}
//if (oox_picture->m_oNvPicPr.m_oCNvPicPr.m_oPicLocks->m_oNoResize)
//{
//}
}
//m_oExtLst
OoxConverter::convert(&oox_picture->spPr, NULL);
OoxConverter::convert(&oox_picture->spPr, oox_picture->style.GetPointer());
}
odf_context()->drawing_context()->end_image();
@ -401,7 +435,6 @@ void OoxConverter::convert(PPTX::Logic::Shape *oox_shape)
if (oox_shape->spPr.Geometry.is_init())
{
if ( oox_shape->spPr.Geometry.is<PPTX::Logic::PrstGeom>() )
{
const PPTX::Logic::PrstGeom& prstGeom = oox_shape->spPr.Geometry.as<PPTX::Logic::PrstGeom>();
@ -652,6 +685,9 @@ void OoxConverter::convert(PPTX::Logic::Path2D *oox_geom_path)
convert(pathBase);
}
if (oox_geom_path->stroke.IsInit() && *oox_geom_path->stroke == false)
odf_context()->drawing_context()->add_path_element(std::wstring(L"S"), L"");
odf_context()->drawing_context()->add_path_element(std::wstring(L"N"), L"");
}
@ -809,11 +845,11 @@ void OoxConverter::convert(PPTX::Logic::GradFill *oox_grad_fill, DWORD nARGB)
odf_context()->drawing_context()->set_opacity_start (*opacityStart);
odf_context()->drawing_context()->set_opacity_end (*opacityEnd);
if (grad_style == odf_types::gradient_style::linear)
if (oox_grad_fill->lin.is_init())
{
odf_context()->drawing_context()->set_opacity_angle(oox_grad_fill->lin->ang.get()/60000.);
}
else
else if (oox_grad_fill->path.is_init())
{
odf_context()->drawing_context()->set_opacity_rect ( XmlUtils::GetInteger(oox_grad_fill->path->rect->l.get_value_or(L"")),
XmlUtils::GetInteger(oox_grad_fill->path->rect->t.get_value_or(L"")),
@ -1071,6 +1107,138 @@ void OoxConverter::convert(PPTX::Logic::NvPr *oox_nvPr)
//nullable_limit<Limit::PlaceholderSize> sz;
}
}
void OoxConverter::convert_list_level(PPTX::Logic::TextParagraphPr *oox_para_props, int level)
{//одномерные списки тока
//if (!oox_list)return;
if (!oox_para_props) return;
PPTX::Theme *theme = oox_theme();
PPTX::Logic::Bullet & bullet = oox_para_props->ParagraphBullet;
if (bullet.is<PPTX::Logic::BuNone>())return;
if (bullet.is<PPTX::Logic::BuAutoNum>())
{
const PPTX::Logic::BuAutoNum & buAutoNum = bullet.as<PPTX::Logic::BuAutoNum>();
int type = 13;
int pptx_type = buAutoNum.type.GetBYTECode();
if ( pptx_type < 3) type = 46;
if (pptx_type > 2 && pptx_type < 6) type = 60;
if (pptx_type > 28 && pptx_type < 32) type = 47;
if (pptx_type > 31 && pptx_type < 35) type = 61;
odf_context()->styles_context()->lists_styles().start_style_level(level, type);
if (buAutoNum.startAt.IsInit())
{
int start_value = *buAutoNum.startAt;
if (start_value > 1)
odf_context()->styles_context()->lists_styles().set_start_number(start_value);
}
}
if (bullet.is<PPTX::Logic::BuChar>())
{
const PPTX::Logic::BuChar & buChar = bullet.as<PPTX::Logic::BuChar>();
odf_context()->styles_context()->lists_styles().start_style_level(level, 5 );
odf_context()->styles_context()->lists_styles().set_bullet_char(buChar.Char);
}
if (bullet.is<PPTX::Logic::BuBlip>())
{
const PPTX::Logic::BuBlip & buBlip = bullet.as<PPTX::Logic::BuBlip>();
odf_context()->styles_context()->lists_styles().start_style_level(level, 1000 );
odf_context()->styles_context()->lists_styles().set_bullet_image(odf_context()->mediaitems()->items().back().odf_ref);
}
//odf_writer::style_list_level_label_alignment * aligment_props = odf_context()->styles_context()->lists_styles().get_list_level_alignment_properties();
odf_writer::style_list_level_properties * level_props = odf_context()->styles_context()->lists_styles().get_list_level_properties();
odf_writer::style_text_properties * text_properties = odf_context()->styles_context()->lists_styles().get_text_properties();
convert(oox_para_props->defRPr.GetPointer(), text_properties);
if (oox_para_props->indent.IsInit())
{
level_props->text_space_before_ = odf_types::length(- oox_para_props->indent.get() / 12700., odf_types::length::pt);
level_props->text_min_label_width_ = odf_types::length(1, odf_types::length::pt);
}else
{
//aligment_props->fo_text_indent_ = odf_types::length(0, odf_types::length::cm);
//aligment_props->fo_margin_left_ = odf_types::length(0, odf_types::length::cm);
}
if (oox_para_props->buColor.is<PPTX::Logic::BuClrTx>())
{
const PPTX::Logic::BuClrTx & buClrTx = oox_para_props->buColor.as<PPTX::Logic::BuClrTx>();
}
if (oox_para_props->buColor.is<PPTX::Logic::BuClr>())
{
PPTX::Logic::BuClr & buClr = oox_para_props->buColor.as<PPTX::Logic::BuClr>();
std::wstring hexColor;
_CP_OPT(double) opacity;
convert(&buClr.Color, hexColor, opacity);
if (!hexColor.empty())
{
int res = 0;
if ((res = hexColor.find(L"#")) < 0) hexColor = std::wstring(L"#") + hexColor;
text_properties->content_.fo_color_ = odf_types::color(hexColor);
}
}
if (oox_para_props->buSize.is<PPTX::Logic::BuSzTx>())
{
const PPTX::Logic::BuSzTx & buSzTx = oox_para_props->buSize.as<PPTX::Logic::BuSzTx>();
}
else if (oox_para_props->buSize.is<PPTX::Logic::BuSzPct>())
{
const PPTX::Logic::BuSzPct & buSzPct = oox_para_props->buSize.as<PPTX::Logic::BuSzPct>();
if (buSzPct.val.IsInit())
text_properties->content_.fo_font_size_ = odf_types::percent(*buSzPct.val / 1000.);
}
else
text_properties->content_.fo_font_size_ = odf_types::percent(100.);
if (oox_para_props->buSize.is<PPTX::Logic::BuSzPts>())
{
const PPTX::Logic::BuSzPts & buSzPts = oox_para_props->buSize.as<PPTX::Logic::BuSzPts>();
if (buSzPts.val.IsInit())
text_properties->content_.fo_font_size_ = odf_types::length(*buSzPts.val, odf_types::length::pt);
}
else if (oox_para_props->buTypeface.is<PPTX::Logic::BuFontTx>())
{
const PPTX::Logic::BuFontTx & buFontTx = oox_para_props->buTypeface.as<PPTX::Logic::BuFontTx>();
}
if (oox_para_props->buTypeface.is<PPTX::Logic::TextFont>())
{
const PPTX::Logic::TextFont & textFont = oox_para_props->buTypeface.as<PPTX::Logic::TextFont>();
std::wstring font = textFont.typeface;
convert_font(theme, font);
if (!font.empty()) text_properties->content_.fo_font_family_ = font;
}
odf_context()->styles_context()->lists_styles().end_style_level();
}
void OoxConverter::convert_list (PPTX::Logic::TextListStyle *oox_list_style)
{
if (!oox_list_style) return;
odf_context()->styles_context()->lists_styles().start_style();
for (int i = 0; i < 9; i++)
{
convert_list_level(oox_list_style->levels[0].GetPointer(), i);
}
odf_context()->styles_context()->lists_styles().end_style();
}
void OoxConverter::convert(PPTX::Logic::Paragraph *oox_paragraph, PPTX::Logic::TextListStyle *oox_list_style)
{
if (!oox_paragraph)return;
@ -1081,53 +1249,76 @@ void OoxConverter::convert(PPTX::Logic::Paragraph *oox_paragraph, PPTX::Logic::T
std::wstring list_style_name;
int list_level = 0;
NSCommon::nullable<PPTX::Logic::TextParagraphPr> paraPr;
if (oox_paragraph->pPr.IsInit() || oox_list_style)
if (oox_paragraph->pPr.IsInit() && oox_paragraph->pPr->lvl.IsInit())
{
if (oox_paragraph->pPr.IsInit() && (oox_paragraph->pPr->lvl.IsInit() || oox_paragraph->pPr->ParagraphBullet.is_init()))
{
list_present = true;
list_level = 1;
if (oox_paragraph->pPr->lvl.IsInit())
list_level = *oox_paragraph->pPr->lvl;
}
list_level = *oox_paragraph->pPr->lvl;
}
if (oox_list_style && list_level >= 0 && list_level < 10)
{
if (oox_list_style->levels[list_level].IsInit())
oox_list_style->levels[list_level]->Merge(paraPr);
}
if (oox_paragraph->pPr.IsInit())
oox_paragraph->pPr->Merge(paraPr);
odf_writer::style_paragraph_properties * paragraph_properties = odf_context()->text_context()->get_paragraph_properties();
//свойства могут быть приписаны не только к параграфу, но и к самому объекту
if (paraPr.IsInit())
{
list_level = paraPr->lvl.IsInit() ? *paraPr->lvl : 0;
if (list_level > 0) list_present = true;
if (paraPr->ParagraphBullet.is_init())
{
list_present = true;
if (paraPr->ParagraphBullet.is<PPTX::Logic::BuNone>())
list_present = false;
else if (list_level == 0) list_level = 1;
}
//свойства могут быть приписаны не только к параграфу, но и к самому объекту
odf_writer::style_paragraph_properties* paragraph_properties = odf_context()->text_context()->get_paragraph_properties();
odf_writer::style_text_properties* text_properties = NULL;
if (!paragraph_properties)
{
odf_context()->text_context()->get_styles_context()->create_style(L"", odf_types::style_family::Paragraph, true, false, -1);
paragraph_properties = odf_context()->text_context()->get_styles_context()->last_state()->get_paragraph_properties();
paragraph_properties = odf_context()->text_context()->get_styles_context()->last_state()->get_paragraph_properties();
text_properties = odf_context()->text_context()->get_styles_context()->last_state()->get_text_properties();
//if(list_present && oox_list_style)
//{
// list_style_name = odf_context->styles_context()->lists_styles().get_style_name(list_style_id);
// odf_context->styles_context()->last_state()->set_list_style_name(list_style_name);
//}
styled = true;
}
convert(oox_list_style, list_level, paragraph_properties);
convert(oox_paragraph->pPr.GetPointer(), paragraph_properties);
}
convert(paraPr.GetPointer(), paragraph_properties, text_properties);
if (odf_context()->drawing_context()->is_wordart())
odf_context()->drawing_context()->set_paragraph_properties(paragraph_properties);
}
if (oox_paragraph->RunElems.empty() && list_present) list_present = false; // ms не обозначает присутствие списка, libra - показывает значек
while (odf_context()->text_context()->list_state_.levels.size() > list_level)
{
odf_context()->text_context()->end_list();
}
if(list_present)
{
while (odf_context()->text_context()->list_state_.levels.size() > list_level)
{
odf_context()->text_context()->end_list();
}
if (odf_context()->text_context()->list_state_.levels.size() < 1)
if (odf_context()->text_context()->list_state_.levels.empty())
{
odf_context()->text_context()->list_state_.started_list = false;
odf_context()->text_context()->list_state_.style_name = L"";
odf_context()->text_context()->list_state_.style_name = L"";
}
if (odf_context()->text_context()->list_state_.started_list == false)
{
odf_context()->styles_context()->lists_styles().start_style();
convert_list_level(paraPr.GetPointer(), list_level - 1);
odf_context()->styles_context()->lists_styles().end_style();
list_style_name = odf_context()->styles_context()->lists_styles().get_style_name();
odf_context()->text_context()->start_list(list_style_name);
//text_context()->set_list_continue(true); //??? держать в памяти все списки????
}
odf_context()->text_context()->start_list_item();
@ -1139,10 +1330,14 @@ void OoxConverter::convert(PPTX::Logic::Paragraph *oox_paragraph, PPTX::Logic::T
odf_context()->text_context()->start_list(list_style_name);
odf_context()->text_context()->start_list_item();
}
}
}
else if (odf_context()->text_context()->list_state_.started_list == true)
{
odf_context()->text_context()->end_list();
}
odf_context()->text_context()->start_paragraph(styled);
for (size_t i=0; i< oox_paragraph->RunElems.size();i++)
for (size_t i=0; i< oox_paragraph->RunElems.size(); i++)
{
convert(&oox_paragraph->RunElems[i].as<OOX::WritingElement>());
}
@ -1153,77 +1348,79 @@ void OoxConverter::convert(PPTX::Logic::Paragraph *oox_paragraph, PPTX::Logic::T
odf_context()->text_context()->end_list_item();
}
}
void OoxConverter::convert(PPTX::Logic::TextListStyle *oox_list_style, int level, odf_writer::style_paragraph_properties * paragraph_properties)
void OoxConverter::convert(PPTX::Logic::TextListStyle *oox_list_style, int level, odf_writer::style_paragraph_properties * paragraph_properties
, odf_writer::style_text_properties * text_properties)
{
if (!oox_list_style) return;
if (!paragraph_properties) return;
convert(oox_list_style->levels[9].GetPointer(), paragraph_properties);
convert(oox_list_style->levels[9].GetPointer(), paragraph_properties, text_properties);
if (level < 0 || level > 9) return;
convert(oox_list_style->levels[level].GetPointer(), paragraph_properties);
convert(oox_list_style->levels[level].GetPointer(), paragraph_properties, text_properties);
}
void OoxConverter::convert(PPTX::Logic::TextParagraphPr *oox_paragraph_pr, odf_writer::style_paragraph_properties * paragraph_properties)
void OoxConverter::convert(PPTX::Logic::TextParagraphPr *oox_paragraph_pr , odf_writer::style_paragraph_properties * paragraph_properties
, odf_writer::style_text_properties * text_properties)
{
if (!oox_paragraph_pr) return;
if (!paragraph_properties) return;
if (oox_paragraph_pr->lnSpc.IsInit())
if (!oox_paragraph_pr) return;
if (paragraph_properties)
{
odf_types::length_or_percent length;
convert(oox_paragraph_pr->lnSpc.GetPointer(), length);
paragraph_properties->content_.fo_line_height_ = odf_types::line_width(length);
}
if (oox_paragraph_pr->spcAft.IsInit())
{
odf_types::length_or_percent length;
convert(oox_paragraph_pr->spcAft.GetPointer(), length);
paragraph_properties->content_.fo_margin_bottom_ = length;
}
if (oox_paragraph_pr->spcBef.IsInit())
{
odf_types::length_or_percent length;
convert(oox_paragraph_pr->spcBef.GetPointer(), length);
paragraph_properties->content_.fo_margin_top_ = length;
}
if (oox_paragraph_pr->algn.IsInit())
{
switch(oox_paragraph_pr->algn->GetBYTECode())
if (oox_paragraph_pr->lnSpc.IsInit())
{
case 0 : paragraph_properties->content_.fo_text_align_ = odf_types::text_align(odf_types::text_align::Center); break;
case 1 :
case 2 :
case 3 : paragraph_properties->content_.fo_text_align_ = odf_types::text_align(odf_types::text_align::Justify); break;
case 5 : paragraph_properties->content_.fo_text_align_ = odf_types::text_align(odf_types::text_align::Right); break;
case 4 :
default:
paragraph_properties->content_.fo_text_align_ = odf_types::text_align(odf_types::text_align::Left); break;
odf_types::length_or_percent length;
convert(oox_paragraph_pr->lnSpc.GetPointer(), length);
paragraph_properties->content_.fo_line_height_ = odf_types::line_width(length);
}
if (oox_paragraph_pr->spcAft.IsInit())
{
odf_types::length_or_percent length;
convert(oox_paragraph_pr->spcAft.GetPointer(), length);
paragraph_properties->content_.fo_margin_bottom_ = length;
}
if (oox_paragraph_pr->spcBef.IsInit())
{
odf_types::length_or_percent length;
convert(oox_paragraph_pr->spcBef.GetPointer(), length);
paragraph_properties->content_.fo_margin_top_ = length;
}
if (oox_paragraph_pr->algn.IsInit())
{
switch(oox_paragraph_pr->algn->GetBYTECode())
{
case 0 : paragraph_properties->content_.fo_text_align_ = odf_types::text_align(odf_types::text_align::Center); break;
case 1 :
case 2 :
case 3 : paragraph_properties->content_.fo_text_align_ = odf_types::text_align(odf_types::text_align::Justify); break;
case 5 : paragraph_properties->content_.fo_text_align_ = odf_types::text_align(odf_types::text_align::Right); break;
case 4 :
default:
paragraph_properties->content_.fo_text_align_ = odf_types::text_align(odf_types::text_align::Left); break;
}
}
if (oox_paragraph_pr->marL.IsInit())
{
paragraph_properties->content_.fo_margin_left_ = odf_types::length_or_percent(odf_types::length(oox_paragraph_pr->marL.get() / 12700., odf_types::length::pt));
}
if (oox_paragraph_pr->marR.IsInit())
{
paragraph_properties->content_.fo_margin_right_ = odf_types::length_or_percent(odf_types::length(oox_paragraph_pr->marR.get() / 12700., odf_types::length::pt));
}
if (oox_paragraph_pr->indent.IsInit())
{
paragraph_properties->content_.fo_text_indent_ = odf_types::length_or_percent(odf_types::length(oox_paragraph_pr->indent.get() / 12700., odf_types::length::pt));
}
if (oox_paragraph_pr->rtl.IsInit())
{
}
}
if (oox_paragraph_pr->marL.IsInit())
{
paragraph_properties->content_.fo_margin_left_ = odf_types::length_or_percent(odf_types::length(oox_paragraph_pr->marL.get() / 12700., odf_types::length::pt));
}
if (oox_paragraph_pr->marR.IsInit())
{
paragraph_properties->content_.fo_margin_right_ = odf_types::length_or_percent(odf_types::length(oox_paragraph_pr->marR.get() / 12700., odf_types::length::pt));
}
if (oox_paragraph_pr->indent.IsInit())
{
paragraph_properties->content_.fo_text_indent_ = odf_types::length_or_percent(odf_types::length(oox_paragraph_pr->indent.get() / 12700., odf_types::length::pt));
}
if (oox_paragraph_pr->rtl.IsInit())
{
}
//nullable<SimpleTypes::CDecimalNumber<> > m_oLvl;
//nullable<SimpleTypes::CCoordinate32<> > m_oDefTabSz;
//nullable<SimpleTypes::CTextFontAlignType<>> m_oFontAlgn;
if (oox_paragraph_pr->defRPr.IsInit())
{
odf_writer::style_text_properties * text_properties = odf_context()->text_context()->get_styles_context()->last_state()->get_text_properties();
if (text_properties)
convert(oox_paragraph_pr->defRPr.GetPointer(), text_properties);
convert(oox_paragraph_pr->defRPr.GetPointer(), text_properties);
//надо подумать как брать последний по family !!!
//convert(oox_paragraph_pr->m_oDefRunProperty.GetPointer());
@ -1242,7 +1439,7 @@ void OoxConverter::convert(PPTX::Logic::TextSpacing *oox_spacing, cpdoccore::odf
}
if ( oox_spacing->spcPts.IsInit() )
{
odf_types::length length = odf_types::length(oox_spacing->GetVal() / 12700., odf_types::length::pt);
odf_types::length length = odf_types::length(-oox_spacing->GetVal() / 100., odf_types::length::pt);
length_or_percent = odf_types::length_or_percent(length);
}
}
@ -1254,43 +1451,59 @@ void OoxConverter::convert(PPTX::Logic::RunProperties *oox_run_pr, odf_writer::s
PPTX::Theme *theme = oox_theme();
PPTX::Logic::GradFill* gradFill = &oox_run_pr->Fill.as<PPTX::Logic::GradFill>();
if (gradFill)
{
if (odf_context()->drawing_context()->change_text_box_2_wordart())
//------------------------------------------------------
odf_writer::odf_drawing_context *drawing = odf_context()->drawing_context();
if (drawing) //from styles impossible(
{
if ((oox_run_pr->Fill.is<PPTX::Logic::GradFill>()) ||
((oox_run_pr->ln.IsInit()) && (oox_run_pr->ln->Fill.is_init() && oox_run_pr->ln->Fill.getType() != OOX::et_a_noFill)))
{
odf_context()->drawing_context()->start_area_properties();
{
convert(gradFill);
}
odf_context()->drawing_context()->end_area_properties();
drawing->change_text_box_2_wordart();
}
if (drawing->is_wordart())
{
if (oox_run_pr->Fill.is_init())
{
drawing->start_area_properties();
convert(&oox_run_pr->Fill);
drawing->end_area_properties();
}
if (oox_run_pr->ln.is_init())
{
drawing->start_line_properties();
if (oox_run_pr->ln->Fill.is_init() && oox_run_pr->ln->Fill.getType() != OOX::et_a_noFill )
{
drawing->set_line_dash_preset(6);
convert(oox_run_pr->ln.GetPointer());
}
else if (drawing->is_wordart())
drawing->set_no_fill();
drawing->end_line_properties();
}
}
}
//---------------------------------------
_CP_OPT(double) opacityText;
std::wstring hexColorText;
PPTX::Logic::GradFill* gradFill = &oox_run_pr->Fill.as<PPTX::Logic::GradFill>();
if (gradFill && !gradFill->GsLst.empty())
{
convert(&gradFill->GsLst[0].color, hexColorText, opacityText);
}
PPTX::Logic::SolidFill* solidFill = &oox_run_pr->Fill.as<PPTX::Logic::SolidFill>();
if (solidFill)
{
std::wstring hexColor;
_CP_OPT(double) opacity;
convert(&solidFill->Color, hexColor, opacity);
convert(&solidFill->Color, hexColorText, opacityText);
}
if (!hexColorText.empty())
{
int res = 0;
if ((res = hexColor.find(L"#")) < 0) hexColor = std::wstring(L"#") + hexColor;
text_properties->content_.fo_color_ = odf_types::color(hexColor);
if ((res = hexColorText.find(L"#")) < 0) hexColorText = std::wstring(L"#") + hexColorText;
text_properties->content_.fo_color_ = odf_types::color(hexColorText);
}
if (oox_run_pr->ln.IsInit() && oox_run_pr->ln->Fill.getType() != OOX::et_a_noFill)
{
if (odf_context()->drawing_context()->change_text_box_2_wordart())
{
odf_context()->drawing_context()->start_line_properties();
{
odf_context()->drawing_context()->set_line_dash_preset(6);
convert(oox_run_pr->ln.GetPointer());
}
odf_context()->drawing_context()->end_line_properties();
}
}
//---------------------------------------
if (oox_run_pr->b.IsInit())
{
if (oox_run_pr->b.get() == true)
@ -1317,12 +1530,8 @@ void OoxConverter::convert(PPTX::Logic::RunProperties *oox_run_pr, odf_writer::s
if (!oox_run_pr->latin->typeface.empty())
{
std::wstring font = oox_run_pr->latin->typeface;
if (font == L"+mj-lt")
font = theme->themeElements.fontScheme.majorFont.latin.typeface;
else if (font == L"+mn-lt")
font = theme->themeElements.fontScheme.minorFont.latin.typeface;
convert_font(theme, font);
if (!font.empty())
text_properties->content_.fo_font_family_ = font;
}
@ -1336,11 +1545,7 @@ void OoxConverter::convert(PPTX::Logic::RunProperties *oox_run_pr, odf_writer::s
if (!oox_run_pr->ea->typeface.empty())
{
std::wstring font = oox_run_pr->ea->typeface;
if (font == L"+mj-ea")
font = theme->themeElements.fontScheme.majorFont.ea.typeface;
else if (font == L"+mn-ea")
font = theme->themeElements.fontScheme.minorFont.ea.typeface;
convert_font(theme, font);
if (!font.empty())
text_properties->content_.style_font_family_asian_ = font;
@ -1354,11 +1559,7 @@ void OoxConverter::convert(PPTX::Logic::RunProperties *oox_run_pr, odf_writer::s
if (!oox_run_pr->cs->typeface.empty())
{
std::wstring font = oox_run_pr->cs->typeface;
if (font == L"+mj-cs")
font = theme->themeElements.fontScheme.majorFont.cs.typeface;
else if (font == L"+mn-cs")
font = theme->themeElements.fontScheme.minorFont.cs.typeface;
convert_font(theme, font);
if (!font.empty())
text_properties->content_.style_font_family_complex_ = font;
@ -1373,12 +1574,12 @@ void OoxConverter::convert(PPTX::Logic::RunProperties *oox_run_pr, odf_writer::s
int res = oox_language.find(L"-");
if (res >= 0)
{
oox_country = oox_language.substr(res);
oox_country = oox_language.substr(res + 1);
oox_language = oox_language.substr(0, res);
}
text_properties->content_.fo_language_ = oox_language;
if (oox_country.length() > 0)
if (!oox_country.empty())
text_properties->content_.fo_country_ = oox_country;
}
@ -1442,7 +1643,7 @@ void OoxConverter::convert(PPTX::Logic::Run *oox_run)
odf_context()->text_context()->start_span(styled);
if ((oox_run->rPr->hlinkClick.IsInit()) && (oox_run->rPr->hlinkClick->id.IsInit()))
if ((oox_run->rPr.IsInit()) && (oox_run->rPr->hlinkClick.IsInit()) && (oox_run->rPr->hlinkClick->id.IsInit()))
{
std::wstring hlink = find_link_by_id(oox_run->rPr->hlinkClick->id.get(), 2);
odf_context()->text_context()->add_hyperlink(hlink, oox_run->GetText());
@ -1490,8 +1691,6 @@ void OoxConverter::convert(PPTX::Logic::TxBody *oox_txBody, PPTX::Logic::ShapeSt
if (oox_txBody->Paragrs.empty()) return;
odf_context()->start_text_context();
for (size_t i = 0; i < oox_txBody->Paragrs.size(); i++)
{

View File

@ -263,6 +263,7 @@ namespace PPTX
class Theme;
namespace Logic
{
class Bullet;
class ClrMap;
class SpTreeElem;
class GraphicFrame;
@ -364,6 +365,7 @@ public:
void convert (double oox_font_size, _CP_OPT(cpdoccore::odf_types::font_size) & odf_font_size);
bool convert (std::wstring sSchemeColor, DWORD & argb);
void convert_font(PPTX::Theme *theme, std::wstring & font);
//.......................................................................................................................
void convert(OOX::WritingElement *oox_unknown);
//drawingML & pptx................................................................................................................................
@ -402,10 +404,16 @@ public:
void convert(PPTX::Logic::NvCxnSpPr *oox_nvSpPr);
void convert(PPTX::Logic::NvGrpSpPr *oox_nvSpPr);
void convert(PPTX::Logic::NvPr *oox_nvPr);
void convert(PPTX::Logic::Paragraph *oox_para, PPTX::Logic::TextListStyle *oox_list_style = NULL);
void convert(PPTX::Logic::TextListStyle *oox_list_style, int level, cpdoccore::odf_writer::style_paragraph_properties * paragraph_properties);
void convert(PPTX::Logic::TextParagraphPr *oox_para_props, cpdoccore::odf_writer::style_paragraph_properties * paragraph_properties);
void convert(PPTX::Logic::RunProperties *oox_run_props, cpdoccore::odf_writer::style_text_properties * text_properties);
void convert(PPTX::Logic::Paragraph *oox_para, PPTX::Logic::TextListStyle *oox_list_style = NULL);
void convert_list_level (PPTX::Logic::TextParagraphPr *oox_para_props, int level);
void convert_list (PPTX::Logic::TextListStyle *oox_list_style);
void convert(PPTX::Logic::TextListStyle *oox_list_style, int level, cpdoccore::odf_writer::style_paragraph_properties *paragraph_properties,
cpdoccore::odf_writer::style_text_properties *text_properties);
void convert(PPTX::Logic::TextParagraphPr *oox_para_props, cpdoccore::odf_writer::style_paragraph_properties *paragraph_properties,
cpdoccore::odf_writer::style_text_properties *text_properties);
void convert(PPTX::Logic::RunProperties *oox_run_props, cpdoccore::odf_writer::style_text_properties *text_properties);
void convert(PPTX::Logic::Run *oox_run);
void convert(PPTX::Logic::Fld *oox_fld);
void convert(PPTX::Logic::Br *oox_br);

View File

@ -3049,7 +3049,7 @@ void DocxConverter::convert(OOX::Numbering::CLvl* oox_num_lvl)
int type_list = odt_context->styles_context()->lists_styles().start_style_level(oox_num_lvl->m_oIlvl->GetValue(), oox_type_list );
if (type_list < 0) return;
odf_writer::style_list_level_properties * level_props = odt_context->styles_context()->lists_styles().get_list_level_properties();
odf_writer::style_list_level_properties * level_props = odt_context->styles_context()->lists_styles().get_list_level_properties();
odf_writer::style_list_level_label_alignment * aligment_props = odt_context->styles_context()->lists_styles().get_list_level_alignment_properties();
if (level_props == NULL)return;
@ -3101,8 +3101,8 @@ void DocxConverter::convert(OOX::Numbering::CLvl* oox_num_lvl)
}
}else
{
aligment_props->fo_text_indent_ = odf_types::length(0,odf_types::length::cm);
aligment_props->fo_margin_left_ = odf_types::length(0,odf_types::length::cm);
aligment_props->fo_text_indent_ = odf_types::length(0, odf_types::length::cm);
aligment_props->fo_margin_left_ = odf_types::length(0, odf_types::length::cm);
}
}
@ -3114,7 +3114,7 @@ void DocxConverter::convert(OOX::Numbering::CLvl* oox_num_lvl)
convert(oox_num_lvl->m_oRPr.GetPointer(), text_props);
//create text style for symbols list НА ЛОКАЛЬНОМ контексте - иначе пересечение имен стилей (todoo вытащить генерацию имен в общую часть)
styles_context->create_style(L"",odf_types::style_family::Text, false, true, -1);
styles_context->create_style(L"", odf_types::style_family::Text, false, true, -1);
odf_writer::odf_style_state_ptr style_state = styles_context->last_state(odf_types::style_family::Text);
if (style_state)
{

View File

@ -219,21 +219,20 @@ void PptxConverter::convert_styles()
odf_writer::style_paragraph_properties * paragraph_properties = odp_context->styles_context()->last_state()->get_paragraph_properties();
odf_writer::style_text_properties * text_properties = odp_context->styles_context()->last_state()->get_text_properties();
if (text_properties)
if (presentation->defaultTextStyle.IsInit())
{
text_properties->content_.fo_font_size_ = odf_types::font_size(odf_types::length(18, odf_types::length::pt));
}
if (slide->theme.IsInit() && text_properties)
{
if (slide->theme->themeElements.fontScheme.majorFont.latin.typeface.empty() == false)
text_properties->content_.fo_font_family_ = slide->theme->themeElements.fontScheme.majorFont.latin.typeface;
if (slide->theme->themeElements.fontScheme.majorFont.cs.typeface.empty() == false)
text_properties->content_.style_font_family_complex_ = slide->theme->themeElements.fontScheme.majorFont.cs.typeface;
OoxConverter::convert(presentation->defaultTextStyle->levels[9].GetPointer(), paragraph_properties, text_properties); //defPPr
OoxConverter::convert(presentation->defaultTextStyle->levels[0].GetPointer(), paragraph_properties, text_properties); //default text
if (slide->theme->themeElements.fontScheme.majorFont.ea.typeface.empty() == false)
text_properties->content_.style_font_family_asian_ = slide->theme->themeElements.fontScheme.majorFont.ea.typeface;
odp_context->styles_context()->create_default_style(odf_types::style_family::Paragraph);
paragraph_properties = odp_context->styles_context()->last_state()->get_paragraph_properties();
OoxConverter::convert(presentation->defaultTextStyle->levels[0].GetPointer(), paragraph_properties, text_properties); //default text
odp_context->styles_context()->create_default_style(odf_types::style_family::Text);
text_properties = odp_context->styles_context()->last_state()->get_text_properties();
OoxConverter::convert(presentation->defaultTextStyle->levels[0].GetPointer(), paragraph_properties, text_properties); //default text
}
//convert(presentation->defaultTextStyle.GetPointer()); //стили дефалтовых списков
@ -295,23 +294,34 @@ void PptxConverter::convert_slides()
{
continue;// странное ... слайд 38 в FY10_September_Partner_Call.pptx
}
current_theme = slide->theme.operator->();
current_clrMap = NULL;
std::wstring master_style_name;
std::wstring layout_style_name;
bool bShow = slide->show.get_value_or(true);
bool bShowMasterAnim = slide->showMasterPhAnim.get_value_or(true);
bool bShowMasterSp = slide->showMasterSp.get_value_or(true);
PPTX::Logic::TxStyles* current_txStyles = NULL;
if (slide->Master.IsInit())
{
current_clrMap = &slide->Master->clrMap;
current_clrMap = &slide->Master->clrMap;
current_txStyles = slide->Master->txStyles.GetPointer();
std::map<std::wstring, std::wstring>::iterator pFind = m_mapMasters.find(slide->Master->m_sOutputFilename + slide->Layout->m_sOutputFilename);
std::wstring master_name = (bShowMasterSp ? slide->Master->m_sOutputFilename : L"") + slide->Layout->m_sOutputFilename;
std::map<std::wstring, std::wstring>::iterator pFind = m_mapMasters.find(master_name);
if (pFind == m_mapMasters.end())
{
master_style_name = L"MasterPage";
if (slide->Master->cSld.attrName.IsInit()) master_style_name = slide->Master->cSld.attrName.get();
else if (current_theme->name.IsInit()) master_style_name = current_theme->name.get();
if (bShowMasterSp)
{
if (slide->Master->cSld.attrName.IsInit()) master_style_name = slide->Master->cSld.attrName.get();
else if (current_theme->name.IsInit()) master_style_name = current_theme->name.get();
}
master_style_name += L"_" ;
if (slide->Layout->cSld.attrName.IsInit()) master_style_name += slide->Layout->cSld.attrName.get();
else if (slide->Layout->attrType.IsInit()) master_style_name += slide->Layout->attrType->get();
@ -320,18 +330,20 @@ void PptxConverter::convert_slides()
odp_context->start_master_slide(master_style_name);
convert_common();
//if (slide->Layout->showMasterSp.IsInit() ? *slide->Layout->showMasterSp : true)
{
current_slide = slide->Master.operator->();
convert_slide(&slide->Master->cSld, false);
}
current_slide = slide->Master.operator->();
if (bShowMasterSp)
convert_slide(&slide->Master->cSld, current_txStyles, false);
else
convert(slide->Master->cSld.bg.GetPointer());
if (slide->Layout->clrMapOvr.IsInit() && slide->Layout->clrMapOvr->overrideClrMapping.IsInit())
current_clrMap = slide->Layout->clrMapOvr->overrideClrMapping.GetPointer();
current_slide = slide->Layout.operator->();
convert_slide(&slide->Layout->cSld, true);
convert_slide(&slide->Layout->cSld, current_txStyles, true);
odp_context->end_master_slide();
m_mapMasters.insert(std::make_pair(slide->Master->m_sOutputFilename + slide->Layout->m_sOutputFilename, master_style_name));
m_mapMasters.insert(std::make_pair(master_name, master_style_name));
}
else
{
@ -366,16 +378,12 @@ void PptxConverter::convert_slides()
odp_context->current_slide().set_master_page (master_style_name);
odp_context->current_slide().set_layout_page (layout_style_name);
//nullable_bool show;
//nullable_bool showMasterPhAnim;
//nullable_bool showMasterSp;
convert_slide (slide->cSld.GetPointer(), true);
convert_slide (slide->cSld.GetPointer(), current_txStyles, true);
convert (slide->comments.operator->());
convert (slide->Note.operator->());
convert (slide->transition.GetPointer());
convert (slide->timing.GetPointer());
convert (slide->timing.GetPointer(), slide->transition.GetPointer());
odp_context->end_slide();
@ -433,13 +441,7 @@ void PptxConverter::convert(PPTX::Comments *oox_comments)
odp_context->end_comment();
}
}
void PptxConverter::convert(PPTX::Logic::Transition *oox_transition)
{
if (!oox_transition) return;
}
void PptxConverter::convert(PPTX::Logic::Timing *oox_timing)
void PptxConverter::convert(PPTX::Logic::Timing *oox_timing, PPTX::Logic::Transition *oox_transition)
{
if (!oox_timing) return;
if (!oox_timing->tnLst.IsInit()) return;
@ -933,14 +935,13 @@ void PptxConverter::convert(PPTX::Logic::Bg *oox_background)
odp_context->end_drawings();
}
void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, bool bPlaceholders)
void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxStyles* txStyles, bool bPlaceholders)
{
if (oox_slide == NULL) return;
if (current_theme && current_clrMap)
current_theme->SetColorMap(*current_clrMap);
if (oox_slide->attrName.IsInit())
odp_context->current_slide().set_page_name(oox_slide->attrName.get());
@ -951,15 +952,50 @@ void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, bool bPlaceholde
smart_ptr<PPTX::WrapperWritingElement> pElem = oox_slide->spTree.SpTreeElems[i].GetElem();
smart_ptr<PPTX::Logic::Shape> pShape = pElem.smart_dynamic_cast<PPTX::Logic::Shape>();
if (pShape.IsInit())
if (pShape.IsInit() && pShape->nvSpPr.nvPr.ph.is_init())
{
pShape->FillLevelUp();
if (!bPlaceholders && pShape->nvSpPr.nvPr.ph.is_init())
if (!bPlaceholders)
continue;
PPTX::Logic::TextListStyle * listMasterStyle = NULL;
if (txStyles)
{
std::wstring type = pShape->nvSpPr.nvPr.ph->type.get_value_or(_T("body"));
if ((type == L"title") || (type == L"ctrTitle"))
listMasterStyle = txStyles->titleStyle.GetPointer();
else if ((type == L"body") || (type == L"subTitle") || (type == L"obj"))
listMasterStyle = txStyles->bodyStyle.GetPointer();
else if (type != L"")
listMasterStyle = txStyles->otherStyle.GetPointer();
}
PPTX::Logic::Shape update_shape;
if (listMasterStyle)
{
update_shape.txBody = new PPTX::Logic::TxBody();
PPTX::Logic::TextListStyle *newListStyle = new PPTX::Logic::TextListStyle();
for (int i = 0; i < 10; i++)
{
if(listMasterStyle->levels[i].is_init())
listMasterStyle->levels[i]->Merge(newListStyle->levels[i]);
}
update_shape.txBody->lstStyle.reset(newListStyle);
}
pShape->Merge(update_shape);
//if (pShape->IsListStyleEmpty() == false)
//{
// //create list style
//}else if (listMasterStyle)
//{
//}
OoxConverter::convert(&update_shape);
}
else

View File

@ -65,6 +65,7 @@ namespace PPTX
class TableCell;
class TableCellProperties;
class TcBdr;
class TxStyles;
}
}
@ -105,14 +106,13 @@ namespace Oox2Odf
void convert(OOX::WritingElement *oox_unknown);
void convert_slide (PPTX::Logic::CSld *oox_slide, bool bPlaceholders = true);
void convert_slide (PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxStyles* txStyles, bool bPlaceholders = true);
void convert_layout (PPTX::Logic::CSld *oox_slide);
void convert (PPTX::Comments *oox_comments);
void convert (PPTX::NotesSlide *oox_note);
void convert(PPTX::Logic::Bg *oox_background);
void convert(PPTX::Logic::Transition *oox_transition);
void convert(PPTX::Logic::Timing *oox_timing);
void convert(PPTX::Logic::Timing *oox_timing, PPTX::Logic::Transition *oox_transition);
void convert(PPTX::Logic::Table *oox_table);
void convert(PPTX::Logic::TableRow *oox_table_row);

View File

@ -45,7 +45,6 @@ namespace PPTX
{
m_name = name_;
m_pLevelUp = NULL;
m_nMasterTextType = -1;
}
Shape::~Shape()
@ -55,21 +54,18 @@ namespace PPTX
Shape::Shape(XmlUtils::CXmlNode& node)
{
m_pLevelUp = NULL;
m_nMasterTextType = -1;
fromXML(node);
}
Shape::Shape(XmlUtils::CXmlLiteReader& oReader)
{
m_pLevelUp = NULL;
m_nMasterTextType = -1;
fromXML(oReader);
}
const Shape& Shape::operator =(XmlUtils::CXmlNode& node)
{
m_pLevelUp = NULL;
m_nMasterTextType = -1;
fromXML(node);
return *this;
@ -77,7 +73,6 @@ namespace PPTX
const Shape& Shape::operator =(XmlUtils::CXmlLiteReader& oReader)
{
m_pLevelUp = NULL;
m_nMasterTextType = -1;
fromXML(oReader);
return *this;
@ -442,7 +437,6 @@ namespace PPTX
pWriter->EndRecord();
}
void Shape::FillLevelUp()
{
if ((m_pLevelUp == NULL) && (nvSpPr.nvPr.ph.IsInit()))
@ -457,57 +451,30 @@ namespace PPTX
}
}
bool Shape::IsListStyleEmpty()
{
if ((m_pLevelUp) && (m_pLevelUp->IsListStyleEmpty() == false)) return false;
if (txBody.IsInit() == false) return true;
if (txBody->lstStyle.IsInit() == false) return true;
for (int i = 0; i < 10; i++)
{
if (txBody->lstStyle->levels[i].IsInit())
return false;
}
return true;
}
void Shape::Merge(Shape& shape, bool bIsSlidePlaceholder)
{
if (m_pLevelUp)
m_pLevelUp->Merge(shape, true);
shape.m_name = m_name;
shape.m_nMasterTextType = m_nMasterTextType;
shape.nvSpPr = nvSpPr;
shape.m_name = m_name;
shape.nvSpPr = nvSpPr;
spPr.Merge(shape.spPr);
if (parentFileIs<SlideMaster>() && (parentFileAs<SlideMaster>()).txStyles.IsInit())
{
TextListStyle * listMasterStyle = NULL;
std::wstring type = nvSpPr.nvPr.ph->type.get_value_or(_T("body"));
if ((type == L"title") || (type == L"ctrTitle"))
{
m_nMasterTextType = 1;
listMasterStyle = (parentFileAs<SlideMaster>()).txStyles->titleStyle.GetPointer();
}
else if ((type == L"body") || (type == L"subTitle") || (type == L"obj"))
{
m_nMasterTextType = 2;
listMasterStyle = (parentFileAs<SlideMaster>()).txStyles->bodyStyle.GetPointer();
}
else if (type != L"")
{
m_nMasterTextType = 3;
listMasterStyle = (parentFileAs<SlideMaster>()).txStyles->otherStyle.GetPointer();
}
if (listMasterStyle)
{
if(!txBody.is_init())
txBody = new TxBody();
TextListStyle *newListStyle = new TextListStyle();
for (int i = 0; i < 10; i++)
{
if(listMasterStyle->levels[i].is_init())
listMasterStyle->levels[i]->Merge(newListStyle->levels[i]);
if(txBody->lstStyle->levels[i].is_init())
txBody->lstStyle->levels[i]->Merge(newListStyle->levels[i]);
}
txBody->lstStyle.reset(newListStyle);
}
}
shape.m_nMasterTextType = m_nMasterTextType;
if (style.is_init())
{
shape.m_bIsFontRefInSlide = bIsSlidePlaceholder;

View File

@ -303,6 +303,7 @@ namespace PPTX
void FillLevelUp();
void Merge(Shape& shape, bool bIsSlidePlaceholder = false);
bool IsListStyleEmpty();
void SetLevelUpElement( Shape* p){m_pLevelUp = p;};
@ -316,7 +317,6 @@ namespace PPTX
//-------------------------------------------------------------------------------------------------
std::wstring m_name;
Shape * m_pLevelUp;
int m_nMasterTextType;
bool m_bIsFontRefInSlide;
//-------------------------------------------------------------------------------------------------
NvSpPr nvSpPr;

View File

@ -0,0 +1,427 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifndef _BUILD_BIGINTEGER_CROSSPLATFORM_H_
#define _BUILD_BIGINTEGER_CROSSPLATFORM_H_
#include <string>
class CBigInteger
{
protected:
std::string m_value;
bool m_isNegative;
public:
CBigInteger()
{
m_value = "0";
m_isNegative = false;
}
CBigInteger(unsigned char* data, int size)
{
m_isNegative = false;
m_value = "0";
for (int i = 0; i < size; i++)
{
CBigInteger tmp((int)data[i]);
for (int j = size - 1 - i; j > 0; --j)
tmp *= 256;
*this += tmp;
}
}
CBigInteger(std::string data, int nBase = 10)
{
m_isNegative = false;
if (10 == nBase)
{
m_value = data;
}
else
{
m_value = "0";
int len = (int)data.length();
for (int i = 0; i < len; i++)
{
int val = 0;
char _c = data[i];
if (_c >= '0' && _c <= '9')
val = _c - '0';
else if (_c >= 'A' && _c <= 'F')
val = 10 + _c - 'A';
else if (_c >= 'a' && _c <= 'f')
val = 10 + _c - 'a';
CBigInteger tmp(val);
for (int j = len - 1 - i; j > 0; --j)
tmp *= nBase;
*this += tmp;
}
}
}
CBigInteger(int value)
{
if (value < 0)
{
m_isNegative = true;
m_value = std::to_string(-value);
}
else
{
m_isNegative = false;
m_value = std::to_string(value);
}
}
std::string GetValue()
{
return m_value;
}
bool IsNegative()
{
return m_isNegative;
}
void operator = (CBigInteger b)
{
m_value = b.m_value;
m_isNegative = b.m_isNegative;
}
bool operator == (CBigInteger b)
{
return equals((*this) , b);
}
bool operator != (CBigInteger b)
{
return !equals((*this) , b);
}
bool operator > (CBigInteger b)
{
return greater((*this) , b);
}
bool operator < (CBigInteger b)
{
return less((*this) , b);
}
bool operator >= (CBigInteger b)
{
return equals((*this) , b) || greater((*this), b);
}
bool operator <= (CBigInteger b)
{
return equals((*this) , b) || less((*this) , b);
}
CBigInteger absolute()
{
return CBigInteger(m_value); // +ve by default
}
CBigInteger& operator ++()
{
// prefix
(*this) = (*this) + 1;
return (*this);
}
CBigInteger operator ++(int)
{
// postfix
CBigInteger before = (*this);
(*this) = (*this) + 1;
return before;
}
CBigInteger& operator --()
{
// prefix
(*this) = (*this) - 1;
return (*this);
}
CBigInteger operator --(int)
{
// postfix
CBigInteger before = (*this);
(*this) = (*this) - 1;
return before;
}
CBigInteger operator + (CBigInteger b)
{
CBigInteger addition;
if (m_isNegative == b.m_isNegative)
{
// both +ve or -ve
addition.m_value = (add(m_value, b.m_value));
addition.m_isNegative = m_isNegative;
}
else
{
// sign different
if (absolute() > b.absolute())
{
addition.m_value = subtract(m_value, b.m_value);
addition.m_isNegative = m_isNegative;
}
else
{
addition.m_value = subtract(b.m_value, m_value);
addition.m_isNegative = b.m_isNegative;
}
}
if (addition.m_value == "0") // avoid (-0) problem
addition.m_isNegative = false;
return addition;
}
CBigInteger operator - (CBigInteger b)
{
b.m_isNegative = !b.m_isNegative; // x - y = x + (-y)
return (*this) + b;
}
CBigInteger operator * (CBigInteger b)
{
CBigInteger mul;
mul.m_value = multiply(m_value, b.m_value);
mul.m_isNegative = (m_isNegative != b.m_isNegative);
if (mul.m_value == "0") // avoid (-0) problem
mul.m_isNegative = false;
return mul;
}
CBigInteger& operator += (CBigInteger b)
{
(*this) = (*this) + b;
return (*this);
}
CBigInteger& operator -= (CBigInteger b)
{
(*this) = (*this) - b;
return (*this);
}
CBigInteger& operator *= (CBigInteger b)
{
(*this) = (*this) * b;
return (*this);
}
CBigInteger operator -() { // unary minus sign
return (*this) * -1;
}
std::string ToString()
{
// for conversion from BigInteger to string
std::string signedString = ( m_isNegative ) ? "-" : ""; // if +ve, don't print + sign
signedString += m_value;
return signedString;
}
private:
bool equals(CBigInteger n1, CBigInteger n2)
{
return ((n1.m_value == n2.m_value) && (n1.m_isNegative == n2.m_isNegative));
}
bool less(CBigInteger n1, CBigInteger n2)
{
bool sign1 = n1.m_isNegative;
bool sign2 = n2.m_isNegative;
if (sign1 && !sign2)
return true;
else if (!sign1 && sign2)
return false;
else if (!sign1)
{
std::string::size_type _size1 = n1.m_value.length();
std::string::size_type _size2 = n2.m_value.length();
if (_size1 < _size2)
return true;
if (_size1 > _size2)
return false;
return n1.m_value < n2.m_value;
}
else
{
std::string::size_type _size1 = n1.m_value.length();
std::string::size_type _size2 = n2.m_value.length();
if (_size1 > _size2)
return true;
if (_size1 < _size2)
return false;
return n1.m_value.compare(n2.m_value) > 0;
}
}
bool greater(CBigInteger n1, CBigInteger n2)
{
return !equals(n1, n2) && !less(n1, n2);
}
std::string add(std::string number1, std::string number2)
{
std::string add = (number1.length() > number2.length()) ? number1 : number2;
char carry = '0';
int differenceInLength = (int)(number1.size() - number2.size());
if (differenceInLength > 0)
number2.insert(0, differenceInLength, '0');
else
number1.insert(0, -differenceInLength, '0');
if (differenceInLength < 0)
differenceInLength = -differenceInLength;
for (int i = number1.size() - 1; i >= 0; --i)
{
add[i] = ((carry-'0')+(number1[i]-'0')+(number2[i]-'0')) + '0';
if(i != 0)
{
if(add[i] > '9')
{
add[i] -= 10;
carry = '1';
}
else
{
carry = '0';
}
}
}
if (add[0] > '9')
{
add[0] -= 10;
add.insert(0, 1, '1');
}
return add;
}
std::string subtract(std::string number1, std::string number2)
{
std::string sub = (number1.length() > number2.length()) ? number1 : number2;
int differenceInLength = (int)(number1.size() - number2.size());
if (differenceInLength > 0)
number2.insert(0, differenceInLength, '0');
else
number1.insert(0, -differenceInLength, '0');
if (differenceInLength < 0)
differenceInLength = -differenceInLength;
for (int i = number1.length() - 1; i >= 0; --i)
{
if (number1[i] < number2[i])
{
number1[i] += 10;
number1[i-1]--;
}
sub[i] = ((number1[i]-'0')-(number2[i]-'0')) + '0';
}
while (sub[0]=='0' && sub.length() != 1) // erase leading zeros
sub.erase(0, 1);
return sub;
}
std::string multiply(std::string n1, std::string n2)
{
if (n1.length() > n2.length())
n1.swap(n2);
std::string res = "0";
for (int i = n1.length() - 1; i >= 0; --i)
{
std::string temp = n2;
int currentDigit = n1[i] - '0';
int carry = 0;
for (int j = temp.length() - 1; j >= 0; --j)
{
temp[j] = ((temp[j]-'0') * currentDigit) + carry;
if (temp[j] > 9)
{
carry = (temp[j] / 10);
temp[j] -= (carry * 10);
}
else
{
carry = 0;
}
temp[j] += '0'; // back to string mood
}
if (carry > 0)
temp.insert(0, 1, (carry+'0'));
temp.append((n1.length() - i - 1), '0'); // as like mult by 10, 100, 1000, 10000 and so on
res = add(res, temp); // O(n)
}
while (res[0] == '0' && res.length() != 1) // erase leading zeros
res.erase(0,1);
return res;
}
};
#endif //_BUILD_BIGINTEGER_CROSSPLATFORM_H_

View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sha1_C14N", "ConsoleApplication1\Sha1_C14N.csproj", "{A945E071-111A-41E0-8BB0-4F7755EBB77B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A945E071-111A-41E0-8BB0-4F7755EBB77B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A945E071-111A-41E0-8BB0-4F7755EBB77B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A945E071-111A-41E0-8BB0-4F7755EBB77B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A945E071-111A-41E0-8BB0-4F7755EBB77B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Security.Cryptography.X509Certificates;
using System.IO;
namespace Sha1_C14N
{
class Program
{
static void Main(string[] args)
{
XmlDocument docStripped = new XmlDocument();
//docStripped.Load(@"D:\GIT\core\DesktopEditor\xmlsec\test\windows_list_serts\Debug\debug\document.xml");
docStripped.Load("D:\\444.txt");
XmlDsigC14NTransform t = new XmlDsigC14NTransform();
t.LoadInput(docStripped);
Stream s = (Stream)t.GetOutput(typeof(Stream));
BinaryReader br = new BinaryReader(s);
byte[] b = br.ReadBytes((int)s.Length);
File.Delete("D:\\1.txt");
var fileStream = File.Create("D:\\1.txt");
s.Seek(0, SeekOrigin.Begin);
s.CopyTo(fileStream);
fileStream.Close();
s.Seek(0, SeekOrigin.Begin);
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHash(s);
string base64String = Convert.ToBase64String(hash);
FileStream fRes = File.Create("D:\\res.bin");
fRes.Write(hash, 0, hash.Length);
fRes.Close();
SHA1 sha33 = SHA1.Create();
byte[] hash33 = sha33.ComputeHash(b);
string base64String2 = Convert.ToBase64String(hash33);
FileStream s1 = File.OpenRead(@"D:\GIT\core\DesktopEditor\xmlsec\test\windows_list_serts\Debug\debug\document2.xml");
SHA1 sha11 = SHA1.Create();
byte[] hash11 = sha11.ComputeHash(s1);
string base64_11 = Convert.ToBase64String(hash11);
X509Store my = new X509Store(StoreName.My, StoreLocation.CurrentUser);
my.Open(OpenFlags.ReadOnly);
// Find the certificate well use to sign
RSACryptoServiceProvider csp = null;
foreach (X509Certificate2 cert in my.Certificates)
{
string sName = cert.Subject;
if (cert.Subject.Contains("Oleg.Korshul"))
{
csp = (RSACryptoServiceProvider)cert.PrivateKey;
break;
}
}
byte[] signedData = csp.SignHash(hash11, CryptoConfig.MapNameToOID("SHA1"));
string signedDataBase64 = Convert.ToBase64String(signedData);
Console.WriteLine(base64_11);
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Управление общими сведениями о сборке осуществляется с помощью
// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
// связанные со сборкой.
[assembly: AssemblyTitle("Sha1_C14N")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Sha1_C14N")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Параметр ComVisible со значением FALSE делает типы в сборке невидимыми
// для COM-компонентов. Если требуется обратиться к типу в этой сборке через
// COM, задайте атрибуту ComVisible значение TRUE для этого типа.
[assembly: ComVisible(false)]
// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
[assembly: Guid("a945e071-111a-41e0-8bb0-4f7755ebb77b")]
// Сведения о версии сборки состоят из следующих четырех значений:
//
// Основной номер версии
// Дополнительный номер версии
// Номер сборки
// Редакция
//
// Можно задать все значения или принять номера сборки и редакции по умолчанию
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A945E071-111A-41E0-8BB0-4F7755EBB77B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ConsoleApplication1</RootNamespace>
<AssemblyName>ConsoleApplication1</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Security" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -7,6 +7,7 @@
#include <string>
#include "../../../common/File.h"
#include "../../../common/BigInteger.h"
#pragma comment (lib, "crypt32.lib")
#pragma comment (lib, "cryptui.lib")
@ -20,8 +21,30 @@ void MyHandleError(char *s);
bool Sign(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFileXml, std::wstring sSignatureFile);
bool Verify(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFileXml, std::wstring sSignatureFile);
void ConvertEndian(const BYTE* src, BYTE* dst, DWORD size)
{
for(BYTE* p = dst + size - 1; p >= dst; ++src, --p)
(*p) = (*src);
}
void main(void)
{
if (false)
{
CBigInteger int1("345097");
CBigInteger int2("87960324");
CBigInteger val1 = int1 + int2;
CBigInteger val2 = int1 - int2;
CBigInteger val3 = int1 * int2;
CBigInteger int3("66A1F302407647974D18D489855371B5", 16);
unsigned char buffer[16] = { 0x66, 0xA1, 0xF3, 0x02, 0x40, 0x76, 0x47, 0x97, 0x4D, 0x18, 0xD4, 0x89, 0x85, 0x53, 0x71, 0xB5 };
CBigInteger val4(buffer, 16);
std::string sValue = int3.ToString();
}
//-------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
@ -312,8 +335,8 @@ void main(void)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool bRes = true;
bRes = Sign(hCertStore, pCertContext, NSFile::GetProcessDirectory() + L"/document.xml", NSFile::GetProcessDirectory() + L"/result.txt");
bRes = Verify(hCertStore, pCertContext, NSFile::GetProcessDirectory() + L"/document.xml", NSFile::GetProcessDirectory() + L"/result.txt");
bRes = Sign(hCertStore, pCertContext, NSFile::GetProcessDirectory() + L"/document2.xml", NSFile::GetProcessDirectory() + L"/result.txt");
bRes = Verify(hCertStore, pCertContext, NSFile::GetProcessDirectory() + L"/document2.xml", NSFile::GetProcessDirectory() + L"/result.txt");
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CertFreeCertificateContext(pCertContext);
@ -342,8 +365,6 @@ bool Sign(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFi
DWORD dwSigLen = 0;
BYTE* pbSignature = NULL;
// Open the certificate store.
bResult = CryptAcquireCertificatePrivateKey(pCertContext, 0, NULL, &hCryptProv, &dwKeySpec, NULL);
bool bIsResult = ((dwKeySpec & AT_SIGNATURE) == AT_SIGNATURE);
@ -357,6 +378,23 @@ bool Sign(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFi
bResult = CryptHashData(hHash, pDataSrc, dwFileSrcLen, 0);
if (true)
{
DWORD cbHashSize = 0, dwCount = sizeof(DWORD);
BOOL b1 = CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE*)&cbHashSize, &dwCount, 0);
BYTE* pDataHashRaw = new BYTE[dwCount];
BOOL b2 = CryptGetHashParam(hHash, HP_HASHVAL, pDataHashRaw, &cbHashSize, 0);
char* pBase64_hash = NULL;
int nBase64Len_hash = 0;
NSFile::CBase64Converter::Encode(pDataHashRaw, (int)cbHashSize, pBase64_hash, nBase64Len_hash, NSBase64::B64_BASE64_FLAG_NONE);
delete [] pBase64_hash;
}
// Sign the hash object
dwSigLen = 0;
bResult = CryptSignHash(hHash, dwKeySpec, NULL, 0, NULL, &dwSigLen);
@ -364,18 +402,27 @@ bool Sign(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFi
pbSignature = new BYTE[dwSigLen];
bResult = CryptSignHash(hHash, dwKeySpec, NULL, 0, pbSignature, &dwSigLen);
NSFile::CFileBinary oFileTmp;
oFileTmp.CreateFileW(NSFile::GetProcessDirectory() + L"/HASH.bin");
oFileTmp.WriteFile(pbSignature, dwSigLen);
oFileTmp.CloseFile();
BYTE* pbSignatureMem = new BYTE[dwSigLen];
ConvertEndian(pbSignature, pbSignatureMem, dwSigLen);
NSFile::CFileBinary oFile;
oFile.CreateFileW(sSignatureFile);
//oFile.WriteFile(pbSignature, dwSigLen);
char* pBase64 = NULL;
int nBase64Len = 0;
NSFile::CBase64Converter::Encode(pbSignature, (int)dwSigLen, pBase64, nBase64Len, NSBase64::B64_BASE64_FLAG_NONE);
NSFile::CBase64Converter::Encode(pbSignatureMem, (int)dwSigLen, pBase64, nBase64Len, NSBase64::B64_BASE64_FLAG_NONE);
oFile.WriteFile((BYTE*)pBase64, (DWORD)nBase64Len);
oFile.CloseFile();
delete[] pbSignature;
delete[] pbSignatureMem;
delete[] pDataSrc;
bResult = CryptDestroyHash(hHash);
@ -409,18 +456,22 @@ bool Verify(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring s
NSFile::CBase64Converter::Decode((char*)pDataHashBase64, (int)dwFileHashSrcLenBase64, pDataHash, nTmp);
dwHashLen = (DWORD)nTmp;
BYTE* pDataHashMem = new BYTE[dwHashLen];
ConvertEndian(pDataHash, pDataHashMem, dwHashLen);
bResult = CryptHashData(hHash, pDataSrc, dwFileSrcLen, 0);
// Get the public key from the certificate
CryptImportPublicKeyInfo(hCryptProv, PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, &pCertContext->pCertInfo->SubjectPublicKeyInfo, &hPubKey);
bResult = CryptVerifySignature(hHash, pDataHash, dwHashLen, hPubKey, NULL, 0);
BOOL bResultRet = CryptVerifySignature(hHash, pDataHashMem, dwHashLen, hPubKey, NULL, 0);
delete[] pDataSrc;
delete[] pDataHash;
delete[] pDataHashMem;
delete[] pDataHashBase64;
bResult = CryptDestroyHash(hHash);
return bResult;
return bResultRet && bResult;
}