Compare commits

...

3 Commits

Author SHA1 Message Date
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
17 changed files with 966 additions and 89 deletions

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

@ -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

@ -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;
@ -1106,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;
@ -1116,27 +1249,37 @@ 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())
{
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;
if (list_level > 0)
list_present = true;
}
}
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);
//свойства могут быть приписаны не только к параграфу, но и к самому объекту
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);
@ -1144,37 +1287,38 @@ void OoxConverter::convert(PPTX::Logic::Paragraph *oox_paragraph, PPTX::Logic::T
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, text_properties);
convert(oox_paragraph->pPr.GetPointer(), paragraph_properties, text_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();
@ -1186,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>());
}

View File

@ -263,6 +263,7 @@ namespace PPTX
class Theme;
namespace Logic
{
class Bullet;
class ClrMap;
class SpTreeElem;
class GraphicFrame;
@ -403,7 +404,10 @@ 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::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);

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

@ -986,9 +986,16 @@ void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxS
}
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

@ -437,7 +437,6 @@ namespace PPTX
pWriter->EndRecord();
}
void Shape::FillLevelUp()
{
if ((m_pLevelUp == NULL) && (nvSpPr.nvPr.ph.IsInit()))
@ -452,6 +451,21 @@ 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)

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;};

View File

@ -0,0 +1,435 @@
/*
* (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++)
{
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 = size - 1 - i; j > 0; --j)
tmp *= 10;
*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,26 @@ 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);
std::string sValue = int3.ToString();
}
//-------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
@ -312,8 +331,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 +361,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 +374,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 +398,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 +452,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;
}