Compare commits

..

11 Commits

Author SHA1 Message Date
cb5d92334e OdfFormatWriter - presentation ... 2017-04-18 16:40:03 +03:00
f6dbc6b9f0 fix bug #34762 2017-04-17 22:16:47 +03:00
c2c6430495 . 2017-04-17 18:55:02 +03:00
9ecf5b7834 Merge pull request #23 from ONLYOFFICE/hotfix/v4.3.2
Hotfix/v4.3.2
2017-04-17 17:12:30 +03:00
1d003863dd . 2017-04-17 17:10:12 +03:00
774561bd00 Merge branch 'develop' into hotfix/v4.3.2 2017-04-17 16:56:05 +03:00
d356a305b9 tests (mscrypto) 2017-04-17 16:45:35 +03:00
2dbec241f7 OdfFormatWriter - presentation comments 2017-04-17 14:06:14 +03:00
f3c66cab50 OdfFormatWriter 2017-04-17 09:56:12 +03:00
51c77c3a85 Fixed downloading icu binaries from sourceforge 2017-04-05 19:59:56 +03:00
4326a7d258 fix bug 34695 2017-04-05 19:48:02 +03:00
41 changed files with 1433 additions and 313 deletions

View File

@ -45,13 +45,13 @@ namespace Writers
int index;
};
std::vector<_chartElem> m_aCharts;
int nChartCount;
public:
std::wstring m_sDir;
int nEmbeddedCount;
ChartWriter(std::wstring sDir) : m_sDir(sDir)
{
nChartCount = 0;
nEmbeddedCount = 1000;
}
~ChartWriter()
{
@ -80,30 +80,20 @@ namespace Writers
}
return true;
}
void AddChart(std::wstring& content, std::wstring& sRelsName, std::wstring& sFileName, int& index)
void AddChart(std::wstring& content, std::wstring& sRelsName, std::wstring& sFileName, int index)
{
_chartElem oChartElem;
oChartElem.content = content;
oChartElem.index = nChartCount + 1;
nChartCount++;
oChartElem.index = index;
oChartElem.filename = L"chart" + std::to_wstring(oChartElem.index) + L".xml";
sRelsName = L"charts/" + oChartElem.filename;
sFileName = oChartElem.filename;
index = oChartElem.index;
m_aCharts.push_back(oChartElem);
}
int getChartCount()
{
return nChartCount;
}
void setChartCount(int val)
{
nChartCount = val;
}
};
}
#endif // #ifndef CHART_WRITER

View File

@ -6292,15 +6292,11 @@ public:
std::wstring sDrawingProperty = oCDrawingProperty.Write();
if(false == sDrawingProperty.empty())
{
m_oFileWriter.m_pDrawingConverter->SetDocumentChartsCount(m_oFileWriter.m_oChartWriter.getChartCount());
long nCurPos = m_oBufferedStream.GetPos();
std::wstring sDrawingXml;
m_oFileWriter.m_pDrawingConverter->SaveObjectEx(oCDrawingProperty.DataPos, oCDrawingProperty.DataLength, sDrawingProperty, XMLWRITER_DOC_TYPE_DOCX, sDrawingXml);
m_oBufferedStream.Seek(nCurPos);
m_oFileWriter.m_oChartWriter.setChartCount(m_oFileWriter.m_pDrawingConverter->GetDocumentChartsCount());
if( false == sDrawingXml.empty())
{
GetRunStringWriter().WriteString(sDrawingXml);
@ -6606,8 +6602,11 @@ public:
OOX::Spreadsheet::CChartSpace* pChartSpace = new OOX::Spreadsheet::CChartSpace();
oBinaryChartReader.ReadCT_ChartSpace(length, &pChartSpace->m_oChartSpace);
//save xlsx
std::wstring sXlsxFilename = L"Microsoft_Excel_Worksheet" + std::to_wstring(m_oFileWriter.m_oChartWriter.getChartCount() + 1) + L".xlsx";
//save xlsx
_INT32 nChartCount = m_oFileWriter.m_pDrawingConverter->GetDocumentChartsCount();
_INT32 nChartIndex = nChartCount + 1;
m_oFileWriter.m_pDrawingConverter->SetDocumentChartsCount(nChartCount + 1);
std::wstring sXlsxFilename = L"Microsoft_Excel_Worksheet" + std::to_wstring(nChartIndex) + L".xlsx";
std::wstring sXlsxPath = pathChartsWorksheetDir.GetPath() + FILE_SEPARATOR_STR + sXlsxFilename;
BinXlsxRW::CXlsxSerializer oXlsxSerializer;
oXlsxSerializer.writeChartXlsx(sXlsxPath, *pChartSpace);
@ -6632,7 +6631,6 @@ public:
std::wstring sFilename;
std::wstring sRelsName;
int nChartIndex;
std::wstring sContent = sw.GetData();
m_oFileWriter.m_oChartWriter.AddChart(sContent, sRelsName, sFilename, nChartIndex);
@ -6826,8 +6824,7 @@ public:
std::wstring strDstEmbeddedTemp = strDstEmbedded + FILE_SEPARATOR_STR + L"Temp";
NSDirectory::CreateDirectory(strDstEmbeddedTemp);
int id = m_oFileWriter.m_oChartWriter.getChartCount();
m_oFileWriter.m_oChartWriter.setChartCount(id + 1);
int id = m_oFileWriter.m_oChartWriter.nEmbeddedCount++;
std::wstring sXlsxFilename = L"Microsoft_Excel_Worksheet" + std::to_wstring( id + 1) + L".xlsx";
BinXlsxRW::SaveParams oSaveParams(m_oFileWriter.m_sThemePath, m_oFileWriter.m_pDrawingConverter->GetContentTypes());//???

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Version="8.00"
Name="OdfFileReaderTest"
ProjectGUID="{C2882DDD-07E6-4314-AD4B-48F43F38D722}"
RootNamespace="ASCOfficeOdfFileTest"

View File

@ -136,7 +136,8 @@ void xlsx_text_context::Impl::serialize_shared_strings(std::wostream & strm)
xlsx_text_context::Impl::Impl(odf_reader::styles_container & styles): paragraphs_cout_(0),styles_(styles),
in_comment(false),in_draw(false),in_paragraph(false),in_span(false),in_cell_content(false)
{
text_properties_cell_ = NULL;
local_styles_ptr_ = NULL;
text_properties_cell_ = NULL;
}
void xlsx_text_context::Impl::add_text(const std::wstring & text)

View File

@ -403,9 +403,11 @@ int draw_enhanced_geometry::parsing(_CP_OPT(std::wstring) val)
void draw_enhanced_geometry_attlist::serialize(CP_ATTR_NODE)
{
CP_XML_ATTR_OPT(L"draw:type", draw_type_);
CP_XML_ATTR_OPT(L"draw:text-areas", draw_text_areas_);
CP_XML_ATTR_OPT(L"drawooo:sub-view-size", draw_sub_view_size_);
CP_XML_ATTR_OPT(L"draw:text-areas", draw_text_areas_);
CP_XML_ATTR_OPT(L"draw:modifiers", draw_modifiers_);
CP_XML_ATTR_OPT(L"draw:enhanced-path", draw_enhanced_path_);
CP_XML_ATTR_OPT(L"drawooo:enhanced-path", draw_enhanced_path_);
//CP_XML_ATTR_OPT(L"draw:enhanced-path", draw_enhanced_path_);
CP_XML_ATTR_OPT(L"draw:glue-points", draw_glue_points_);
CP_XML_ATTR_OPT(L"draw:mirror-vertical", draw_mirror_vertical_);
CP_XML_ATTR_OPT(L"draw:mirror-horizontal", draw_mirror_horizontal_);

View File

@ -316,19 +316,21 @@ CP_REGISTER_OFFICE_ELEMENT2(draw_handle);
class draw_enhanced_geometry_attlist
{
public:
_CP_OPT(std::wstring) draw_type_;
_CP_OPT(std::wstring) draw_modifiers_;
_CP_OPT(std::wstring) draw_enhanced_path_;
_CP_OPT(std::wstring) draw_text_areas_;
_CP_OPT(std::wstring) draw_glue_points_;
_CP_OPT(std::wstring) draw_type_;
_CP_OPT(std::wstring) draw_modifiers_;
_CP_OPT(std::wstring) draw_enhanced_path_;
_CP_OPT(std::wstring) draw_text_areas_;
_CP_OPT(std::wstring) draw_glue_points_;
_CP_OPT(odf_types::Bool) draw_mirror_vertical_;
_CP_OPT(odf_types::Bool) draw_mirror_horizontal_;
_CP_OPT(std::wstring) draw_sub_view_size_;
_CP_OPT(odf_types::Bool) draw_mirror_vertical_;
_CP_OPT(odf_types::Bool) draw_mirror_horizontal_;
_CP_OPT(odf_types::Bool) draw_text_path_;
_CP_OPT(odf_types::Bool) draw_text_path_same_letter_heights_;
_CP_OPT(std::wstring) draw_text_path_mode_;
_CP_OPT(std::wstring) draw_text_path_scale_;
_CP_OPT(odf_types::Bool) draw_text_path_;
_CP_OPT(odf_types::Bool) draw_text_path_same_letter_heights_;
_CP_OPT(std::wstring) draw_text_path_mode_;
_CP_OPT(std::wstring) draw_text_path_scale_;
void serialize(CP_ATTR_NODE);
};

View File

@ -96,7 +96,7 @@ void odf_comment_context::start_comment(office_element_ptr &elm, int oox_id)
impl_->comments_.push_back(state);
impl_->comments_.back().elements_.push_back(elm);//"0" - root comment eleemnt
impl_->comments_.back().oox_id = oox_id;
impl_->comments_.back().oox_id = oox_id < 0 ? impl_->comments_.back().elements_.size() : oox_id;
impl_->comments_.back().odf_name = L"comment_" + boost::lexical_cast<std::wstring>(oox_id);
impl_->comments_.back().is_started = false;
@ -159,14 +159,14 @@ std::wstring odf_comment_context::find_name_by_id(int oox_id)
}
bool odf_comment_context::is_started()
{
if (impl_->comments_.size()>0)
if (!impl_->comments_.empty())
return impl_->comments_.back().is_started;
else return false;
}
void odf_comment_context::set_author(std::wstring author)
{
if ((impl_->comments_.size()<1) || !is_started()) return;
if ((impl_->comments_.empty()) || !is_started()) return;
office_element_ptr elm;
create_element(L"dc", L"creator", elm, impl_->odf_context_);
@ -178,11 +178,15 @@ void odf_comment_context::set_author(std::wstring author)
impl_->comments_.back().elements_[0]->add_child_element(elm);
impl_->comments_.back().elements_.push_back(elm);
}
void odf_comment_context::set_initials(std::wstring initials)
{
if ((impl_->comments_.empty()) || !is_started()) return;
}
void odf_comment_context::set_date(std::wstring _date)
{
if ((impl_->comments_.size()<1) || !is_started()) return;
if ((impl_->comments_.empty()) || !is_started()) return;
office_element_ptr elm;
create_element(L"dc", L"date", elm, impl_->odf_context_);
@ -195,5 +199,18 @@ void odf_comment_context::set_date(std::wstring _date)
impl_->comments_.back().elements_[0]->add_child_element(elm);
impl_->comments_.back().elements_.push_back(elm);
}
void odf_comment_context::set_position (double x, double y)
{
if ((impl_->comments_.empty()) || !is_started()) return;
office_annotation* comm = dynamic_cast<office_annotation*>(impl_->comments_.back().elements_.back().get());
if (comm)
{
comm->office_annotation_attr_.svg_x_ = odf_types::length(x, odf_types::length::pt);
comm->office_annotation_attr_.svg_y_ = odf_types::length(y, odf_types::length::pt);
}
}
}
}

View File

@ -66,8 +66,11 @@ public:
void start_comment_content ();
void end_comment_content ();
void set_author (std::wstring author);
void set_date (std::wstring author);
void set_author (std::wstring author);
void set_initials (std::wstring author);
void set_date (std::wstring author);
void set_position (double x, double y);
private:
std::wstring find_name_by_id(int oox_id);

View File

@ -190,9 +190,9 @@ struct odf_drawing_state
path_ = L"";
view_box_ = L"";
path_last_command_ = L"";
modifiers_ = L"";
oox_shape_preset = -1;
oox_shape_.reset();
in_group = false;
text_box_tableframe = false;
@ -221,11 +221,10 @@ struct odf_drawing_state
bool flipH;
bool flipV;
std::wstring path_;
std::wstring view_box_;
std::wstring path_last_command_;
std::wstring modifiers_;
std::wstring path_;
std::wstring view_box_;
std::wstring path_last_command_;
oox_shape_ptr oox_shape_;
///////////////////////
int oox_shape_preset;
bool in_group;
@ -713,7 +712,7 @@ void odf_drawing_context::Impl::create_draw_base(int type)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int level = current_level_.size();
if (current_level_.size()>0)
if (current_level_.size() > 0)
current_level_.back()->add_child_element(draw_elm);
current_level_.push_back(draw_elm);
@ -722,6 +721,9 @@ void odf_drawing_context::Impl::create_draw_base(int type)
current_drawing_state_.elements_.push_back(state);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (type == 7)
current_drawing_state_.oox_shape_ = oox_shape_ptr(new oox_shape());
}
void odf_drawing_context::start_shape(int type)
@ -738,7 +740,7 @@ void odf_drawing_context::start_shape(int type)
}
else if (type == 1001)
{
impl_->create_draw_base(6);//пока кастом .. потом переделать на path, что правильнее
impl_->create_draw_base(6); //path
}
else if (type == 2000)
{
@ -748,9 +750,9 @@ void odf_drawing_context::start_shape(int type)
{
start_image(L"");
}
else if (type > 2000 && type < 3000)
else if (type > 2000 && type < 3000) //custom text path
{
impl_->create_draw_base(7);
impl_->create_draw_base(7);
}
}
@ -812,7 +814,10 @@ void odf_drawing_context::end_shape()
if (impl_->current_drawing_state_.oox_shape_preset == 3000) return end_image();
//вторичные, вычисляемые свойства шейпов
bool line_always_present = false;
if (isLineShape())
{
impl_->current_graphic_properties->common_draw_fill_attlist_.draw_fill_ = draw_fill::none;
}
draw_path* path = dynamic_cast<draw_path*>(impl_->current_drawing_state_.elements_[0].elm.get());
if (path)
@ -821,10 +826,8 @@ void odf_drawing_context::end_shape()
set_viewBox( impl_->current_drawing_state_.svg_width_->get_value_unit(length::cm) * 1000,
impl_->current_drawing_state_.svg_height_->get_value_unit(length::cm) *1000);
if (impl_->current_drawing_state_.path_.length()>1) path->draw_path_attlist_.svg_d_ = impl_->current_drawing_state_.path_;
if (impl_->current_drawing_state_.view_box_.length()>1) path->draw_path_attlist_.svg_viewbox_ = impl_->current_drawing_state_.view_box_;
line_always_present = true;
if (!impl_->current_drawing_state_.path_.empty()) path->draw_path_attlist_.svg_d_ = impl_->current_drawing_state_.path_;
if (!impl_->current_drawing_state_.view_box_.empty()) path->draw_path_attlist_.svg_viewbox_ = impl_->current_drawing_state_.view_box_;
}
////////////////////////////////////////////////////////////////////////////////////////////
draw_line* line = dynamic_cast<draw_line*>(impl_->current_level_.back().get());
@ -861,16 +864,14 @@ void odf_drawing_context::end_shape()
line->draw_line_attlist_.svg_x1_ = line->draw_line_attlist_.svg_x2_;
line->draw_line_attlist_.svg_x2_ = tmp;
}
line_always_present = true;
}
////////////////////////////////////////////////////////////////////////////////////
draw_connector* connector = dynamic_cast<draw_connector*>(impl_->current_level_.back().get());
if (connector)
{
if (!connector->draw_connector_attlist_.draw_type_) connector->draw_connector_attlist_.draw_type_ = L"line";
line_always_present = true;
if (!connector->draw_connector_attlist_.draw_type_)
connector->draw_connector_attlist_.draw_type_ = L"line";
}
//////////////////////////////////////////////////////////////////////////////////////////////////
@ -888,11 +889,11 @@ void odf_drawing_context::end_shape()
{
text_shape = true;
}
else
{
sub_type = L"polyline";
line_always_present = true;
}
//else
//{
// sub_type = L"polyline";
// line_always_present = true;
//}
office_element_ptr enhanced_elm;
create_element(L"draw", L"enhanced-geometry", enhanced_elm, impl_->odf_context_);
@ -906,52 +907,50 @@ void odf_drawing_context::end_shape()
{
enhanced->draw_enhanced_geometry_attlist_.draw_text_path_same_letter_heights_ = false;
enhanced->draw_enhanced_geometry_attlist_.draw_text_path_scale_ = L"path" ;
enhanced->draw_enhanced_geometry_attlist_.draw_text_path_mode_ = L"shape" ;
enhanced->draw_enhanced_geometry_attlist_.draw_text_path_ = true;
enhanced->draw_enhanced_geometry_attlist_.draw_text_path_mode_ = L"shape" ;
enhanced->draw_enhanced_geometry_attlist_.draw_text_path_ = true;
}
if (impl_->current_drawing_state_.path_.length()>1)
if (!impl_->current_drawing_state_.path_.empty())
{
enhanced->draw_enhanced_geometry_attlist_.draw_enhanced_path_ =impl_->current_drawing_state_.path_;
}
if (impl_->current_drawing_state_.view_box_.length()>1)
if (!impl_->current_drawing_state_.view_box_.empty())
{
enhanced->svg_viewbox_ = impl_->current_drawing_state_.view_box_;
}
if (sub_type.length()>1)
if (!sub_type.empty())
{
enhanced->draw_enhanced_geometry_attlist_.draw_type_ = sub_type;
int res=0;
if ((res = sub_type.find(L"ooxml")) >= 0 && impl_->current_drawing_state_.modifiers_.length()>1)
{
enhanced->draw_enhanced_geometry_attlist_.draw_modifiers_ = impl_->current_drawing_state_.modifiers_;
}
}
else
{
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_;
if (shape_define)
{
enhanced->svg_viewbox_ = shape_define->view_box;
enhanced->draw_enhanced_geometry_attlist_.draw_type_ = shape_define->odf_type_name;
enhanced->draw_enhanced_geometry_attlist_.draw_text_areas_ = shape_define->text_areas;
if (shape_define->glue_points)
{
enhanced->draw_enhanced_geometry_attlist_.draw_glue_points_ = *shape_define->glue_points;
}
enhanced->svg_viewbox_ = shape_define->view_box;
enhanced->draw_enhanced_geometry_attlist_.draw_type_ = shape_define->odf_type_name;
enhanced->draw_enhanced_geometry_attlist_.draw_text_areas_ = shape_define->text_areas;
enhanced->draw_enhanced_geometry_attlist_.draw_glue_points_ = shape_define->glue_points;
enhanced->draw_enhanced_geometry_attlist_.draw_sub_view_size_ = shape_define->sub_view_size;
if (impl_->current_drawing_state_.modifiers_.length()>1)
if (impl_->current_drawing_state_.oox_shape_ && !impl_->current_drawing_state_.oox_shape_->modifiers.empty())
{
enhanced->draw_enhanced_geometry_attlist_.draw_modifiers_ = impl_->current_drawing_state_.modifiers_;
enhanced->draw_enhanced_geometry_attlist_.draw_modifiers_ = impl_->current_drawing_state_.oox_shape_->modifiers;
}
else // обязательно нужны дефолтовые
enhanced->draw_enhanced_geometry_attlist_.draw_modifiers_ = shape_define->modifiers;
enhanced->draw_enhanced_geometry_attlist_.draw_enhanced_path_ = shape_define->enhanced_path;
if (!shape_define->enhanced_path.empty())
enhanced->draw_enhanced_geometry_attlist_.draw_enhanced_path_ = shape_define->enhanced_path;
else
enhanced->draw_enhanced_geometry_attlist_.draw_enhanced_path_ = impl_->current_drawing_state_.path_;
for (size_t i = 0; i < shape_define->equations.size();i++)
for (size_t i = 0; i < shape_define->equations.size(); i++)
{
office_element_ptr elm_eq;
create_element(L"draw", L"equation", elm_eq, impl_->odf_context_);
@ -965,7 +964,7 @@ void odf_drawing_context::end_shape()
end_element();
}
//-----------------------------
for (size_t i = 0; i < shape_define->handles.size();i++)
for (size_t i = 0; i < shape_define->handles.size(); i++)
{
office_element_ptr elm_h;
create_element(L"draw", L"handle", elm_h, impl_->odf_context_);
@ -988,7 +987,38 @@ void odf_drawing_context::end_shape()
}
end_element();
}
void odf_drawing_context::corrected_line_fill()
bool odf_drawing_context::isLineShape()
{
if (impl_->current_level_.empty()) return false;
draw_line* line = dynamic_cast<draw_line*>(impl_->current_level_.back().get());
if (line) return true;
draw_connector* connector = dynamic_cast<draw_connector*>(impl_->current_level_.back().get());
if (connector) return true;
draw_path* path = dynamic_cast<draw_path*>(impl_->current_level_.back().get());
if (path) return true;
switch(impl_->current_drawing_state_.oox_shape_preset)
{
case 20: //SimpleTypes::shapetypeBentConnector2:
case 21: //SimpleTypes::shapetypeBentConnector3:
case 22: //SimpleTypes::shapetypeBentConnector4:
case 23: //SimpleTypes::shapetypeBentConnector5:
case 47: //SimpleTypes::shapetypeCurvedConnector2:
case 48: //SimpleTypes::shapetypeCurvedConnector3:
case 49: //SimpleTypes::shapetypeCurvedConnector4:
case 50: //SimpleTypes::shapetypeCurvedConnector5:
return true;
default:
return false;
}
return false;
}
void odf_drawing_context::corrected_line_fill() //for vml objects
{
if (!impl_->current_graphic_properties)return;
@ -1246,10 +1276,12 @@ void odf_drawing_context::set_path(std::wstring path_string)
//boost::replace_all(path_string, L",,", L" 0 ");
//boost::replace_all(path_string, L" -", L"-");
//boost::replace_all(path_string, L",", L"0"); // нужен разбор
//impl_->current_drawing_state_.path_ = path_string;
impl_->current_drawing_state_.path_ = path_string;
}
void odf_drawing_context::add_path_element(std::wstring command, const std::wstring & strE)
void odf_drawing_context::add_path_element(std::wstring command, std::wstring strE)
{
XmlUtils::replace_all(strE, L"gd", L"?f");
if (command != impl_->current_drawing_state_.path_last_command_)
{
impl_->current_drawing_state_.path_ += command;
@ -1258,19 +1290,179 @@ void odf_drawing_context::add_path_element(std::wstring command, const std::wstr
impl_->current_drawing_state_.path_last_command_ = command;
}
if (command != L"N")
impl_->current_drawing_state_.path_ += strE + L" ";
else
impl_->current_drawing_state_.path_ += strE;
impl_->current_drawing_state_.path_ += strE + L" ";
if (command == L"N")
impl_->current_drawing_state_.path_last_command_.clear();
}
void odf_drawing_context::add_modifier(std::wstring modifier)
void odf_drawing_context::add_modifier (std::wstring modifier)
{
if (!impl_->current_drawing_state_.oox_shape_) return;
boost::algorithm::to_lower(modifier);
int res = modifier.find(L"val ");
if (res >=0) modifier = modifier.substr(4);
impl_->current_drawing_state_.modifiers_ += modifier + L" ";
impl_->current_drawing_state_.oox_shape_->modifiers += modifier + L" ";
}
void odf_drawing_context::set_viewBox(double W, double H)
int GetFormulaType2(const WCHAR& c1, const WCHAR& c2)
{
switch (c1)
{
case (WCHAR)'*': return 0;
case (WCHAR)'+': return ((WCHAR)'-' == c2) ? 1 : 2;
case (WCHAR)'?': return 3;
case (WCHAR)'a': return ((WCHAR)'b' == c2) ? 4 : 5;
case (WCHAR)'c': return ((WCHAR)'a' == c2) ? 6 : 7;
case (WCHAR)'m': return ((WCHAR)'a' == c2) ? 8 : (((WCHAR)'i' == c2) ? 16 : 9);
case (WCHAR)'p': return 10;
case (WCHAR)'s': return ((WCHAR)'a' == c2) ? 11 : (((WCHAR)'i' == c2) ? 12 : 13);
case (WCHAR)'t': return 14;
case (WCHAR)'v': return 15;
default:
break;
}
return 0;
}
void odf_drawing_context::set_textarea (std::wstring l, std::wstring t, std::wstring r, std::wstring b)
{
if (!impl_->current_drawing_state_.oox_shape_) return;
impl_->current_drawing_state_.oox_shape_->text_areas = l + L" " + t + L" " + r + L" " + b;
XmlUtils::replace_all(impl_->current_drawing_state_.oox_shape_->text_areas, L"gd", L"?f");
}
void odf_drawing_context::add_handle (std::wstring x, std::wstring y, std::wstring refX, std::wstring refY,
std::wstring minX, std::wstring maxX, std::wstring minY, std::wstring maxY)
{
if (!impl_->current_drawing_state_.oox_shape_) return;
oox_shape::_handle h;
XmlUtils::replace_all(x, L"gd", L"?f");
XmlUtils::replace_all(y, L"gd", L"?f");
h.position = x + L" " + y;
if (!maxX.empty()) h.x_maximum= maxX;
if (!minX.empty()) h.x_minimum= minX;
if (!maxY.empty()) h.y_maximum= maxY;
if (!minY.empty()) h.y_minimum= minY;
impl_->current_drawing_state_.oox_shape_->handles.push_back(h);
}
void odf_drawing_context::add_formula (std::wstring name, std::wstring fmla)
{
if (!impl_->current_drawing_state_.oox_shape_) return;
size_t nStart = 0;
size_t nCurrent = 0;
const wchar_t* pData = fmla.c_str();
int nFound = 0, x = 0, y = 0;
std::wstring val[4];
while (nCurrent < fmla.length())
{
if (pData[nCurrent] == (WCHAR)' ')
{
if (nStart < nCurrent)
{
if (0 == nFound)
{
if ((nCurrent - nStart) > 1)
{
x = GetFormulaType2(pData[nStart], pData[nStart + 1]);
}
else
{
x = 0;
}
}
else
{
val[nFound-1] = std::wstring( pData + nStart, (ULONG)(nCurrent - nStart));
}
nStart = nCurrent + 1;
++nFound;
}
}
++nCurrent;
}
if (nStart < nCurrent)
{
if (0 == nFound)
{
if ((nCurrent - nStart) > 1)
{
y = GetFormulaType2(pData[nStart], pData[nStart + 1]);
}
else
{
y = 0;
}
}
else
{
val[nFound-1] = std::wstring( pData + nStart, (ULONG)(nCurrent - nStart));
}
}
std::wstring odf_fmla = L"";
switch(x)
{
case 0:
odf_fmla = val[0] + L"*" + val[1] + L"/" + val[2];
break;
case 1:
odf_fmla = val[0] + L"+" + val[1] + L"-" + val[2];
break;
case 2:
odf_fmla = val[0] + L"+" + val[1];
break;
case 3:
odf_fmla = L"if(";
for (int i = 0; i < nFound - 1; i++)
{
odf_fmla += val[i] + L",";
}
odf_fmla += val[nFound-1] + L")"; break;
case 4:
odf_fmla = L"abs(" + val[0] + L")";
break;
case 7:
odf_fmla = val[0] + L"*cos(pi*(" + val[1] + L")/10800000)";
break;
case 12:
odf_fmla = val[0] + L"*sin(pi*(" + val[1] + L")/10800000)";
break;
case 13:
odf_fmla = L"sqrt(" + val[0] + L")";
break;
case 15:
odf_fmla = val[0];
break;
default:
odf_fmla = fmla;
break;
}
//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");
impl_->current_drawing_state_.oox_shape_->add(name, odf_fmla);
}
void odf_drawing_context::set_viewBox (double W, double H)
{
if (W < 0.01)
{
@ -1282,7 +1474,15 @@ void odf_drawing_context::set_viewBox(double W, double H)
if (impl_->current_drawing_state_.svg_height_)
H = impl_->current_drawing_state_.svg_height_->get_value_unit(length::emu);
}
impl_->current_drawing_state_.view_box_ = std::wstring(L"0 0 ") + boost::lexical_cast<std::wstring>((int)W) + L" " + boost::lexical_cast<std::wstring>((int)H);
impl_->current_drawing_state_.view_box_ = std::wstring(L"0 0 ") + std::to_wstring((int)W) + L" " + std::to_wstring((int)H);
if (impl_->current_drawing_state_.oox_shape_)
{
if (impl_->current_drawing_state_.oox_shape_->sub_view_size)
impl_->current_drawing_state_.oox_shape_->sub_view_size = *impl_->current_drawing_state_.oox_shape_->sub_view_size + L" " + std::to_wstring((int)W) + L" " + std::to_wstring((int)H);
else
impl_->current_drawing_state_.oox_shape_->sub_view_size = std::to_wstring((int)W) + L" " + std::to_wstring((int)H);
}
}
void odf_drawing_context::set_flip_H(bool bVal)
{

View File

@ -139,6 +139,7 @@ public:
void start_object(std::wstring name);
void end_object();
bool isLineShape();
void corrected_line_fill();
office_element_ptr & get_root_element();
@ -149,8 +150,12 @@ public:
bool is_exist_content();
//////////////////////////////////////////////////////////////////////////////////////
void set_path (std::wstring path_string);
void add_path_element (std::wstring command, const std::wstring & elm);
void add_path_element (std::wstring command, std::wstring elm);
void add_modifier (std::wstring modifier);
void add_formula (std::wstring name, std::wstring fmla);
void set_textarea (std::wstring l, std::wstring t, std::wstring r, std::wstring b);
void add_handle (std::wstring x, std::wstring y, std::wstring refX, std::wstring refY,
std::wstring minX, std::wstring maxX, std::wstring minY, std::wstring maxY);
void set_viewBox (double W, double H);

View File

@ -136,5 +136,40 @@ void odp_conversion_context::start_image(const std::wstring & image_file_name)
current_slide().drawing_context()->start_image(odf_ref_name);
}
void odp_conversion_context::start_comment(int oox_comm_id)
{
office_element_ptr comm_elm;
create_element(L"office", L"annotation", comm_elm, this);
current_slide().comment_context()->start_comment(comm_elm, oox_comm_id);
current_slide().drawing_context()->start_drawing();
current_slide().drawing_context()->start_element(comm_elm);
}
void odp_conversion_context::start_comment_content()
{
current_slide().comment_context()->start_comment_content();
office_element_ptr & root_comm_element = current_slide().drawing_context()->get_current_element();
start_text_context();
text_context()->start_element(root_comm_element);
text_context()->start_paragraph();
}
void odp_conversion_context::end_comment_content()
{
text_context()->end_paragraph();
current_slide().comment_context()->end_comment_content();
text_context()->end_element();
end_text_context();
}
void odp_conversion_context::end_comment()
{
current_slide().drawing_context()->end_element();
current_slide().drawing_context()->end_drawing();
}
}
}

View File

@ -67,12 +67,18 @@ public:
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();}
void start_drawings();
void end_drawings();
virtual void start_image(const std::wstring & image_file_name);
void start_comment (int oox_comment_id);
void end_comment ();
void start_comment_content ();
void end_comment_content ();
private:
odp_slide_context slide_context_;

View File

@ -58,7 +58,7 @@ namespace odf_writer {
///////////////////////////////////////////////////////////////
odp_page_state::odp_page_state(odf_conversion_context * Context, office_element_ptr & elm)
: context_(Context), drawing_context_(Context)
: context_(Context), drawing_context_(Context), comment_context_(Context)
{
page_elm_ = elm;

View File

@ -40,11 +40,11 @@
#include"../../../Common/DocxFormat/Source/XML/Utils.h"
#include "odf_drawing_context.h"
#include "odf_comment_context.h"
#include "office_elements_create.h"
namespace cpdoccore {
namespace odf_types
@ -57,7 +57,6 @@ namespace odf_writer {
class odp_conversion_context;
class odf_text_context;
//class table_table;
class style;
@ -85,6 +84,7 @@ public:
///////////////////////////////
odf_drawing_context * drawing_context(){return &drawing_context_;}
odf_comment_context * comment_context(){return &comment_context_;}
std::wstring office_page_name_;
office_element_ptr page_elm_;
@ -94,6 +94,7 @@ private:
odf_conversion_context * context_;
odf_drawing_context drawing_context_;
odf_comment_context comment_context_;
friend class odp_slide_context;

View File

@ -58,7 +58,6 @@ public:
odp_page_state & state();
odf_comment_context * comment_context();
odf_table_context * table_context();
void start_table ();

View File

@ -238,11 +238,11 @@ void ods_conversion_context::end_row()
//////////////////////
void ods_conversion_context::start_comment(int col, int row, std::wstring & author)
{
current_table().start_comment(col,row,author);
current_table().start_comment(col, row, author);
start_text_context();
////////////////
office_element_ptr paragr_elm;
create_element(L"text", L"p",paragr_elm,this);
create_element(L"text", L"p", paragr_elm, this);
current_text_context_->start_paragraph(paragr_elm);
}
@ -309,7 +309,7 @@ void ods_conversion_context::add_merge_cells(const std::wstring & ref)
void ods_conversion_context::start_cell(std::wstring & ref, int xfd_style)
{
int col=0, row=0;
int col = 0, row = 0;
utils::parsing_ref ( ref, col,row);
if (col > current_table().current_column()+1)
@ -389,11 +389,31 @@ void ods_conversion_context::start_rows()
void ods_conversion_context::end_rows()
{
//add default last row
int repeat = (std::max)(current_table().dimension_row,64) - current_table().current_row();
if (repeat < 0) repeat = 1;
int repeated = (std::max)(current_table().dimension_row, 64) - current_table().current_row();
if (repeated < 0) repeated = 1;
start_row(current_table().current_row()+1,repeat,0,true);
end_row();
while(true)
{
//делим на 3 - до, с комметом, после;
int comment_idx = current_table().is_row_comment(current_table().current_row() + 1, repeated);
if (comment_idx < 0) break;
int rows = current_table().comments_[comment_idx].row - current_table().current_row() - 1;
start_row(current_table().current_row() + 1, rows, 0, true);
end_row();
start_row(current_table().current_row() + 1, 1, 0, true);
end_row();
repeated -= (1 + rows);
}
if (repeated > 0)
{
start_row(current_table().current_row() + 1, repeated, 0, true);
end_row();
}
}
void ods_conversion_context::add_column(int start_column, int repeated, int level, bool _default)

View File

@ -136,8 +136,8 @@ ods_table_state::ods_table_state(odf_conversion_context * Context, office_elemen
{
office_table_ = elm;
current_table_row_ =0;
current_table_column_ =0;
current_table_row_ = 0;
current_table_column_ = 0;
current_level_.push_back(office_table_);
@ -395,7 +395,7 @@ bool ods_table_state::is_cell_hyperlink()
bool ods_table_state::is_cell_comment()
{
if (cells_size_ <1)return false;
return cells_.back().comment_idx >=0 ? true : false;
return cells_.back().comment_idx >= 0 ? true : false;
}
int ods_table_state::is_cell_hyperlink(int col, int row)
@ -413,7 +413,18 @@ int ods_table_state::is_cell_comment(int col, int row, short repeate_col)
{
for (size_t i = 0; i < comments_.size(); i++)
{
if ((comments_[i].col < col+repeate_col && comments_[i].col >= col) && comments_[i].row == row)
if ((comments_[i].col < col + repeate_col && comments_[i].col >= col) && comments_[i].row == row)
{
return i;
}
}
return -1;
}
int ods_table_state::is_row_comment(int row, int repeate_row)
{
for (size_t i = 0; i < comments_.size(); i++)
{
if (comments_[i].row < row + repeate_row && comments_[i].row >= row)
{
return i;
}
@ -489,10 +500,10 @@ void ods_table_state::start_cell(office_element_ptr & elm, office_element_ptr &
state.empty = true;
state.elm = elm; state.repeated = 1; state.style_name = style_name; state.style_elm = style_elm;
state.row=current_table_row_; state.col =current_table_column_+1;
state.row = current_table_row_; state.col =current_table_column_ + 1;
state.hyperlink_idx = is_cell_hyperlink(state.col, state.row);
state.comment_idx = is_cell_comment(state.col, state.row);
state.comment_idx = is_cell_comment(state.col, state.row);
current_table_column_ += state.repeated;
cells_.push_back(state);
@ -1016,8 +1027,8 @@ void ods_table_state::end_cell()
void ods_table_state::add_default_cell( short repeated)
{
int comment_idx = is_cell_comment(current_table_column_+1 , current_table_row_, repeated);
if (comment_idx >=0 && repeated >1)
int comment_idx = is_cell_comment(current_table_column_ + 1 , current_table_row_, repeated);
if (comment_idx >= 0 && repeated > 1)
{
//делим на 3 - до, с комметом, после;
int c = current_table_column_;

View File

@ -300,6 +300,7 @@ public:
int is_cell_hyperlink (int col, int row);
bool is_cell_comment ();
int is_cell_comment (int col, int row, short repeate_col = 1);
int is_row_comment (int row, int repeate_row = 1);
ods_hyperlink_state & current_hyperlink();
@ -316,7 +317,8 @@ public:
odf_drawing_context * drawing_context(){return &drawing_context_;}
std::wstring office_table_name_;
std::wstring office_table_name_;
std::vector<ods_comment_state> comments_;
private:
odf_conversion_context * context_;
@ -342,9 +344,7 @@ private:
std::list<ods_cell_state> cells_;
long cells_size_;
std::vector<ods_hyperlink_state> hyperlinks_;
std::vector<ods_comment_state> comments_;
std::vector<ods_hyperlink_state> hyperlinks_;
std::vector<ods_shared_formula_state> shared_formulas_;
odf_drawing_context drawing_context_;

View File

@ -50,6 +50,12 @@
namespace cpdoccore
{
oox_shape::oox_shape()
{
odf_type_name = L"ooxml-non-primitive";
view_box = L"0 0 0 0";
}
oox_shape_ptr oox_shape::create(int ooxPrstGeomType)
{
switch (ooxPrstGeomType)
@ -127,7 +133,7 @@ oox_shape_ptr oox_shape::create(int ooxPrstGeomType)
default:
if (ooxPrstGeomType > 2000) return boost::make_shared<oox_shape_textPlain>();
else return boost::make_shared<oox_shape>();
else return oox_shape_ptr();
}
}

View File

@ -48,6 +48,8 @@ namespace cpdoccore
public:
static oox_shape_ptr create(int ooxPrstGeomType);
oox_shape();
struct _equation
{
std::wstring name;
@ -66,20 +68,20 @@ namespace cpdoccore
void add(std::wstring name,std::wstring frmla)
{
_equation q = {name,frmla};
_equation q = {name, frmla};
equations.push_back(q);
}
std::vector<_equation> equations;
std::vector<_handle> handles;
std::vector<_equation> equations;
std::vector<_handle> handles;
std::wstring enhanced_path;
std::wstring modifiers;
std::wstring text_areas;
std::wstring view_box;
std::wstring enhanced_path;
std::wstring modifiers;
std::wstring text_areas;
std::wstring view_box;
_CP_OPT(std::wstring) sub_view_size;
_CP_OPT(std::wstring) glue_points;
std::wstring odf_type_name;
_CP_OPT(std::wstring) glue_points;
std::wstring odf_type_name;
};
};

View File

@ -372,7 +372,17 @@ void OoxConverter::convert(PPTX::Logic::CxnSp *oox_connect)
odf_context()->drawing_context()->start_drawing();
odf_context()->drawing_context()->start_shape(SimpleTypes::shapetypeLine);
int type = SimpleTypes::shapetypeLine;
if ( oox_connect->spPr.Geometry.is<PPTX::Logic::PrstGeom>() )
{
const PPTX::Logic::PrstGeom& prstGeom = oox_connect->spPr.Geometry.as<PPTX::Logic::PrstGeom>();
SimpleTypes::CShapeType<> preset;
preset.FromString(prstGeom.prst.get());
type = preset.GetValue();
}
odf_context()->drawing_context()->start_shape(type);
convert(&oox_connect->spPr, oox_connect->style.GetPointer());
convert(&oox_connect->nvCxnSpPr);
@ -462,7 +472,7 @@ void OoxConverter::convert(PPTX::Logic::SpPr *oox_spPr, PPTX::Logic::ShapeStyle*
convert(prstGeom);
convert(custGeom);
bool bLine = prstGeom ? (prstGeom->prst.get() == L"line") : false;
bool bLine = odf_context()->drawing_context()->isLineShape();
if (!bLine)
{
@ -526,19 +536,52 @@ void OoxConverter::convert(PPTX::Logic::PrstGeom *oox_geom)
for (size_t i = 0; i < oox_geom->avLst.size(); i++)
{
if (oox_geom->avLst[i].fmla.IsInit())
odf_context()->drawing_context()->add_modifier(oox_geom->avLst[i].fmla.get());
odf_context()->drawing_context()->add_modifier(oox_geom->avLst[i].fmla.get_value_or(L"0"));
}
}
void OoxConverter::convert(PPTX::Logic::CustGeom *oox_cust_geom)
{
if (!oox_cust_geom) return;
for (size_t i = 0; i < oox_cust_geom->gdLst.size(); i++)
{
odf_context()->drawing_context()->add_formula(oox_cust_geom->gdLst[i].name.get_value_or(L""), oox_cust_geom->gdLst[i].fmla.get_value_or(L""));
}
for (size_t i = 0; i < oox_cust_geom->pathLst.size(); i++)
{
convert(&oox_cust_geom->pathLst[i]);
}
for (size_t i = 0; i < oox_cust_geom->avLst.size(); i++)
{
odf_context()->drawing_context()->add_modifier(oox_cust_geom->avLst[i].fmla.get_value_or(L"0"));
}
for (size_t i = 0; i < oox_cust_geom->ahLst.size(); i++)
{
convert(oox_cust_geom->ahLst[i].ah.operator->());
}
if (oox_cust_geom->rect.IsInit())
{
odf_context()->drawing_context()->set_textarea (oox_cust_geom->rect->l.get_value_or(L"0"),
oox_cust_geom->rect->t.get_value_or(L"0"),
oox_cust_geom->rect->r.get_value_or(L"0"),
oox_cust_geom->rect->b.get_value_or(L"0"));
}
}
void OoxConverter::convert(PPTX::Logic::AhXY *oox_handle)
{
if (!oox_handle) return;
odf_context()->drawing_context()->add_handle(oox_handle->x, oox_handle->y,
oox_handle->gdRefX.get_value_or(L""), oox_handle->gdRefY.get_value_or(L""),
oox_handle->minX.get_value_or(L""), oox_handle->maxX.get_value_or(L""),
oox_handle->minX.get_value_or(L""), oox_handle->maxY.get_value_or(L""));
}
void OoxConverter::convert(PPTX::Logic::AhPolar *oox_handle)
{
if (!oox_handle) return;
}
void OoxConverter::convert(PPTX::Logic::EffectLst *oox_effect_list)
{
if (!oox_effect_list) return;
@ -609,6 +652,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"");
}
@ -616,44 +662,20 @@ void OoxConverter::convert(PPTX::Logic::PathBase *oox_path)
{
if (!oox_path) return;
PPTX::Logic::MoveTo* moveTo = dynamic_cast<PPTX::Logic::MoveTo*> (oox_path);
PPTX::Logic::LineTo* lineTo = dynamic_cast<PPTX::Logic::LineTo*> (oox_path);
PPTX::Logic::CubicBezTo* cubicBezTo = dynamic_cast<PPTX::Logic::CubicBezTo*> (oox_path);
PPTX::Logic::MoveTo* moveTo = dynamic_cast<PPTX::Logic::MoveTo*> (oox_path);
PPTX::Logic::LineTo* lineTo = dynamic_cast<PPTX::Logic::LineTo*> (oox_path);
PPTX::Logic::CubicBezTo* cubicBezTo = dynamic_cast<PPTX::Logic::CubicBezTo*>(oox_path);
PPTX::Logic::Close* close = dynamic_cast<PPTX::Logic::Close*> (oox_path);
PPTX::Logic::ArcTo* arcTo = dynamic_cast<PPTX::Logic::ArcTo*> (oox_path);
PPTX::Logic::QuadBezTo* quadBezTo = dynamic_cast<PPTX::Logic::QuadBezTo*> (oox_path);
if (moveTo)
{
std::wstring path_elm = moveTo->x + L" " + moveTo->y;
odf_context()->drawing_context()->add_path_element(std::wstring(L"M"), path_elm);
}
if (lineTo)
{
std::wstring path_elm = lineTo->x + L" " + lineTo->y;
odf_context()->drawing_context()->add_path_element(std::wstring(L"L"), path_elm);
}
if (cubicBezTo)
{
std::wstring path_elm = cubicBezTo->x[0] + L" " + cubicBezTo->y[0] + L" " +
cubicBezTo->x[1] + L" " + cubicBezTo->y[1] + L" " +
cubicBezTo->x[2] + L" " + cubicBezTo->y[2];
odf_context()->drawing_context()->add_path_element(std::wstring(L"C"), path_elm);
}
if (quadBezTo)
{
std::wstring path_elm = quadBezTo->x[0] + L" " + quadBezTo->y[0] + L" " +
quadBezTo->x[1] + L" " + quadBezTo->y[1];
odf_context()->drawing_context()->add_path_element(std::wstring(L"S"), path_elm);
}
if (arcTo)
{
}
if (close)
{
std::wstring path_elm ;
odf_context()->drawing_context()->add_path_element(std::wstring(L"Z"), path_elm);
}
if (moveTo) convert(moveTo);
if (lineTo) convert(lineTo);
if (cubicBezTo) convert(cubicBezTo);
if (quadBezTo) convert(quadBezTo);
if (arcTo) convert(arcTo);
if (close) convert(close);
}
@ -810,7 +832,7 @@ void OoxConverter::convert(PPTX::Logic::GradFill *oox_grad_fill, DWORD nARGB)
}
void OoxConverter::convert(PPTX::Logic::UniColor * color, std::wstring & hexString, _CP_OPT(double) & opacity, DWORD nARGB)
void OoxConverter::convert(PPTX::Logic::UniColor * color, DWORD & nARGB)
{
if (!color) return;
@ -818,6 +840,13 @@ void OoxConverter::convert(PPTX::Logic::UniColor * color, std::wstring & hexStri
smart_ptr<PPTX::Theme> theme(oox_theme()); theme.AddRef();
nARGB = color->GetRGBColor(theme, clrMap, nARGB);
}
void OoxConverter::convert(PPTX::Logic::UniColor * color, std::wstring & hexString, _CP_OPT(double) & opacity, DWORD nARGB)
{
if (!color) return;
convert(color, nARGB);
hexString = XmlUtils::IntToString(nARGB & 0x00FFFFFF, L"#%06X");
@ -896,7 +925,7 @@ void OoxConverter::convert(PPTX::Logic::Ln *oox_line_prop, DWORD ARGB, PPTX::Log
{
if (oox_line_prop->headEnd->len.IsInit() || oox_line_prop->headEnd->type.IsInit() || oox_line_prop->headEnd->w.IsInit())
{
int type = 0, w=1, len =1;//medium arrow
int type = 0, w = 1, len = 1;//medium arrow
if (oox_line_prop->headEnd->len.IsInit()) len = oox_line_prop->headEnd->len->GetBYTECode();
if (oox_line_prop->headEnd->type.IsInit()) type = oox_line_prop->headEnd->type->GetBYTECode();
if (oox_line_prop->headEnd->w.IsInit()) w = oox_line_prop->headEnd->w->GetBYTECode();
@ -908,7 +937,7 @@ void OoxConverter::convert(PPTX::Logic::Ln *oox_line_prop, DWORD ARGB, PPTX::Log
{
if (oox_line_prop->tailEnd->len.IsInit() || oox_line_prop->tailEnd->type.IsInit() || oox_line_prop->tailEnd->w.IsInit())
{
int type =0, w=1, len =1;//medium arrow
int type = 0, w = 1, len = 1;//medium arrow
if (oox_line_prop->tailEnd->len.IsInit()) len = oox_line_prop->tailEnd->len->GetBYTECode();
if (oox_line_prop->tailEnd->type.IsInit()) type = oox_line_prop->tailEnd->type->GetBYTECode();
if (oox_line_prop->tailEnd->w.IsInit()) w = oox_line_prop->tailEnd->w->GetBYTECode();
@ -1058,13 +1087,19 @@ void OoxConverter::convert(PPTX::Logic::Paragraph *oox_paragraph, PPTX::Logic::T
if (oox_paragraph->pPr.IsInit() || oox_list_style)
{
if (oox_paragraph->pPr.IsInit() && (oox_paragraph->pPr->lvl.IsInit() || oox_paragraph->pPr->ParagraphBullet.is_init()))
if (oox_paragraph->pPr.IsInit())
{
list_present = true;
list_level = 1;
if (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 (list_level > 0)
list_present = true;
}
}
odf_writer::style_paragraph_properties * paragraph_properties = odf_context()->text_context()->get_paragraph_properties();
@ -1416,7 +1451,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());
@ -1487,10 +1522,9 @@ void OoxConverter::convert(PPTX::Logic::ArcTo *oox_geom_path)
{
if (!oox_geom_path) return;
//std::wstring path_elm = std::to_wstring ((int)pt2emu(oox_geom_path->m_oPt.m_oX.GetValue())) +
// std::wstring(L" ")+ std::to_wstring ((int)pt2emu(oox_geom_path->m_oPt.m_oY.GetValue()));
//
//odf_context()->drawing_context()->add_path_element(std::wstring(L"A"), path_elm);
std::wstring path_elm = oox_geom_path->hR + L" " + oox_geom_path->wR + L" " + oox_geom_path->swAng + L" " + oox_geom_path->stAng;
odf_context()->drawing_context()->add_path_element(std::wstring(L"G"), path_elm);
}
void OoxConverter::convert(PPTX::Logic::QuadBezTo *oox_geom_path)
{
@ -1521,14 +1555,19 @@ void OoxConverter::convert(PPTX::Logic::Close *oox_geom_path)
void OoxConverter::convert(PPTX::Logic::StyleRef *style_ref, int type)
{
if (!style_ref) return;
DWORD nARGB = 0;
convert(&style_ref->Color, nARGB);
if (style_ref->idx.IsInit() == false)
{
std::wstring hexColor;
std::wstring hexColor = XmlUtils::IntToString(nARGB & 0x00FFFFFF, L"#%06X");
_CP_OPT(double) opacity;
convert(&style_ref->Color, hexColor, opacity);
if ((nARGB >> 24) != 0xff)
{
opacity = ((nARGB >> 24) /255.) * 100.;
}
if (type != 3) //?? todooo
{
@ -1568,14 +1607,14 @@ void OoxConverter::convert(PPTX::Logic::StyleRef *style_ref, int type)
}
}
convert(fill, style_ref->Color.GetARGB());
convert(fill, nARGB);
}
else if (type == 2)
{
index -= 1;
if ((index >= 0) || (index < theme->themeElements.fmtScheme.lnStyleLst.size()))
{
convert(&theme->themeElements.fmtScheme.lnStyleLst[index], style_ref->Color.GetARGB());
convert(&theme->themeElements.fmtScheme.lnStyleLst[index], nARGB);
}
}
else if (type == 3)

View File

@ -181,6 +181,14 @@ void OoxConverter::convert(OOX::WritingElement *oox_unknown)
{
convert(dynamic_cast<PPTX::Logic::CustGeom*>(oox_unknown));
}break;
case OOX::et_a_ahXY:
{
convert(dynamic_cast<PPTX::Logic::AhXY*>(oox_unknown));
}break;
case OOX::et_a_ahPolar:
{
convert(dynamic_cast<PPTX::Logic::AhPolar*>(oox_unknown));
}break;
case OOX::et_a_lnTo:
{
convert(dynamic_cast<PPTX::Logic::LineTo*>(oox_unknown));

View File

@ -322,6 +322,8 @@ namespace PPTX
class InnerShdw;
class OuterShdw;
class PrstShdw;
class AhXY;
class AhPolar;
}
}
@ -390,6 +392,7 @@ public:
void convert(PPTX::Logic::PathBase *oox_path);
void convert(PPTX::Logic::BodyPr *oox_bodyPr);
void convert(PPTX::Logic::UniFill *oox_fill, DWORD ARGB = 0);
void convert(PPTX::Logic::UniColor *color, DWORD & nARGB);
void convert(PPTX::Logic::UniColor *color, std::wstring & hexString, _CP_OPT(double) & opacity, DWORD ARGB = 0);
void convert(PPTX::Logic::NvSpPr *oox_nvSpPr);
void convert(PPTX::Logic::CNvPr *oox_cnvPr);
@ -417,6 +420,8 @@ public:
void convert(PPTX::Logic::QuadBezTo *oox_geom_path);
void convert(PPTX::Logic::CubicBezTo *oox_geom_path);
void convert(PPTX::Logic::Close *oox_geom_path);
void convert(PPTX::Logic::AhXY *oox_handle);
void convert(PPTX::Logic::AhPolar *oox_handle);
void convert(PPTX::Logic::EffectStyle *oox_effect);
void convert(PPTX::Logic::EffectLst *oox_effect_list);
void convert(PPTX::Logic::InnerShdw *oox_effect);

View File

@ -3392,7 +3392,7 @@ void DocxConverter::convert(OOX::Logic::CCommentRangeStart* oox_comm_start)
bool added = odt_context->start_comment(oox_comm_id);
if (added==false)
if (added == false)
{
convert_comment(oox_comm_id);
}

View File

@ -35,6 +35,7 @@
#include "../../../ASCOfficePPTXFile/PPTXFormat/Folder.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Presentation.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Slide.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Logic/Table/Table.h"
#include <boost/lexical_cast.hpp>
@ -294,15 +295,18 @@ 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;
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);
if (pFind == m_mapMasters.end())
@ -322,12 +326,12 @@ void PptxConverter::convert_slides()
//if (slide->Layout->showMasterSp.IsInit() ? *slide->Layout->showMasterSp : true)
{
current_slide = slide->Master.operator->();
convert_slide(&slide->Master->cSld, false);
convert_slide(&slide->Master->cSld, current_txStyles, false);
}
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));
@ -369,19 +373,21 @@ void PptxConverter::convert_slides()
//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->timing.GetPointer(), slide->transition.GetPointer());
//nullable<Logic::Transition> transition;
//nullable<Logic::Timing> timing;
//smart_ptr<NotesSlide> Note;
//smart_ptr<PPTX::Comments> comments;
odp_context->end_slide();
}
}
void PptxConverter::convert(PPTX::NotesSlide *oox_note)
{
if (!oox_note) return;
}
void PptxConverter::convert(OOX::WritingElement *oox_unknown)
{
if (oox_unknown == NULL)return;
@ -394,7 +400,51 @@ void PptxConverter::convert(OOX::WritingElement *oox_unknown)
}break;
}
}
void PptxConverter::convert(PPTX::Comments *oox_comments)
{
if (!oox_comments) return;
for (size_t i = 0; i < oox_comments->m_arComments.size(); i++)
{
PPTX::Logic::Comment & oox_comment = oox_comments->m_arComments[i];
odp_context->start_comment(oox_comment.idx.get_value_or(-1));
odp_context->start_comment_content();
if (oox_comment.pos_x.IsInit() && oox_comment.pos_y.IsInit())
odp_context->comment_context()->set_position (*oox_comment.pos_x / 10., *oox_comment.pos_y / 10.); //pt
if (oox_comment.authorId.IsInit() && presentation->commentAuthors.IsInit())
{
for (size_t a = 0; a < presentation->commentAuthors->m_arAuthors.size(); a++)
{
PPTX::Logic::CommentAuthor & autor = presentation->commentAuthors->m_arAuthors[a];
if (autor.id.IsInit() && autor.id.get() == oox_comment.authorId.get())
{
odp_context->comment_context()->set_author(autor.name.get_value_or(L""));
odp_context->comment_context()->set_initials(autor.initials.get_value_or(L""));
break;
}
}
}
if (oox_comment.dt.IsInit()) odp_context->comment_context()->set_date(*oox_comment.dt);
if (oox_comment.text.IsInit()) odp_context->text_context()->add_text_content(*oox_comment.text);
odp_context->end_comment_content();
odp_context->end_comment();
}
}
void PptxConverter::convert(PPTX::Logic::Timing *oox_timing, PPTX::Logic::Transition *oox_transition)
{
if (!oox_timing) return;
if (!oox_timing->tnLst.IsInit()) return;
for (size_t i = 0; i < oox_timing->tnLst->list.size(); i++)
{
//oox_timing->tnLst[0]
}
}
void PptxConverter::convert(PPTX::Logic::TableProperties *oox_table_pr)
{
if (!oox_table_pr) return;
@ -879,14 +929,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());
@ -897,13 +946,41 @@ 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);
OoxConverter::convert(&update_shape);

View File

@ -47,7 +47,9 @@ namespace OOX
namespace PPTX
{
class TableStyles;
class NotesSlide;
class Presentation;
class Comments;
class Folder;
namespace Logic
@ -63,6 +65,7 @@ namespace PPTX
class TableCell;
class TableCellProperties;
class TcBdr;
class TxStyles;
}
}
@ -103,10 +106,13 @@ namespace Oox2Odf
void convert(OOX::WritingElement *oox_unknown);
void convert_slide (PPTX::Logic::CSld *oox_slide, bool bPlaceholders = true);
void convert_layout (PPTX::Logic::CSld *oox_slide);
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::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

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Version="8.00"
Name="Oox2OdfConverter"
ProjectGUID="{BEE01B53-244A-44E6-8947-ED9342D9247E}"
RootNamespace="Oox2OdfConverter"

View File

@ -44,7 +44,7 @@ namespace PPTX
{
public:
PPTX_LOGIC_BASE(CommentAuthor)
private:
nullable_int id;
nullable_int last_idx;
nullable_int clr_idx;
@ -52,8 +52,6 @@ namespace PPTX
nullable_string name;
nullable_string initials;
public:
virtual void fromXML(XmlUtils::CXmlNode& node)
{
node.ReadAttributeBase(L"id", id);
@ -138,10 +136,9 @@ namespace PPTX
class Authors : public WrapperFile
{
private:
public:
std::vector<PPTX::Logic::CommentAuthor> m_arAuthors;
public:
Authors()
{
}
@ -152,8 +149,6 @@ namespace PPTX
virtual ~Authors()
{
}
public:
virtual void read(const OOX::CPath& filename, FileMap& map)
{
XmlUtils::CXmlNode oNode;
@ -177,8 +172,6 @@ namespace PPTX
{
WrapperFile::write(filename, directory, content);
}
public:
virtual const OOX::FileType type() const
{
return OOX::Presentation::FileTypes::CommentAuthors;
@ -191,8 +184,6 @@ namespace PPTX
{
return type().DefaultFileName();
}
public:
virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const
{
pWriter->WriteRecordArray(0, 0, m_arAuthors);

View File

@ -44,7 +44,7 @@ namespace PPTX
{
public:
PPTX_LOGIC_BASE(Comment)
private:
nullable_int authorId;
nullable_int idx;
nullable_string dt;
@ -59,8 +59,6 @@ namespace PPTX
nullable_string additional_data; // teamlab editor information!!!
public:
virtual void fromXML(XmlUtils::CXmlNode& node)
{
node.ReadAttributeBase(L"authorId", authorId);
@ -276,10 +274,9 @@ namespace PPTX
class Comments : public WrapperFile
{
private:
public:
std::vector<PPTX::Logic::Comment> m_arComments;
public:
Comments()
{
}
@ -291,7 +288,6 @@ namespace PPTX
{
}
public:
virtual void read(const OOX::CPath& filename, FileMap& map)
{
XmlUtils::CXmlNode oNode;
@ -315,7 +311,6 @@ namespace PPTX
WrapperFile::write(filename, directory, content);
}
public:
virtual const OOX::FileType type() const
{
return OOX::Presentation::FileTypes::SlideComments;
@ -328,8 +323,6 @@ namespace PPTX
{
return type().DefaultFileName();
}
public:
virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const
{
pWriter->WriteRecordArray(0, 0, m_arComments);

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;
@ -462,52 +457,10 @@ namespace PPTX
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

@ -316,7 +316,6 @@ namespace PPTX
//-------------------------------------------------------------------------------------------------
std::wstring m_name;
Shape * m_pLevelUp;
int m_nMasterTextType;
bool m_bIsFontRefInSlide;
//-------------------------------------------------------------------------------------------------
NvSpPr nvSpPr;

View File

@ -36,8 +36,11 @@
#include "../SlideMaster.h"
#include "../../ASCOfficeDrawingConverter.h"
#include "../../../XlsxSerializerCom/Reader/ChartFromToBinary.h"
#include "../../../ASCOfficeDocxFile2/DocWrapper/XlsxSerializer.h"
#include "../../../ASCOfficeDocxFile2/BinWriter/BinWriters.h"
#include "../../../Common/DocxFormat/Source/DocxFormat/Diagram/DiagramData.h"
#include "../../../Common/DocxFormat/Source/DocxFormat/Diagram/DiagramDrawing.h"
@ -86,10 +89,10 @@ namespace PPTX
}
}
if (id_drawing.IsInit())
if (id_drawing.IsInit() && pDiagramData)
{
if (parentFileIs<OOX::IFileContainer>()) oFileDrawing = parentFileAs<OOX::IFileContainer>().Find(*id_drawing);
else if (pRels != NULL) oFileDrawing = pRels->Find(*id_data);
else if (pRels != NULL) oFileDrawing = pRels->Find(*id_drawing);
}
else
{
@ -97,10 +100,7 @@ namespace PPTX
//пробуем по тому же пути с номером data.xml - ниже
}
}
if (oFileDrawing.IsInit())
{
pDiagramDrawing = dynamic_cast<OOX::CDiagramDrawing*>(oFileDrawing.operator->());
}
pDiagramDrawing = dynamic_cast<OOX::CDiagramDrawing*>(oFileDrawing.operator->());
if (!pDiagramDrawing && pDiagramData)
{
@ -122,7 +122,7 @@ namespace PPTX
m_diag = pDiagramDrawing->m_oShapeTree;
FillParentPointersForChilds();
m_pFileContainer = smart_ptr<OOX::IFileContainer>(pDiagramDrawing);
m_pFileContainer = oFileDrawing.smart_dynamic_cast<OOX::IFileContainer>();
if (!m_diag->grpSpPr.xfrm.IsInit())
m_diag->grpSpPr.xfrm = new PPTX::Logic::Xfrm;
@ -132,7 +132,22 @@ namespace PPTX
//parse pDiagramData !!
}
}
void SmartArt::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const
{
if (m_diag.is_init())
{
smart_ptr<OOX::IFileContainer> old = *pWriter->m_pCurrentContainer;
*pWriter->m_pCurrentContainer = m_pFileContainer;
if (pWriter->m_pMainDocument)
pWriter->m_pMainDocument->m_pParamsWriter->m_pCurRels = (OOX::IFileContainer*)m_pFileContainer.operator->();
m_diag->toPPTY(pWriter);
*pWriter->m_pCurrentContainer = old;
if (pWriter->m_pMainDocument)
pWriter->m_pMainDocument->m_pParamsWriter->m_pCurRels = old.operator->();
}
}
void ChartRec::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const
{
OOX::IFileContainer* pRels = NULL;

View File

@ -93,19 +93,7 @@ namespace PPTX
{
}
virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const
{
if (m_diag.is_init())
{
smart_ptr<OOX::IFileContainer> old = *pWriter->m_pCurrentContainer;
*pWriter->m_pCurrentContainer = m_pFileContainer;
m_diag->toPPTY(pWriter);
*pWriter->m_pCurrentContainer = old;
}
}
virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const;
virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader)
{
pReader->SkipRecord();

View File

@ -47,7 +47,6 @@ namespace PPTX
explicit TimeNodeBase(XmlUtils::CXmlNode& node);
const TimeNodeBase& operator =(XmlUtils::CXmlNode& node);
public:
virtual void fromXML(XmlUtils::CXmlNode& node);
virtual void GetTimeNodeFrom(XmlUtils::CXmlNode& element);
virtual bool is_init()const{return (m_node.IsInit());};
@ -61,7 +60,6 @@ namespace PPTX
template<class T> AVSINLINE const T& as() const { return m_node.as<T>(); }
virtual std::wstring toXML() const;
//public:
private:
smart_ptr<WrapperWritingElement> m_node;
protected:

View File

@ -46,7 +46,6 @@ namespace PPTX
public:
PPTX_LOGIC_BASE(Timing)
public:
virtual void fromXML(XmlUtils::CXmlNode& node)
{
tnLst = node.ReadNode(_T("p:tnLst"));
@ -76,7 +75,6 @@ namespace PPTX
pWriter->EndNode(_T("p:timing"));
}
public:
nullable<TnLst> tnLst;
nullable<BldLst> bldLst;
protected:

View File

@ -55,8 +55,6 @@ namespace PPTX
return *this;
}
public:
virtual void fromXML(XmlUtils::CXmlNode& node)
{
name = XmlUtils::GetNameNoNS(node.GetName());
@ -72,9 +70,8 @@ namespace PPTX
return XmlUtils::CreateNode(_T("p:") + name, oValue);
}
public:
std::vector<TimeNodeBase> list;
std::wstring name;
std::wstring name;
protected:
virtual void FillParentPointersForChilds()
{

View File

@ -23,7 +23,7 @@ if "%platform%" == "win_64" (
if exist "%SCRIPTPATH%%platform%\icu.zip" (
echo "icu already downloaded"
) else (
Powershell.exe Invoke-WebRequest -OutFile %platform%\icu.zip "%URL%"
Powershell.exe Invoke-WebRequest -OutFile %platform%\icu.zip -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::FireFox "%URL%"
)
SET UNSIP_PROGRAMM="C:\Program Files\7-Zip\7z.exe"

View File

@ -0,0 +1,274 @@
/**
* XML Security Library example: Signing a file with a dynamicaly created template and an X509 certificate.
*
* Signs a file using a dynamicaly created template, key from PEM file and
* an X509 certificate. The signature has one reference with one enveloped
* transform to sign the whole document except the <dsig:Signature/> node
* itself. The key certificate is written in the <dsig:X509Data/> node.
*
* This example was developed and tested with OpenSSL crypto library. The
* certificates management policies for another crypto library may break it.
*
* Usage:
* sign3 <xml-doc> <pem-key>
*
* Example:
* ./sign3 sign3-doc.xml rsakey.pem rsacert.pem > sign3-res.xml
*
* The result signature could be validated using verify3 example:
* ./verify3 sign3-res.xml ca2cert.pem cacert.pem
*
* This is free software; see Copyright file in the source
* distribution for preciese wording.
*
* Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#ifndef XMLSEC_NO_XSLT
#include <libxslt/xslt.h>
#include <libxslt/security.h>
#endif /* XMLSEC_NO_XSLT */
#include <xmlsec/xmlsec.h>
#include <xmlsec/xmltree.h>
#include <xmlsec/xmldsig.h>
#include <xmlsec/templates.h>
#include <xmlsec/crypto.h>
int sign_file(const char* xml_file, const char* key_file, const char* cert_file);
int
main(int argc, char **argv) {
#ifndef XMLSEC_NO_XSLT
xsltSecurityPrefsPtr xsltSecPrefs = NULL;
#endif /* XMLSEC_NO_XSLT */
assert(argv);
if(argc != 4) {
fprintf(stderr, "Error: wrong number of arguments.\n");
fprintf(stderr, "Usage: %s <xml-file> <key-file> <cert-file>\n", argv[0]);
return(1);
}
/* Init libxml and libxslt libraries */
xmlInitParser();
//LIBXML_TEST_VERSION
//xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
xmlSubstituteEntitiesDefault(1);
#ifndef XMLSEC_NO_XSLT
xmlIndentTreeOutput = 1;
#endif /* XMLSEC_NO_XSLT */
/* Init libxslt */
#ifndef XMLSEC_NO_XSLT
/* disable everything */
xsltSecPrefs = xsltNewSecurityPrefs();
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_READ_FILE, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_WRITE_FILE, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_CREATE_DIRECTORY, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_READ_NETWORK, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_WRITE_NETWORK, xsltSecurityForbid);
xsltSetDefaultSecurityPrefs(xsltSecPrefs);
#endif /* XMLSEC_NO_XSLT */
/* Init xmlsec library */
if(xmlSecInit() < 0) {
fprintf(stderr, "Error: xmlsec initialization failed.\n");
return(-1);
}
/* Check loaded library version */
if(xmlSecCheckVersion() != 1) {
fprintf(stderr, "Error: loaded xmlsec library version is not compatible.\n");
return(-1);
}
/* Load default crypto engine if we are supporting dynamic
* loading for xmlsec-crypto libraries. Use the crypto library
* name ("openssl", "nss", etc.) to load corresponding
* xmlsec-crypto library.
*/
#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
if(xmlSecCryptoDLLoadLibrary(NULL) < 0) {
fprintf(stderr, "Error: unable to load default xmlsec-crypto library. Make sure\n"
"that you have it installed and check shared libraries path\n"
"(LD_LIBRARY_PATH) envornment variable.\n");
return(-1);
}
#endif /* XMLSEC_CRYPTO_DYNAMIC_LOADING */
/* Init crypto library */
if(xmlSecCryptoAppInit(NULL) < 0) {
fprintf(stderr, "Error: crypto initialization failed.\n");
return(-1);
}
/* Init xmlsec-crypto library */
if(xmlSecCryptoInit() < 0) {
fprintf(stderr, "Error: xmlsec-crypto initialization failed.\n");
return(-1);
}
if(sign_file(argv[1], argv[2], argv[3]) < 0) {
return(-1);
}
/* Shutdown xmlsec-crypto library */
xmlSecCryptoShutdown();
/* Shutdown crypto library */
xmlSecCryptoAppShutdown();
/* Shutdown xmlsec library */
xmlSecShutdown();
/* Shutdown libxslt/libxml */
#ifndef XMLSEC_NO_XSLT
xsltFreeSecurityPrefs(xsltSecPrefs);
xsltCleanupGlobals();
#endif /* XMLSEC_NO_XSLT */
xmlCleanupParser();
return(0);
}
/**
* sign_file:
* @xml_file: the XML file name.
* @key_file: the PEM private key file name.
* @cert_file: the x509 certificate PEM file.
*
* Signs the @xml_file using private key from @key_file and dynamicaly
* created enveloped signature template. The certificate from @cert_file
* is placed in the <dsig:X509Data/> node.
*
* Returns 0 on success or a negative value if an error occurs.
*/
int
sign_file(const char* xml_file, const char* key_file, const char* cert_file) {
xmlDocPtr doc = NULL;
xmlNodePtr signNode = NULL;
xmlNodePtr refNode = NULL;
xmlNodePtr keyInfoNode = NULL;
xmlNodePtr x509DataNode = NULL;
xmlSecDSigCtxPtr dsigCtx = NULL;
int res = -1;
assert(xml_file);
assert(key_file);
assert(cert_file);
/* load doc file */
doc = xmlParseFile(xml_file);
if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)){
fprintf(stderr, "Error: unable to parse file \"%s\"\n", xml_file);
goto done;
}
/* create signature template for RSA-SHA1 enveloped signature */
signNode = xmlSecTmplSignatureCreate(doc, xmlSecTransformExclC14NId,
xmlSecTransformRsaSha1Id, NULL);
if(signNode == NULL) {
fprintf(stderr, "Error: failed to create signature template\n");
goto done;
}
/* add <dsig:Signature/> node to the doc */
xmlAddChild(xmlDocGetRootElement(doc), signNode);
/* add reference */
refNode = xmlSecTmplSignatureAddReference(signNode, xmlSecTransformSha1Id,
NULL, NULL, NULL);
if(refNode == NULL) {
fprintf(stderr, "Error: failed to add reference to signature template\n");
goto done;
}
/* add enveloped transform */
if(xmlSecTmplReferenceAddTransform(refNode, xmlSecTransformEnvelopedId) == NULL) {
fprintf(stderr, "Error: failed to add enveloped transform to reference\n");
goto done;
}
/* add <dsig:KeyInfo/> and <dsig:X509Data/> */
keyInfoNode = xmlSecTmplSignatureEnsureKeyInfo(signNode, NULL);
if(keyInfoNode == NULL) {
fprintf(stderr, "Error: failed to add key info\n");
goto done;
}
x509DataNode = xmlSecTmplKeyInfoAddX509Data(keyInfoNode);
if(x509DataNode == NULL) {
fprintf(stderr, "Error: failed to add X509Data node\n");
goto done;
}
if(xmlSecTmplX509DataAddSubjectName(x509DataNode) == NULL) {
fprintf(stderr, "Error: failed to add X509SubjectName node\n");
goto done;
}
if(xmlSecTmplX509DataAddCertificate(x509DataNode) == NULL) {
fprintf(stderr, "Error: failed to add X509Certificate node\n");
goto done;
}
/* create signature context, we don't need keys manager in this example */
dsigCtx = xmlSecDSigCtxCreate(NULL);
if(dsigCtx == NULL) {
fprintf(stderr,"Error: failed to create signature context\n");
goto done;
}
/* load private key, assuming that there is not password */
dsigCtx->signKey = xmlSecCryptoAppKeyLoad(key_file, xmlSecKeyDataFormatPem, NULL, NULL, NULL);
if(dsigCtx->signKey == NULL) {
fprintf(stderr,"Error: failed to load private pem key from \"%s\"\n", key_file);
goto done;
}
/* load certificate and add to the key */
if(xmlSecCryptoAppKeyCertLoad(dsigCtx->signKey, cert_file, xmlSecKeyDataFormatPem) < 0) {
fprintf(stderr,"Error: failed to load pem certificate \"%s\"\n", cert_file);
goto done;
}
/* set key name to the file name, this is just an example! */
if(xmlSecKeySetName(dsigCtx->signKey, (const xmlChar*)key_file) < 0) {
fprintf(stderr,"Error: failed to set key name for key from \"%s\"\n", key_file);
goto done;
}
/* sign the template */
if(xmlSecDSigCtxSign(dsigCtx, signNode) < 0) {
fprintf(stderr,"Error: signature failed\n");
goto done;
}
/* print signed document to stdout */
xmlDocDump(stdout, doc);
/* success */
res = 0;
done:
/* cleanup */
if(dsigCtx != NULL) {
xmlSecDSigCtxDestroy(dsigCtx);
}
if(doc != NULL) {
xmlFreeDoc(doc);
}
return(res);
}

View File

@ -0,0 +1,45 @@
QT -= core gui
TARGET = test
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
DEFINES += UNICODE
CORE_ROOT_DIR = $$PWD/../../../..
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
#DEFINES += XMLSEC_CRYPTO_DYNAMIC_LOADING
DEFINES += XMLSEC_CRYPTO_MSCRYPTO
INCLUDEPATH += \
$$CORE_ROOT_DIR/DesktopEditor/xml/libxml2/include \
$$CORE_ROOT_DIR/DesktopEditor/xml/libxml2/include/libxml \
\
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/xmlsec/include
DEFINES += \
LIBXML_READER_ENABLED \
LIBXML_PUSH_ENABLED \
LIBXML_HTML_ENABLED \
LIBXML_XPATH_ENABLED \
LIBXML_OUTPUT_ENABLED \
LIBXML_C14N_ENABLED \
LIBXML_SAX1_ENABLED \
LIBXML_TREE_ENABLED \
LIBXML_XPTR_ENABLED
DEFINES += XMLSEC_NO_XSLT
DEFINES += XMLSEC_STATIC
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -llibxmlsec
LIBS += -lcrypt32
LIBS += -lcryptui
LIBS += -lAdvapi32
SOURCES += main.cpp

View File

@ -0,0 +1,426 @@
#include <stdio.h>
#include <windows.h>
#include <wincrypt.h>
#include <cryptuiapi.h>
#include <tchar.h>
#include <string>
#include "../../../common/File.h"
#pragma comment (lib, "crypt32.lib")
#pragma comment (lib, "cryptui.lib")
#pragma comment (lib, "Advapi32.lib")
//#define ENUMS_CERTS
#define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
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 main(void)
{
//-------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// This program lists all of the certificates in a system certificate
// store and all of the property identifier numbers of those
// certificates. It also demonstrates the use of two
// UI functions. One, CryptUIDlgSelectCertificateFromStore,
// displays the certificates in a store
// and allows the user to select one of them,
// The other, CryptUIDlgViewContext,
// displays the contents of a single certificate.
//-------------------------------------------------------------------
// Declare and initialize variables.
HCERTSTORE hCertStore;
PCCERT_CONTEXT pCertContext=NULL;
char pszNameString[256];
char pszStoreName[256];
void* pvData;
DWORD cbData;
DWORD dwPropId = 0;
// Zero must be used on the first
// call to the function. After that,
// the last returned property identifier is passed.
//-------------------------------------------------------------------
// Begin processing and Get the name of the system certificate store
// to be enumerated. Output here is to stderr so that the program
// can be run from the command line and stdout can be redirected
// to a file.
/*
fprintf(stderr,"Please enter the store name:");
gets_s(pszStoreName, sizeof(pszStoreName));
fprintf(stderr,"The store name is %s.\n",pszStoreName);
*/
pszStoreName[0] = 'M';
pszStoreName[1] = 'Y';
pszStoreName[2] = '\0';
//-------------------------------------------------------------------
// Open a system certificate store.
if ( hCertStore = CertOpenSystemStore(NULL, pszStoreName))
{
fprintf(stderr,"The %s store has been opened. \n", pszStoreName);
}
else
{
// If the store was not opened, exit to an error routine.
MyHandleError("The store was not opened.");
}
//-------------------------------------------------------------------
// Use CertEnumCertificatesInStore to get the certificates
// from the open store. pCertContext must be reset to
// NULL to retrieve the first certificate in the store.
// pCertContext = NULL;
#ifdef ENUMS_CERTS
while(pCertContext= CertEnumCertificatesInStore(
hCertStore,
pCertContext))
{
//-------------------------------------------------------------------
// A certificate was retrieved. Continue.
//-------------------------------------------------------------------
// Display the certificate.
if ( CryptUIDlgViewContext(
CERT_STORE_CERTIFICATE_CONTEXT,
pCertContext,
NULL,
NULL,
0,
NULL))
{
// printf("OK\n");
}
else
{
MyHandleError("UI failed.");
}
if(CertGetNameString(
pCertContext,
CERT_NAME_SIMPLE_DISPLAY_TYPE,
0,
NULL,
pszNameString,
128))
{
printf("\nCertificate for %s \n",pszNameString);
}
else
fprintf(stderr,"CertGetName failed. \n");
//-------------------------------------------------------------------
// Loop to find all of the property identifiers for the specified
// certificate. The loop continues until
// CertEnumCertificateContextProperties returns zero.
while(dwPropId = CertEnumCertificateContextProperties(
pCertContext, // The context whose properties are to be listed.
dwPropId)) // Number of the last property found.
// This must be zero to find the first
// property identifier.
{
//-------------------------------------------------------------------
// When the loop is executed, a property identifier has been found.
// Print the property number.
printf("Property # %d found->", dwPropId);
//-------------------------------------------------------------------
// Indicate the kind of property found.
switch(dwPropId)
{
case CERT_FRIENDLY_NAME_PROP_ID:
{
printf("Display name: ");
break;
}
case CERT_SIGNATURE_HASH_PROP_ID:
{
printf("Signature hash identifier ");
break;
}
case CERT_KEY_PROV_HANDLE_PROP_ID:
{
printf("KEY PROVE HANDLE");
break;
}
case CERT_KEY_PROV_INFO_PROP_ID:
{
printf("KEY PROV INFO PROP ID ");
break;
}
case CERT_SHA1_HASH_PROP_ID:
{
printf("SHA1 HASH identifier");
break;
}
case CERT_MD5_HASH_PROP_ID:
{
printf("md5 hash identifier ");
break;
}
case CERT_KEY_CONTEXT_PROP_ID:
{
printf("KEY CONTEXT PROP identifier");
break;
}
case CERT_KEY_SPEC_PROP_ID:
{
printf("KEY SPEC PROP identifier");
break;
}
case CERT_ENHKEY_USAGE_PROP_ID:
{
printf("ENHKEY USAGE PROP identifier");
break;
}
case CERT_NEXT_UPDATE_LOCATION_PROP_ID:
{
printf("NEXT UPDATE LOCATION PROP identifier");
break;
}
case CERT_PVK_FILE_PROP_ID:
{
printf("PVK FILE PROP identifier ");
break;
}
case CERT_DESCRIPTION_PROP_ID:
{
printf("DESCRIPTION PROP identifier ");
break;
}
case CERT_ACCESS_STATE_PROP_ID:
{
printf("ACCESS STATE PROP identifier ");
break;
}
case CERT_SMART_CARD_DATA_PROP_ID:
{
printf("SMART_CARD DATA PROP identifier ");
break;
}
case CERT_EFS_PROP_ID:
{
printf("EFS PROP identifier ");
break;
}
case CERT_FORTEZZA_DATA_PROP_ID:
{
printf("FORTEZZA DATA PROP identifier ");
break;
}
case CERT_ARCHIVED_PROP_ID:
{
printf("ARCHIVED PROP identifier ");
break;
}
case CERT_KEY_IDENTIFIER_PROP_ID:
{
printf("KEY IDENTIFIER PROP identifier ");
break;
}
case CERT_AUTO_ENROLL_PROP_ID:
{
printf("AUTO ENROLL identifier. ");
break;
}
} // End switch.
//-------------------------------------------------------------------
// Retrieve information on the property by first getting the
// property size.
// For more information, see CertGetCertificateContextProperty.
if(CertGetCertificateContextProperty(
pCertContext,
dwPropId ,
NULL,
&cbData))
{
// Continue.
}
else
{
// If the first call to the function failed,
// exit to an error routine.
MyHandleError("Call #1 to GetCertContextProperty failed.");
}
//-------------------------------------------------------------------
// The call succeeded. Use the size to allocate memory
// for the property.
if(pvData = (void*)malloc(cbData))
{
// Memory is allocated. Continue.
}
else
{
// If memory allocation failed, exit to an error routine.
MyHandleError("Memory allocation failed.");
}
//----------------------------------------------------------------
// Allocation succeeded. Retrieve the property data.
if(CertGetCertificateContextProperty(
pCertContext,
dwPropId,
pvData,
&cbData))
{
// The data has been retrieved. Continue.
}
else
{
// If an error occurred in the second call,
// exit to an error routine.
MyHandleError("Call #2 failed.");
}
//---------------------------------------------------------------
// Show the results.
printf("The Property Content is %d \n", pvData);
//----------------------------------------------------------------
// Free the certificate context property memory.
free(pvData);
} // End inner while.
} // End outer while.
#endif
//-------------------------------------------------------------------
// Select a new certificate by using the user interface.
if(!(pCertContext = CryptUIDlgSelectCertificateFromStore(hCertStore, NULL, NULL, NULL, CRYPTUI_SELECT_LOCATION_COLUMN, 0, NULL)))
{
MyHandleError("Select UI failed." );
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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");
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CertFreeCertificateContext(pCertContext);
CertCloseStore(hCertStore,0);
printf("The function completed successfully. \n");
}
void MyHandleError(LPTSTR psz)
{
_ftprintf(stderr, TEXT("An error occurred in the program. \n"));
_ftprintf(stderr, TEXT("%s\n"), psz);
_ftprintf(stderr, TEXT("Error number %x.\n"), GetLastError());
_ftprintf(stderr, TEXT("Program terminating. \n"));
exit(1);
} // End of MyHandleError.
bool Sign(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFileXml, std::wstring sSignatureFile)
{
// Variables
HCRYPTPROV hCryptProv = NULL;
DWORD dwKeySpec = 0;
HCRYPTHASH hHash = NULL;
BOOL bResult = FALSE;
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);
// Create the hash object.
bResult = CryptCreateHash(hCryptProv, CALG_SHA1, 0, 0, &hHash);
BYTE* pDataSrc = NULL;
DWORD dwFileSrcLen = 0;
NSFile::CFileBinary::ReadAllBytes(sFileXml, &pDataSrc, dwFileSrcLen);
bResult = CryptHashData(hHash, pDataSrc, dwFileSrcLen, 0);
// Sign the hash object
dwSigLen = 0;
bResult = CryptSignHash(hHash, dwKeySpec, NULL, 0, NULL, &dwSigLen);
pbSignature = new BYTE[dwSigLen];
bResult = CryptSignHash(hHash, dwKeySpec, NULL, 0, pbSignature, &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);
oFile.WriteFile((BYTE*)pBase64, (DWORD)nBase64Len);
oFile.CloseFile();
delete[] pbSignature;
delete[] pDataSrc;
bResult = CryptDestroyHash(hHash);
return (bResult == TRUE);
}
bool Verify(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFileXml, std::wstring sSignatureFile)
{
DWORD dwKeySpec = 0;
HCRYPTPROV hCryptProv = NULL;
HCRYPTHASH hHash = NULL;
HCRYPTKEY hPubKey = NULL;
BOOL bResult = CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
// Create the hash object.
bResult = CryptCreateHash(hCryptProv, CALG_SHA1, 0, 0, &hHash);
BYTE* pDataSrc = NULL;
DWORD dwFileSrcLen = 0;
NSFile::CFileBinary::ReadAllBytes(sFileXml, &pDataSrc, dwFileSrcLen);
BYTE* pDataHashBase64 = NULL;
DWORD dwFileHashSrcLenBase64 = 0;
NSFile::CFileBinary::ReadAllBytes(sSignatureFile, &pDataHashBase64, dwFileHashSrcLenBase64);
BYTE* pDataHash = NULL;
DWORD dwHashLen = 0;
int nTmp = 0;
NSFile::CBase64Converter::Decode((char*)pDataHashBase64, (int)dwFileHashSrcLenBase64, pDataHash, nTmp);
dwHashLen = (DWORD)nTmp;
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);
delete[] pDataSrc;
delete[] pDataHash;
delete[] pDataHashBase64;
bResult = CryptDestroyHash(hHash);
return bResult;
}

View File

@ -0,0 +1,11 @@
QT -= core gui
TARGET = test
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
DEFINES -= UNICODE
SOURCES += main.cpp