mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Compare commits
7 Commits
core-windo
...
core/devel
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b7ad03465 | |||
| 3162bb0bfe | |||
| ec95648c43 | |||
| 72ac11ac07 | |||
| f70ea2b74f | |||
| db834666ba | |||
| 6ed0e13178 |
@ -7196,6 +7196,8 @@ namespace BinDocxRW
|
||||
}
|
||||
void WriteColorSchemeMapping(const PPTX::Logic::ClrMap& oColorSchemeMapping)
|
||||
{
|
||||
int re_index[] = {0, 1, 2, 3, 4, 5, 10, 11, 6, 7, 8, 9, 10, 6, 7};
|
||||
|
||||
int nCurPos = 0;
|
||||
std::map<std::wstring, PPTX::Limit::ColorSchemeIndex>::const_iterator pFind;
|
||||
|
||||
@ -7204,84 +7206,84 @@ namespace BinDocxRW
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::Accent1);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"accent2");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::Accent2);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"accent3");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::Accent3);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"accent4");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::Accent4);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"accent5");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::Accent5);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"accent6");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::Accent6);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"bg1");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::Bg1);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"bg2");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::Bg2);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"folHlink");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::FollowedHyperlink);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"hlink");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::Hyperlink);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"tx1");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::T1);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
pFind = oColorSchemeMapping.ColorMap.find(L"tx2");
|
||||
if(pFind != oColorSchemeMapping.ColorMap.end())
|
||||
{
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSer_ClrSchemeMappingType::T2);
|
||||
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
|
||||
m_oBcw.m_oStream.WriteBYTE(pFind->second.GetBYTECode());
|
||||
m_oBcw.m_oStream.WriteBYTE(re_index[pFind->second.GetBYTECode()]);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -85,7 +85,7 @@ void draw_page::serialize(std::wostream & _Wostream)
|
||||
{
|
||||
CP_XML_NODE_SIMPLE()
|
||||
{
|
||||
draw_page_attr_.serialize(CP_GET_XML_NODE());
|
||||
attlist_.serialize(CP_GET_XML_NODE());
|
||||
for (int i = 0; i < content_.size(); i++)
|
||||
{
|
||||
content_[i]->serialize(CP_XML_STREAM());
|
||||
@ -107,7 +107,7 @@ const wchar_t * presentation_footer_decl::name = L"footer-decl";
|
||||
// CP_XML_ATTR_OPT(L"presentation:name", presentation_name_);
|
||||
//}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------
|
||||
const wchar_t * presentation_date_time_decl::ns = L"presentation";
|
||||
const wchar_t * presentation_date_time_decl::name = L"date-time-decl";
|
||||
//
|
||||
@ -119,5 +119,33 @@ const wchar_t * presentation_date_time_decl::name = L"date-time-decl";
|
||||
//}
|
||||
//
|
||||
|
||||
//------------------------------------------------------
|
||||
const wchar_t * presentation_notes::ns = L"presentation";
|
||||
const wchar_t * presentation_notes::name = L"notes";
|
||||
|
||||
void presentation_notes::create_child_element( const std::wstring & Ns, const std::wstring & Name)
|
||||
{
|
||||
CP_CREATE_ELEMENT(content_);
|
||||
}
|
||||
void presentation_notes::add_child_element( const office_element_ptr & child_element)
|
||||
{
|
||||
content_.push_back(child_element);
|
||||
}
|
||||
|
||||
void presentation_notes::serialize(std::wostream & _Wostream)
|
||||
{
|
||||
CP_XML_WRITER(_Wostream)
|
||||
{
|
||||
CP_XML_NODE_SIMPLE()
|
||||
{
|
||||
attlist_.serialize(CP_GET_XML_NODE());
|
||||
for (int i = 0; i < content_.size(); i++)
|
||||
{
|
||||
content_[i]->serialize(CP_XML_STREAM());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ public:
|
||||
office_element_ptr_array content_;
|
||||
office_element_ptr animation_;
|
||||
|
||||
draw_page_attr draw_page_attr_;
|
||||
draw_page_attr attlist_;
|
||||
};
|
||||
|
||||
CP_REGISTER_OFFICE_ELEMENT2(draw_page);
|
||||
@ -127,6 +127,26 @@ public:
|
||||
|
||||
};
|
||||
CP_REGISTER_OFFICE_ELEMENT2(presentation_date_time_decl);
|
||||
//---------------------------------------------------------------------
|
||||
class presentation_notes : public office_element_impl<presentation_notes>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
static const wchar_t * name;
|
||||
static const xml::NodeType xml_type = xml::typeElement;
|
||||
static const ElementType type = typePresentationNotes;
|
||||
CPDOCCORE_DEFINE_VISITABLE();
|
||||
|
||||
virtual void create_child_element(const std::wstring & Ns, const std::wstring & Name);
|
||||
virtual void add_child_element( const office_element_ptr & child_element);
|
||||
|
||||
virtual void serialize(std::wostream & _Wostream);
|
||||
|
||||
office_element_ptr_array content_;
|
||||
draw_page_attr attlist_;
|
||||
};
|
||||
|
||||
CP_REGISTER_OFFICE_ELEMENT2(presentation_notes);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ void odf_master_state::set_name(std::wstring & name)
|
||||
|
||||
if (!style_)return;
|
||||
|
||||
style_->style_master_page_attlist_.style_name_ = name;
|
||||
style_->attlist_.style_name_ = name;
|
||||
}
|
||||
void odf_master_state::set_display_name(std::wstring & name)
|
||||
{
|
||||
@ -92,7 +92,7 @@ void odf_master_state::set_display_name(std::wstring & name)
|
||||
|
||||
if (!style_)return;
|
||||
|
||||
style_->style_master_page_attlist_.style_display_name_ = name;
|
||||
style_->attlist_.style_display_name_ = name;
|
||||
}
|
||||
|
||||
void odf_master_state::set_layout_style_name(std::wstring name)
|
||||
@ -101,14 +101,14 @@ void odf_master_state::set_layout_style_name(std::wstring name)
|
||||
|
||||
if (!style_)return;
|
||||
|
||||
style_->style_master_page_attlist_.style_page_layout_name_ = name;
|
||||
style_->attlist_.style_page_layout_name_ = name;
|
||||
}
|
||||
std::wstring odf_master_state::get_name()
|
||||
{
|
||||
style_master_page* style_ = dynamic_cast<style_master_page*>(elements_[0].elm.get());
|
||||
if (!style_)return L"";
|
||||
|
||||
return style_->style_master_page_attlist_.style_name_.get_value_or(L"");
|
||||
return style_->attlist_.style_name_.get_value_or(L"");
|
||||
}
|
||||
void odf_master_state::add_footer(office_element_ptr & elm)
|
||||
{
|
||||
|
||||
@ -147,7 +147,16 @@ void odp_conversion_context::end_drawings()
|
||||
{
|
||||
current_slide().drawing_context()->clear();
|
||||
}
|
||||
|
||||
void odp_conversion_context::start_note()
|
||||
{
|
||||
office_element_ptr note_elm;
|
||||
create_element(L"presentation", L"notes", note_elm, this);
|
||||
|
||||
current_slide().drawing_context()->start_drawing();
|
||||
current_slide().drawing_context()->start_element(note_elm);
|
||||
|
||||
slide_context_.start_page(note_elm);
|
||||
}
|
||||
void odp_conversion_context::start_comment(int oox_comm_id)
|
||||
{
|
||||
office_element_ptr comm_elm;
|
||||
@ -182,6 +191,15 @@ void odp_conversion_context::end_comment()
|
||||
current_slide().drawing_context()->end_element();
|
||||
current_slide().drawing_context()->end_drawing();
|
||||
}
|
||||
void odp_conversion_context::end_note()
|
||||
{
|
||||
slide_context_.end_page();
|
||||
|
||||
slide_context_.remove_page();
|
||||
|
||||
current_slide().drawing_context()->end_element();
|
||||
current_slide().drawing_context()->end_drawing();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,6 +77,9 @@ public:
|
||||
void start_comment_content ();
|
||||
void end_comment_content ();
|
||||
|
||||
void start_note();
|
||||
void end_note();
|
||||
|
||||
private:
|
||||
odp_slide_context slide_context_;
|
||||
|
||||
|
||||
@ -72,12 +72,12 @@ void odp_page_state::set_page_name(std::wstring name)
|
||||
|
||||
draw_page* page = dynamic_cast<draw_page*>(page_elm_.get());
|
||||
if (page)
|
||||
page->draw_page_attr_.draw_name_ = name;
|
||||
page->attlist_.draw_name_ = name;
|
||||
else
|
||||
{
|
||||
//style_master_page *master_page = dynamic_cast<style_master_page*>(page_elm_.get());
|
||||
//if (master_page)
|
||||
// master_page->style_master_page_attlist_.style_display_name_ = name;
|
||||
// master_page->attlist_.style_display_name_ = name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ void odp_page_state::set_layout_page(std::wstring name)
|
||||
draw_page* page = dynamic_cast<draw_page*>(page_elm_.get());
|
||||
if (page == NULL)return;
|
||||
|
||||
page->draw_page_attr_.page_layout_name_ = name;
|
||||
page->attlist_.page_layout_name_ = name;
|
||||
}
|
||||
|
||||
void odp_page_state::set_master_page(std::wstring name)
|
||||
@ -98,7 +98,7 @@ void odp_page_state::set_master_page(std::wstring name)
|
||||
draw_page* page = dynamic_cast<draw_page*>(page_elm_.get());
|
||||
if (page == NULL)return;
|
||||
|
||||
page->draw_page_attr_.master_page_name_ = name;
|
||||
page->attlist_.master_page_name_ = name;
|
||||
}
|
||||
|
||||
void odp_page_state::set_page_style(office_element_ptr & elm)
|
||||
@ -111,12 +111,18 @@ void odp_page_state::set_page_style(office_element_ptr & elm)
|
||||
|
||||
draw_page* page = dynamic_cast<draw_page*>(page_elm_.get());
|
||||
if (page)
|
||||
page->draw_page_attr_.draw_style_name_ = office_page_style_->style_name_;
|
||||
page->attlist_.draw_style_name_ = office_page_style_->style_name_;
|
||||
else
|
||||
{
|
||||
style_master_page *master_page = dynamic_cast<style_master_page*>(page_elm_.get());
|
||||
if (master_page)
|
||||
master_page->style_master_page_attlist_.draw_style_name_ = office_page_style_->style_name_;
|
||||
master_page->attlist_.draw_style_name_ = office_page_style_->style_name_;
|
||||
else
|
||||
{
|
||||
presentation_notes* notes = dynamic_cast<presentation_notes*>(page_elm_.get());
|
||||
if (notes)
|
||||
notes->attlist_.draw_style_name_ = office_page_style_->style_name_;
|
||||
}
|
||||
}
|
||||
}
|
||||
void odp_page_state::add_child_element( const office_element_ptr & child_element)
|
||||
|
||||
@ -44,8 +44,9 @@ namespace cpdoccore {
|
||||
|
||||
namespace odf_writer {
|
||||
|
||||
odp_slide_context::odp_slide_context(odp_conversion_context & Context): context_(Context), table_context_(&Context), comment_context_(&Context)
|
||||
odp_slide_context::odp_slide_context(odp_conversion_context & Context) : context_(Context), table_context_(&Context), comment_context_(&Context)
|
||||
{
|
||||
count_slides_ = 0;
|
||||
styles_context_ = Context.styles_context();
|
||||
}
|
||||
void odp_slide_context::set_styles_context(odf_style_context* styles_context)
|
||||
@ -67,17 +68,13 @@ void odp_slide_context::start_page(office_element_ptr & elm)
|
||||
{
|
||||
page_state_list_.push_back( odp_page_state(&context_, elm) );
|
||||
|
||||
std::wstring style_name_new = L"dp" + boost::lexical_cast<std::wstring>(page_state_list_.size());
|
||||
std::wstring style_name_new = L"dp" + std::to_wstring(++count_slides_);
|
||||
|
||||
office_element_ptr & style = styles_context_->add_or_find(style_name_new, style_family::DrawingPage, true);
|
||||
style->create_child_element(L"style", L"drawing-page-properties");
|
||||
|
||||
state().set_page_style(style);
|
||||
state().drawing_context()->set_styles_context(styles_context_);
|
||||
|
||||
//для свойств страницы, а не таблицы - нужно создать master-page c page layout и связать по имени со стилем таблицы
|
||||
//причем здесь, т.к. с другой стороны это ВСЕ еще свойства листа. то есть совйства листа разделить на свйства страницы и таблицы ..
|
||||
//todooo
|
||||
//????
|
||||
}
|
||||
|
||||
void odp_slide_context::end_page()
|
||||
@ -85,6 +82,11 @@ void odp_slide_context::end_page()
|
||||
state().drawing_context()->finalize(state().page_elm_);
|
||||
}
|
||||
|
||||
void odp_slide_context::remove_page()
|
||||
{
|
||||
page_state_list_.pop_back();
|
||||
}
|
||||
|
||||
odf_table_context* odp_slide_context::table_context()
|
||||
{
|
||||
return &table_context_;
|
||||
|
||||
@ -53,6 +53,8 @@ public:
|
||||
void start_page (office_element_ptr & elm);
|
||||
void end_page ();
|
||||
|
||||
void remove_page();
|
||||
|
||||
void set_styles_context(odf_style_context* styles_context);
|
||||
odf_style_context* get_styles_context();
|
||||
|
||||
@ -81,6 +83,7 @@ private:
|
||||
odf_comment_context comment_context_;
|
||||
|
||||
std::list<odp_page_state> page_state_list_;
|
||||
int count_slides_;
|
||||
|
||||
friend class odp_conversion_context;
|
||||
|
||||
|
||||
@ -157,8 +157,6 @@ enum ElementType
|
||||
typeStylePresentationPlaceholder,
|
||||
typeStyleDrawingPageProperties,
|
||||
|
||||
typePresentationNotes,
|
||||
|
||||
typeStyleColumns,
|
||||
typeStyleColumn,
|
||||
typeStyleColumnSep,
|
||||
@ -264,6 +262,7 @@ enum ElementType
|
||||
typeDrawPage,
|
||||
typePresentationFooterDecl,
|
||||
typePresentationDateTimeDecl,
|
||||
typePresentationNotes,
|
||||
|
||||
typeAnimPar,
|
||||
typeAnimSeq,
|
||||
|
||||
@ -1270,7 +1270,7 @@ void style_master_page::serialize(std::wostream & strm)
|
||||
{
|
||||
CP_XML_NODE_SIMPLE()
|
||||
{
|
||||
style_master_page_attlist_.serialize( CP_GET_XML_NODE());
|
||||
attlist_.serialize( CP_GET_XML_NODE());
|
||||
|
||||
if (style_footer_) style_footer_->serialize(CP_XML_STREAM());
|
||||
if (style_header_) style_header_->serialize(CP_XML_STREAM());
|
||||
|
||||
@ -505,7 +505,7 @@ public:
|
||||
|
||||
int find_placeHolderIndex(odf_types::presentation_class::type placeHolder,int & last_idx);
|
||||
|
||||
style_master_page_attlist style_master_page_attlist_;
|
||||
style_master_page_attlist attlist_;
|
||||
|
||||
office_element_ptr style_header_;
|
||||
office_element_ptr style_header_left_;
|
||||
|
||||
@ -1825,9 +1825,27 @@ void OoxConverter::convert(PPTX::Logic::Run *oox_run)
|
||||
|
||||
if ((oox_run->rPr.IsInit()) && (oox_run->rPr->hlinkClick.IsInit()) && (oox_run->rPr->hlinkClick->id.IsInit()))
|
||||
{
|
||||
odf_writer::style_text_properties * text_properties = odf_context()->text_context()->get_text_properties();
|
||||
|
||||
if (!text_properties->content_.fo_color_)
|
||||
{
|
||||
PPTX::Logic::UniColor colorLink;
|
||||
colorLink.Color.reset(new PPTX::Logic::SchemeClr());
|
||||
|
||||
PPTX::Logic::SchemeClr & clr = colorLink.as<PPTX::Logic::SchemeClr>();
|
||||
clr.val.set(L"hlink");
|
||||
|
||||
std::wstring strHexColor;
|
||||
_CP_OPT(double) opacity;
|
||||
convert(&colorLink, strHexColor, opacity);
|
||||
if (!strHexColor.empty())
|
||||
text_properties->content_.fo_color_ = strHexColor;
|
||||
}
|
||||
text_properties->content_.style_text_underline_type_ = odf_types::line_type::Single;
|
||||
text_properties->content_.style_text_underline_style_ = odf_types::line_style::Solid;
|
||||
|
||||
std::wstring hlink = find_link_by_id(oox_run->rPr->hlinkClick->id.get(), 2);
|
||||
odf_context()->text_context()->add_hyperlink(hlink, oox_run->GetText());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1929,17 +1947,17 @@ void OoxConverter::convert(PPTX::Logic::TxBody *oox_txBody, PPTX::Logic::ShapeSt
|
||||
for (size_t i = 0; i < oox_txBody->Paragrs.size(); i++)
|
||||
{
|
||||
convert(&oox_txBody->Paragrs[i], oox_txBody->lstStyle.GetPointer());
|
||||
|
||||
//внешние настройки для текста
|
||||
convert(oox_txBody->bodyPr.GetPointer());
|
||||
|
||||
if (oox_style)
|
||||
{
|
||||
convert(&oox_style->fontRef);
|
||||
}
|
||||
}
|
||||
odf_context()->drawing_context()->set_text( odf_context()->text_context());
|
||||
|
||||
//внешние настройки для текста
|
||||
|
||||
convert(oox_txBody->bodyPr.GetPointer());
|
||||
|
||||
if (oox_style)
|
||||
{
|
||||
convert(&oox_style->fontRef);
|
||||
}
|
||||
odf_context()->end_text_context();
|
||||
}
|
||||
void OoxConverter::convert(PPTX::Logic::ArcTo *oox_geom_path)
|
||||
|
||||
@ -412,6 +412,18 @@ void PptxConverter::convert_slides()
|
||||
void PptxConverter::convert(PPTX::NotesSlide *oox_note)
|
||||
{
|
||||
if (!oox_note) return;
|
||||
|
||||
odp_context->start_note();
|
||||
|
||||
current_slide = dynamic_cast<OOX::IFileContainer*>(oox_note);
|
||||
|
||||
if (oox_note->clrMapOvr.IsInit() && oox_note->clrMapOvr->overrideClrMapping.IsInit())
|
||||
current_clrMap = oox_note->clrMapOvr->overrideClrMapping.GetPointer();
|
||||
//current_txStyles = oox_note->Master->txStyles.GetPointer();
|
||||
|
||||
convert_slide(&oox_note->cSld, NULL, true, true);
|
||||
|
||||
odp_context->end_note();
|
||||
}
|
||||
|
||||
void PptxConverter::convert(OOX::WritingElement *oox_unknown)
|
||||
|
||||
@ -145,19 +145,21 @@ namespace PPTX
|
||||
lColorIndex._set(node.GetAttribute(_T("w:followedHyperlink"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("folHlink"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("w:hyperlink"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("hlink"), lColorIndex));
|
||||
}
|
||||
|
||||
lColorIndex._set(node.GetAttribute(_T("accent1"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent1"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("accent2"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent2"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("accent3"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent3"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("accent4"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent4"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("accent5"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent5"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("accent6"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent6"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("bg1"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("bg1"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("bg2"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("bg2"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("tx1"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("tx1"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("tx2"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("tx2"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("folHlink")));ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("folHlink"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("hlink"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("hlink"), lColorIndex));
|
||||
else
|
||||
{
|
||||
lColorIndex._set(node.GetAttribute(_T("accent1"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent1"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("accent2"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent2"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("accent3"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent3"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("accent4"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent4"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("accent5"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent5"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("accent6"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("accent6"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("bg1"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("bg1"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("bg2"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("bg2"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("tx1"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("tx1"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("tx2"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("tx2"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("folHlink")));ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("folHlink"), lColorIndex));
|
||||
lColorIndex._set(node.GetAttribute(_T("hlink"))); ColorMap.insert(std::pair<std::wstring,Limit::ColorSchemeIndex>(_T("hlink"), lColorIndex));
|
||||
}
|
||||
}
|
||||
|
||||
virtual std::wstring toXML() const
|
||||
|
||||
@ -182,12 +182,14 @@ namespace PPTX
|
||||
NSBinPptxRW::CDrawingConverter oDrawingConverter;
|
||||
NSBinPptxRW::CBinaryFileWriter* pOldWriter = oDrawingConverter.m_pBinaryWriter;
|
||||
|
||||
oDrawingConverter.m_pBinaryWriter = pWriter;
|
||||
oDrawingConverter.m_pBinaryWriter = pWriter;
|
||||
smart_ptr<OOX::IFileContainer> oldRels = oDrawingConverter.GetRels();
|
||||
oDrawingConverter.SetRels(pChart.smart_dynamic_cast<OOX::IFileContainer>());
|
||||
|
||||
BinXlsxRW::BinaryChartWriter oBinaryChartWriter(*pWriter, &oDrawingConverter);
|
||||
oBinaryChartWriter.WriteCT_ChartSpace(*pChart);
|
||||
|
||||
oDrawingConverter.SetRels(oldRels);
|
||||
oDrawingConverter.m_pBinaryWriter = pOldWriter;
|
||||
}
|
||||
std::wstring ChartRec::toXML() const
|
||||
|
||||
@ -694,6 +694,25 @@ namespace NSStringUtils
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
static void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
static void string_replaceA(std::string& text, const std::string& replaceFrom, const std::string& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::string::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _BUILD_STRING_BUILDER_CROSSPLATFORM_H_
|
||||
|
||||
@ -656,7 +656,7 @@ void main(void)
|
||||
}
|
||||
|
||||
//SignDocument(NSFile::GetProcessDirectory() + L"/ImageStamp", pCertContext, L"{39B6B9C7-60AD-45A2-9F61-40C74A24042E}");
|
||||
SignDocument(L"D:\\555", pCertContext, L"{58CBB483-BC48-4EFF-B742-44379E8D913E}");
|
||||
SignDocument(L"D:\\555", pCertContext, L"{9792D33F-AB37-4E5B-A465-481B9465818B}");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -709,10 +709,22 @@ bool Verify(PCCERT_CONTEXT pCertContext, std::wstring sFileXml, std::wstring sSi
|
||||
class COOXMLSigner
|
||||
{
|
||||
public:
|
||||
PCCERT_CONTEXT m_context;
|
||||
std::wstring m_sFolder;
|
||||
PCCERT_CONTEXT m_context;
|
||||
std::wstring m_sFolder;
|
||||
|
||||
CXmlSigner* m_signer;
|
||||
CXmlSigner* m_signer;
|
||||
|
||||
std::wstring m_date;
|
||||
std::map<std::wstring, std::wstring> m_content_types;
|
||||
std::vector<std::wstring> m_rels;
|
||||
std::vector<std::wstring> m_files;
|
||||
|
||||
NSStringUtils::CStringBuilderA m_signed_info;
|
||||
|
||||
std::wstring m_image_valid;
|
||||
std::wstring m_image_invalid;
|
||||
|
||||
std::wstring m_guid;
|
||||
|
||||
public:
|
||||
class COOXMLRelationship
|
||||
@ -882,6 +894,11 @@ public:
|
||||
m_sFolder = sFolder;
|
||||
m_context = pContext;
|
||||
m_signer = new CXmlSigner(pContext);
|
||||
|
||||
m_date = L"2017-04-21T08:30:21Z";
|
||||
|
||||
m_signed_info.WriteString("<CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>");
|
||||
m_signed_info.WriteString("<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>");
|
||||
}
|
||||
~COOXMLSigner()
|
||||
{
|
||||
@ -1028,6 +1045,126 @@ Type=\"http://schemas.openxmlformats.org/package/2006/relationships/digital-sign
|
||||
return rId;
|
||||
}
|
||||
|
||||
void ParseContentTypes()
|
||||
{
|
||||
std::wstring file = m_sFolder + L"/[Content_Types].xml";
|
||||
XmlUtils::CXmlNode oNode;
|
||||
oNode.FromXmlFile(file);
|
||||
|
||||
XmlUtils::CXmlNodes nodesDefaults;
|
||||
oNode.GetNodes(L"Default", nodesDefaults);
|
||||
|
||||
XmlUtils::CXmlNodes nodesOverrides;
|
||||
oNode.GetNodes(L"Override", nodesOverrides);
|
||||
|
||||
int nCount = nodesDefaults.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode node;
|
||||
nodesDefaults.GetAt(i, node);
|
||||
|
||||
m_content_types.insert(std::pair<std::wstring, std::wstring>(node.GetAttribute("Extension"), node.GetAttribute("ContentType")));
|
||||
}
|
||||
|
||||
nCount = nodesOverrides.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode node;
|
||||
nodesOverrides.GetAt(i, node);
|
||||
|
||||
m_content_types.insert(std::pair<std::wstring, std::wstring>(node.GetAttribute("PartName"), node.GetAttribute("ContentType")));
|
||||
}
|
||||
}
|
||||
|
||||
void Parse()
|
||||
{
|
||||
// 1) Parse Content_Types.xml
|
||||
ParseContentTypes();
|
||||
|
||||
// 2) Parse files in directory
|
||||
std::vector<std::wstring> files = NSDirectory::GetFiles(m_sFolder, true);
|
||||
|
||||
// 3) Check each file
|
||||
std::wstring sFolder = m_sFolder;
|
||||
NSStringUtils::string_replace(sFolder, L"\\", L"/");
|
||||
for (std::vector<std::wstring>::iterator i = files.begin(); i != files.end(); i++)
|
||||
{
|
||||
std::wstring sCheckFile = *i;
|
||||
NSStringUtils::string_replace(sCheckFile, L"\\", L"/");
|
||||
|
||||
if (0 != sCheckFile.find(sFolder))
|
||||
continue;
|
||||
|
||||
// make cool filename
|
||||
sCheckFile = sCheckFile.substr(sFolder.length());
|
||||
|
||||
// check needed file
|
||||
if (0 == sCheckFile.find(L"/_xmlsignatures") ||
|
||||
0 == sCheckFile.find(L"/docProps") ||
|
||||
0 == sCheckFile.find(L"/[Content_Types].xml"))
|
||||
continue;
|
||||
|
||||
// check rels and add to needed array
|
||||
std::wstring::size_type posExt = sCheckFile.rfind(L".");
|
||||
if (std::wstring::npos == posExt)
|
||||
continue;
|
||||
|
||||
std::wstring sExt = sCheckFile.substr(posExt + 1);
|
||||
if (sExt == L"rels")
|
||||
m_rels.push_back(sCheckFile);
|
||||
else
|
||||
m_files.push_back(sCheckFile);
|
||||
}
|
||||
|
||||
std::sort(m_rels.begin(), m_rels.end());
|
||||
std::sort(m_files.begin(), m_files.end());
|
||||
}
|
||||
|
||||
void WriteRelsReferences(NSStringUtils::CStringBuilder& builder)
|
||||
{
|
||||
for (std::vector<std::wstring>::iterator i = m_rels.begin(); i != m_rels.end(); i++)
|
||||
{
|
||||
builder.WriteString(GetRelsReference(*i));
|
||||
}
|
||||
}
|
||||
|
||||
void WriteFilesReferences(NSStringUtils::CStringBuilder& builder)
|
||||
{
|
||||
for (std::vector<std::wstring>::iterator i = m_files.begin(); i != m_files.end(); i++)
|
||||
{
|
||||
std::wstring sFile = *i;
|
||||
std::wstring sContentType = L"application/xml";
|
||||
|
||||
std::map<std::wstring, std::wstring>::iterator _find = m_content_types.find(sFile);
|
||||
if (_find != m_content_types.end())
|
||||
{
|
||||
sContentType = _find->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring::size_type posExt = sFile.rfind(L".");
|
||||
if (std::wstring::npos != posExt)
|
||||
{
|
||||
std::wstring sExt = sFile.substr(posExt + 1);
|
||||
|
||||
_find = m_content_types.find(sExt);
|
||||
if (_find != m_content_types.end())
|
||||
sContentType = _find->second;
|
||||
}
|
||||
}
|
||||
|
||||
builder.WriteString(GetReference(sFile, sContentType));
|
||||
}
|
||||
}
|
||||
|
||||
void WriteManifest(NSStringUtils::CStringBuilder& builder)
|
||||
{
|
||||
builder.WriteString(L"<Manifest>");
|
||||
WriteRelsReferences(builder);
|
||||
WriteFilesReferences(builder);
|
||||
builder.WriteString(L"</Manifest>");
|
||||
}
|
||||
|
||||
void CorrectContentTypes(int nCountSigsNeeds)
|
||||
{
|
||||
std::wstring file = m_sFolder + L"/[Content_Types].xml";
|
||||
@ -1098,69 +1235,55 @@ Type=\"http://schemas.openxmlformats.org/package/2006/relationships/digital-sign
|
||||
oFile.WriteFile((BYTE*)sRet.c_str(), (DWORD)sRet.length());
|
||||
oFile.CloseFile();
|
||||
}
|
||||
};
|
||||
|
||||
bool SignDocument(std::wstring sFolderOOXML, PCCERT_CONTEXT pCertContext, std::wstring sign_id)
|
||||
{
|
||||
std::wstring sFolder = NSFile::GetProcessDirectory();
|
||||
|
||||
COOXMLSigner oOOXMLSigner(sFolderOOXML, pCertContext);
|
||||
|
||||
std::string sSignedData;
|
||||
std::wstring sXmlData;
|
||||
|
||||
std::wstring sDataSign = L"2017-04-21T08:30:21Z";
|
||||
|
||||
sSignedData += "<CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>\
|
||||
<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>";
|
||||
|
||||
if (true)
|
||||
void SetGuid(const std::wstring& guid)
|
||||
{
|
||||
// idPackageObject
|
||||
std::wstring sXml = L"<Manifest>";
|
||||
|
||||
if (true)
|
||||
{
|
||||
sXml += oOOXMLSigner.GetRelsReference(L"/_rels/.rels");
|
||||
sXml += oOOXMLSigner.GetRelsReference(L"/word/_rels/document.xml.rels");
|
||||
}
|
||||
|
||||
sXml += oOOXMLSigner.GetReference(L"/word/document.xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
|
||||
sXml += oOOXMLSigner.GetReference(L"/word/fontTable.xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml");
|
||||
sXml += oOOXMLSigner.GetReference(L"/word/media/image1.emf", L"image/x-emf");
|
||||
sXml += oOOXMLSigner.GetReference(L"/word/settings.xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml");
|
||||
sXml += oOOXMLSigner.GetReference(L"/word/styles.xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml");
|
||||
sXml += oOOXMLSigner.GetReference(L"/word/theme/theme1.xml", L"application/vnd.openxmlformats-officedocument.theme+xml");
|
||||
sXml += oOOXMLSigner.GetReference(L"/word/webSettings.xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml");
|
||||
|
||||
sXml += L"</Manifest>";
|
||||
|
||||
sXml += L"<SignatureProperties><SignatureProperty Id=\"idSignatureTime\" Target=\"#idPackageSignature\">";
|
||||
sXml += (L"<mdssi:SignatureTime xmlns:mdssi=\"http://schemas.openxmlformats.org/package/2006/digital-signature\">\
|
||||
<mdssi:Format>YYYY-MM-DDThh:mm:ssTZD</mdssi:Format>\
|
||||
<mdssi:Value>" + sDataSign + L"</mdssi:Value>\
|
||||
</mdssi:SignatureTime></SignatureProperty></SignatureProperties>");
|
||||
|
||||
sXmlData += (L"<Object Id=\"idPackageObject\">" + sXml + L"</Object>");
|
||||
|
||||
sSignedData += ("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idPackageObject\">" +
|
||||
oOOXMLSigner.GetReferenceMain(sXml, L"idPackageObject", false) + "</Reference>");
|
||||
m_guid = guid;
|
||||
}
|
||||
void SetImageValid(const std::wstring& file)
|
||||
{
|
||||
m_image_valid = GetImageBase64(file);
|
||||
}
|
||||
void SetImageInvalid(const std::wstring& file)
|
||||
{
|
||||
m_image_invalid = GetImageBase64(file);
|
||||
}
|
||||
|
||||
|
||||
std::wstring sImageValid = oOOXMLSigner.GetImageBase64(sFolder + L"/../../../resources/valid.png");
|
||||
std::wstring sImageInValid = oOOXMLSigner.GetImageBase64(sFolder + L"/../../../resources/invalid.png");
|
||||
|
||||
if (true)
|
||||
std::wstring GeneratePackageObject()
|
||||
{
|
||||
// idOfficeObject
|
||||
std::wstring sXml = L"<SignatureProperties>\
|
||||
<SignatureProperty Id=\"idOfficeV1Details\" Target=\"#idPackageSignature\">\
|
||||
<SignatureInfoV1 xmlns=\"http://schemas.microsoft.com/office/2006/digsig\">\
|
||||
<SetupID>" + sign_id + L"</SetupID>\
|
||||
<SignatureText></SignatureText>\
|
||||
<SignatureImage>" + sImageValid + L"</SignatureImage>\
|
||||
<SignatureComments/>\
|
||||
NSStringUtils::CStringBuilder builder;
|
||||
WriteManifest(builder);
|
||||
|
||||
builder.WriteString(L"<SignatureProperties><SignatureProperty Id=\"idSignatureTime\" Target=\"#idPackageSignature\">");
|
||||
builder.WriteString(L"<mdssi:SignatureTime xmlns:mdssi=\"http://schemas.openxmlformats.org/package/2006/digital-signature\">");
|
||||
builder.WriteString(L"<mdssi:Format>YYYY-MM-DDThh:mm:ssTZD</mdssi:Format>");
|
||||
builder.WriteString(L"<mdssi:Value>");
|
||||
builder.WriteString(m_date);
|
||||
builder.WriteString(L"</mdssi:Value>");
|
||||
builder.WriteString(L"</mdssi:SignatureTime></SignatureProperty></SignatureProperties>");
|
||||
|
||||
std::wstring sXml = builder.GetData();
|
||||
|
||||
m_signed_info.WriteString("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idPackageObject\">");
|
||||
m_signed_info.WriteString(GetReferenceMain(sXml, L"idPackageObject", false));
|
||||
m_signed_info.WriteString("</Reference>");
|
||||
|
||||
return (L"<Object Id=\"idPackageObject\">" + sXml + L"</Object>");
|
||||
}
|
||||
std::wstring GenerateOfficeObject()
|
||||
{
|
||||
NSStringUtils::CStringBuilder builder;
|
||||
|
||||
builder.WriteString(L"<SignatureProperties><SignatureProperty Id=\"idOfficeV1Details\" Target=\"#idPackageSignature\">");
|
||||
builder.WriteString(L"<SignatureInfoV1 xmlns=\"http://schemas.microsoft.com/office/2006/digsig\">");
|
||||
builder.WriteString(L"<SetupID>");
|
||||
builder.WriteString(m_guid);
|
||||
builder.WriteString(L"</SetupID>");
|
||||
builder.WriteString(L"<SignatureText></SignatureText>");
|
||||
builder.WriteString(L"<SignatureImage>");
|
||||
builder.WriteString(m_image_valid);
|
||||
builder.WriteString(L"</SignatureImage>");
|
||||
builder.WriteString(L"<SignatureComments/>\
|
||||
<WindowsVersion>10.0</WindowsVersion>\
|
||||
<OfficeVersion>16.0</OfficeVersion>\
|
||||
<ApplicationVersion>16.0</ApplicationVersion>\
|
||||
@ -1174,33 +1297,50 @@ bool SignDocument(std::wstring sFolderOOXML, PCCERT_CONTEXT pCertContext, std::w
|
||||
<SignatureType>2</SignatureType>\
|
||||
</SignatureInfoV1>\
|
||||
</SignatureProperty>\
|
||||
</SignatureProperties>";
|
||||
</SignatureProperties>");
|
||||
|
||||
sXmlData += (L"<Object Id=\"idOfficeObject\">" + sXml + L"</Object>");
|
||||
m_signed_info.WriteString("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idOfficeObject\">");
|
||||
m_signed_info.WriteString(GetReferenceMain(builder.GetData(), L"idOfficeObject", false));
|
||||
m_signed_info.WriteString("</Reference>");
|
||||
|
||||
sSignedData += ("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idOfficeObject\">" +
|
||||
oOOXMLSigner.GetReferenceMain(sXml, L"idOfficeObject", false) + "</Reference>");
|
||||
return (L"<Object Id=\"idOfficeObject\">" + builder.GetData() + L"</Object>");
|
||||
}
|
||||
|
||||
if (true)
|
||||
std::wstring GenerateImageObject()
|
||||
{
|
||||
DWORD dwNameLen = CertGetNameStringW(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, NULL, 0);
|
||||
if (m_image_valid.empty())
|
||||
return L"";
|
||||
|
||||
m_signed_info.WriteString("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idValidSigLnImg\">");
|
||||
m_signed_info.WriteString(GetReferenceMain(m_image_valid, L"idValidSigLnImg", false));
|
||||
m_signed_info.WriteString("</Reference>");
|
||||
|
||||
m_signed_info.WriteString("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idInvalidSigLnImg\">");
|
||||
m_signed_info.WriteString(GetReferenceMain(m_image_invalid, L"idInvalidSigLnImg", false));
|
||||
m_signed_info.WriteString("</Reference>");
|
||||
|
||||
return (L"<Object Id=\"idValidSigLnImg\">" + m_image_valid + L"</Object><Object Id=\"idInvalidSigLnImg\">" + m_image_invalid + L"</Object>");
|
||||
}
|
||||
|
||||
std::wstring GenerateSignPropertiesObject()
|
||||
{
|
||||
DWORD dwNameLen = CertGetNameStringW(m_context, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, NULL, 0);
|
||||
wchar_t* pNameData = new wchar_t[dwNameLen];
|
||||
CertGetNameStringW(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, pNameData, dwNameLen);
|
||||
CertGetNameStringW(m_context, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, pNameData, dwNameLen);
|
||||
std::wstring sName(pNameData);
|
||||
RELEASEARRAYOBJECTS(pNameData);
|
||||
|
||||
int nNumberLen = (int)pCertContext->pCertInfo->SerialNumber.cbData;
|
||||
int nNumberLen = (int)m_context->pCertInfo->SerialNumber.cbData;
|
||||
BYTE* pNumberData = new BYTE[nNumberLen];
|
||||
CXmlSigner::ConvertEndian(pCertContext->pCertInfo->SerialNumber.pbData, pNumberData, (DWORD)nNumberLen);
|
||||
CXmlSigner::ConvertEndian(m_context->pCertInfo->SerialNumber.pbData, pNumberData, (DWORD)nNumberLen);
|
||||
CBigInteger oInteger(pNumberData, nNumberLen);
|
||||
delete[] pNumberData;
|
||||
|
||||
std::string sKeyA = oInteger.ToString();
|
||||
std::wstring sKey = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sKeyA.c_str(), (LONG)sKeyA.length());
|
||||
std::wstring sKey = UTF8_TO_U(sKeyA);
|
||||
|
||||
std::wstring sXml = (L"<xd:SignedSignatureProperties>\
|
||||
<xd:SigningTime>" + sDataSign + L"</xd:SigningTime>\
|
||||
<xd:SigningTime>" + m_date + L"</xd:SigningTime>\
|
||||
<xd:SigningCertificate>\
|
||||
<xd:Cert>\
|
||||
<xd:CertDigest>\
|
||||
@ -1222,74 +1362,88 @@ bool SignDocument(std::wstring sFolderOOXML, PCCERT_CONTEXT pCertContext, std::w
|
||||
sSignedXml += sXml;
|
||||
sSignedXml += L"</xd:SignedProperties>";
|
||||
|
||||
sXmlData += L"<Object><xd:QualifyingProperties xmlns:xd=\"http://uri.etsi.org/01903/v1.3.2#\" Target=\"#idPackageSignature\">\
|
||||
<xd:SignedProperties Id=\"idSignedProperties\">";
|
||||
sXmlData += sXml;
|
||||
sXmlData += L"</xd:SignedProperties></xd:QualifyingProperties></Object>";
|
||||
|
||||
sSignedData += "<Reference Type=\"http://uri.etsi.org/01903#SignedProperties\" URI=\"#idSignedProperties\">\
|
||||
<Transforms><Transform Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/></Transforms>\
|
||||
<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>";
|
||||
|
||||
std::string sXmlTmp = CXmlCanonicalizator::Execute(U_TO_UTF8(sSignedXml), XML_C14N_1_0);
|
||||
sSignedData += oOOXMLSigner.m_signer->GetHash(sXmlTmp);
|
||||
|
||||
sSignedData += "</DigestValue></Reference>";
|
||||
m_signed_info.WriteString("<Reference Type=\"http://uri.etsi.org/01903#SignedProperties\" URI=\"#idSignedProperties\">");
|
||||
m_signed_info.WriteString("<Transforms><Transform Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/></Transforms>");
|
||||
m_signed_info.WriteString("<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>");
|
||||
m_signed_info.WriteString(m_signer->GetHash(sXmlTmp));
|
||||
m_signed_info.WriteString("</DigestValue></Reference>");
|
||||
|
||||
return (L"<Object><xd:QualifyingProperties xmlns:xd=\"http://uri.etsi.org/01903/v1.3.2#\" Target=\"#idPackageSignature\">\
|
||||
<xd:SignedProperties Id=\"idSignedProperties\">" + sXml + L"</xd:SignedProperties></xd:QualifyingProperties></Object>");
|
||||
}
|
||||
|
||||
if (true)
|
||||
int AddSignatureReference()
|
||||
{
|
||||
std::wstring sXml = sImageValid;
|
||||
std::wstring sDirectory = m_sFolder + L"/_xmlsignatures";
|
||||
|
||||
sXmlData += (L"<Object Id=\"idValidSigLnImg\">" + sXml + L"</Object>");
|
||||
if (!NSDirectory::Exists(sDirectory))
|
||||
NSDirectory::CreateDirectory(sDirectory);
|
||||
|
||||
sSignedData += ("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idValidSigLnImg\">" +
|
||||
oOOXMLSigner.GetReferenceMain(sXml, L"idValidSigLnImg", false) + "</Reference>");
|
||||
if (!NSFile::CFileBinary::Exists(sDirectory + L"/origin.sigs"))
|
||||
{
|
||||
NSFile::CFileBinary oFile;
|
||||
oFile.CreateFileW(sDirectory + L"/origin.sigs");
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
if (!NSDirectory::Exists(sDirectory + L"/_rels"))
|
||||
NSDirectory::CreateDirectory(sDirectory + L"/_rels");
|
||||
|
||||
int nSignNum = GetCountSigns(sDirectory + L"/_rels/origin.sigs.rels");
|
||||
|
||||
CorrectContentTypes(nSignNum);
|
||||
|
||||
return nSignNum;
|
||||
}
|
||||
|
||||
if (true)
|
||||
void Sign()
|
||||
{
|
||||
std::wstring sXml = sImageInValid;
|
||||
Parse();
|
||||
|
||||
sXmlData += (L"<Object Id=\"idInvalidSigLnImg\">" + sXml + L"</Object>");
|
||||
std::string sSignedData;
|
||||
|
||||
sSignedData += ("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idInvalidSigLnImg\">" +
|
||||
oOOXMLSigner.GetReferenceMain(sXml, L"idInvalidSigLnImg", false) + "</Reference>");
|
||||
NSStringUtils::CStringBuilder builderMain;
|
||||
|
||||
builderMain.WriteString(GeneratePackageObject());
|
||||
builderMain.WriteString(GenerateOfficeObject());
|
||||
builderMain.WriteString(GenerateSignPropertiesObject());
|
||||
builderMain.WriteString(GenerateImageObject());
|
||||
|
||||
std::string sSignedInfoData = m_signed_info.GetData();
|
||||
std::string sSignedXml = "<SignedInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + sSignedInfoData + "</SignedInfo>";
|
||||
sSignedXml = CXmlCanonicalizator::Execute(sSignedXml, XML_C14N_1_0);
|
||||
sSignedXml = m_signer->Sign(sSignedXml);
|
||||
|
||||
NSStringUtils::CStringBuilder builderResult;
|
||||
builderResult.WriteString(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?><Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\" Id=\"idPackageSignature\"><SignedInfo>");
|
||||
builderResult.WriteString(UTF8_TO_U(sSignedInfoData));
|
||||
builderResult.WriteString(L"</SignedInfo>");
|
||||
builderResult.WriteString(L"<SignatureValue>");
|
||||
builderResult.WriteString(UTF8_TO_U(sSignedXml));
|
||||
builderResult.WriteString(L"</SignatureValue>");
|
||||
builderResult.WriteString(L"<KeyInfo><X509Data><X509Certificate>");
|
||||
builderResult.WriteString(UTF8_TO_U(m_signer->GetCertificateBase64()));
|
||||
builderResult.WriteString(L"</X509Certificate></X509Data></KeyInfo>");
|
||||
|
||||
builderResult.Write(builderMain);
|
||||
builderResult.WriteString(L"</Signature>");
|
||||
|
||||
int nSignNum = AddSignatureReference();
|
||||
|
||||
NSFile::CFileBinary::SaveToFile(m_sFolder + L"/_xmlsignatures/sig" + std::to_wstring(nSignNum) + L".xml", builderResult.GetData(), false);
|
||||
}
|
||||
};
|
||||
|
||||
std::string sXmlPrepend = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\" Id=\"idPackageSignature\"><SignedInfo>");
|
||||
sXmlPrepend += sSignedData;
|
||||
sXmlPrepend += "</SignedInfo>";
|
||||
bool SignDocument(std::wstring sFolderOOXML, PCCERT_CONTEXT pCertContext, std::wstring sign_id)
|
||||
{
|
||||
COOXMLSigner oOOXMLSigner(sFolderOOXML, pCertContext);
|
||||
|
||||
sXmlPrepend += "<SignatureValue>";
|
||||
std::string sSignedInfo = "<SignedInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + sSignedData + "</SignedInfo>";
|
||||
sSignedInfo = CXmlCanonicalizator::Execute(sSignedInfo, XML_C14N_1_0);
|
||||
sXmlPrepend += oOOXMLSigner.m_signer->Sign(sSignedInfo);
|
||||
sXmlPrepend += "</SignatureValue>";
|
||||
sXmlPrepend += ("<KeyInfo><X509Data><X509Certificate>" + oOOXMLSigner.m_signer->GetCertificateBase64() + "</X509Certificate></X509Data></KeyInfo>");
|
||||
oOOXMLSigner.SetGuid(sign_id);
|
||||
oOOXMLSigner.SetImageValid(NSFile::GetProcessDirectory() + L"/../../../resources/valid.png");
|
||||
oOOXMLSigner.SetImageInvalid(NSFile::GetProcessDirectory() + L"/../../../resources/invalid.png");
|
||||
|
||||
sXmlData = (UTF8_TO_U(sXmlPrepend) + sXmlData);
|
||||
sXmlData += L"</Signature>";
|
||||
|
||||
std::wstring sDirectory = sFolderOOXML + L"/_xmlsignatures";
|
||||
|
||||
if (!NSDirectory::Exists(sDirectory))
|
||||
NSDirectory::CreateDirectory(sDirectory);
|
||||
|
||||
if (!NSFile::CFileBinary::Exists(sDirectory + L"/origin.sigs"))
|
||||
{
|
||||
NSFile::CFileBinary oFile;
|
||||
oFile.CreateFileW(sDirectory + L"/origin.sigs");
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
if (!NSDirectory::Exists(sDirectory + L"/_rels"))
|
||||
NSDirectory::CreateDirectory(sDirectory + L"/_rels");
|
||||
|
||||
int nSignNum = oOOXMLSigner.GetCountSigns(sDirectory + L"/_rels/origin.sigs.rels");
|
||||
|
||||
oOOXMLSigner.CorrectContentTypes(nSignNum);
|
||||
|
||||
NSFile::CFileBinary::SaveToFile(sDirectory + L"/sig" + std::to_wstring(nSignNum) + L".xml", sXmlData, false);
|
||||
oOOXMLSigner.Sign();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
QT -= core
|
||||
QT -= gui
|
||||
|
||||
VERSION = 2.4.454.0
|
||||
VERSION = 2.4.455.0
|
||||
DEFINES += INTVER=$$VERSION
|
||||
|
||||
TARGET = x2t
|
||||
|
||||
@ -333,6 +333,7 @@ namespace NExtractTools
|
||||
int* m_nFormatTo;
|
||||
int* m_nCsvTxtEncoding;
|
||||
int* m_nCsvDelimiter;
|
||||
std::wstring* m_sCsvDelimiterChar;
|
||||
bool* m_bPaid;
|
||||
bool* m_bFromChanges;
|
||||
bool* m_bDontSaveAdditional;
|
||||
@ -356,6 +357,7 @@ namespace NExtractTools
|
||||
m_nFormatTo = NULL;
|
||||
m_nCsvTxtEncoding = NULL;
|
||||
m_nCsvDelimiter = NULL;
|
||||
m_sCsvDelimiterChar = NULL;
|
||||
m_bPaid = NULL;
|
||||
m_bFromChanges = NULL;
|
||||
m_bDontSaveAdditional = NULL;
|
||||
@ -379,6 +381,7 @@ namespace NExtractTools
|
||||
RELEASEOBJECT(m_nFormatTo);
|
||||
RELEASEOBJECT(m_nCsvTxtEncoding);
|
||||
RELEASEOBJECT(m_nCsvDelimiter);
|
||||
RELEASEOBJECT(m_sCsvDelimiterChar);
|
||||
RELEASEOBJECT(m_bPaid);
|
||||
RELEASEOBJECT(m_bFromChanges);
|
||||
RELEASEOBJECT(m_bDontSaveAdditional);
|
||||
@ -456,6 +459,8 @@ namespace NExtractTools
|
||||
m_nCsvTxtEncoding = new int(XmlUtils::GetInteger(sValue));
|
||||
else if(_T("m_nCsvDelimiter") == sName)
|
||||
m_nCsvDelimiter = new int(XmlUtils::GetInteger(sValue));
|
||||
else if(_T("m_nCsvDelimiterChar") == sName)
|
||||
m_sCsvDelimiterChar = new std::wstring(sValue);
|
||||
else if(_T("m_bPaid") == sName)
|
||||
m_bPaid = new bool(XmlUtils::GetBoolean2(sValue));
|
||||
else if(_T("m_bFromChanges") == sName)
|
||||
@ -475,6 +480,10 @@ namespace NExtractTools
|
||||
else if(_T("m_sPassword") == sName)
|
||||
m_sPassword = new std::wstring(sValue);
|
||||
}
|
||||
else if(_T("m_nCsvDelimiterChar") == sName)
|
||||
{
|
||||
m_sCsvDelimiterChar = new std::wstring(L"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -492,8 +501,8 @@ namespace NExtractTools
|
||||
std::wstring getXmlOptions()
|
||||
{
|
||||
std::wstring sRes;
|
||||
int nCsvEncoding = 65001; //utf8
|
||||
std::string cDelimiter = ",";
|
||||
int nCsvEncoding = 46;//65001 utf8
|
||||
std::wstring cDelimiter = L"";
|
||||
|
||||
if(NULL != m_nCsvTxtEncoding)
|
||||
nCsvEncoding = *m_nCsvTxtEncoding;
|
||||
@ -501,13 +510,17 @@ namespace NExtractTools
|
||||
{
|
||||
switch (*m_nCsvDelimiter)
|
||||
{
|
||||
case TCSVD_TAB: cDelimiter = "\t"; break;
|
||||
case TCSVD_SEMICOLON: cDelimiter = ";"; break;
|
||||
case TCSVD_COLON: cDelimiter = ":"; break;
|
||||
case TCSVD_COMMA: cDelimiter = ","; break;
|
||||
case TCSVD_SPACE: cDelimiter = " "; break;
|
||||
case TCSVD_TAB: cDelimiter = L"\t"; break;
|
||||
case TCSVD_SEMICOLON: cDelimiter = L";"; break;
|
||||
case TCSVD_COLON: cDelimiter = L":"; break;
|
||||
case TCSVD_COMMA: cDelimiter = L","; break;
|
||||
case TCSVD_SPACE: cDelimiter = L" "; break;
|
||||
}
|
||||
}
|
||||
if(NULL != m_sCsvDelimiterChar)
|
||||
{
|
||||
cDelimiter = *m_sCsvDelimiterChar;
|
||||
}
|
||||
int nFileType = 1;
|
||||
if(NULL != m_nFormatFrom && AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV == *m_nFormatFrom)
|
||||
nFileType = 2;
|
||||
@ -522,7 +535,7 @@ namespace NExtractTools
|
||||
}
|
||||
sRes = L"<xmlOptions><fileOptions fileType='" + std::to_wstring(nFileType);
|
||||
sRes += L"' codePage='" + std::to_wstring(nCsvEncoding);
|
||||
sRes += L"' delimiter='" + std::wstring(cDelimiter.begin(), cDelimiter.end()) + L"' " + sSaveType;
|
||||
sRes += L"' delimiter='" + XmlUtils::EncodeXmlString(cDelimiter) + L"' " + sSaveType;
|
||||
sRes += L"/><TXTOptions><Encoding>" + std::to_wstring(nCsvEncoding) + L"</Encoding></TXTOptions></xmlOptions>";
|
||||
|
||||
return sRes;
|
||||
@ -602,7 +615,7 @@ namespace NExtractTools
|
||||
eRes = TCD_ERROR;
|
||||
}
|
||||
}
|
||||
else if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV == nFormatFrom && (NULL == m_nCsvTxtEncoding || NULL == m_nCsvDelimiter))
|
||||
else if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV == nFormatFrom && (NULL == m_nCsvTxtEncoding || (NULL == m_nCsvDelimiter && NULL == m_sCsvDelimiterChar)))
|
||||
{
|
||||
if(!getDontSaveAdditional())
|
||||
{
|
||||
|
||||
@ -40,10 +40,6 @@
|
||||
#endif
|
||||
#include "../../DesktopEditor/common/File.h"
|
||||
|
||||
#ifndef CP_UTF8
|
||||
#define CP_UTF8 65001
|
||||
#endif
|
||||
|
||||
namespace SerializeCommon
|
||||
{
|
||||
std::wstring DownloadImage(const std::wstring& strFile)
|
||||
@ -99,11 +95,11 @@ namespace SerializeCommon
|
||||
return sSourcePath.substr(0, nIndex + 1) + sTargetExt;
|
||||
return sSourcePath;
|
||||
}
|
||||
void ReadFileType(const std::wstring& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter, BYTE& cSaveFileType)
|
||||
void ReadFileType(const std::wstring& sXMLOptions, BYTE& result, UINT& nCodePage, std::wstring& sDelimiter, BYTE& cSaveFileType)
|
||||
{
|
||||
result = BinXlsxRW::c_oFileTypes::XLSX;
|
||||
nCodePage = CP_UTF8;
|
||||
wcDelimiter = _T(',');
|
||||
nCodePage = 46;//todo 46 временно CP_UTF8
|
||||
sDelimiter = _T("");
|
||||
cSaveFileType = BinXlsxRW::c_oFileTypes::XLSX;
|
||||
|
||||
nullable<SimpleTypes::CUnsignedDecimalNumber<>> fileType;
|
||||
@ -142,9 +138,7 @@ namespace SerializeCommon
|
||||
cSaveFileType = (BYTE)saveFileType->GetValue();
|
||||
if (delimiter.IsInit())
|
||||
{
|
||||
const std::wstring& sDelimiter = delimiter.get();
|
||||
if (0 < sDelimiter.length())
|
||||
wcDelimiter = sDelimiter[0];
|
||||
sDelimiter = delimiter.get();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ namespace SerializeCommon
|
||||
aReplies.clear();
|
||||
}
|
||||
};
|
||||
void ReadFileType(const std::wstring& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter, BYTE& saveFileType);
|
||||
void ReadFileType(const std::wstring& sXMLOptions, BYTE& result, UINT& nCodePage, std::wstring& wcDelimiter, BYTE& saveFileType);
|
||||
}
|
||||
|
||||
#endif //SERIALIZER_COMMON
|
||||
|
||||
@ -3926,16 +3926,16 @@ namespace BinXlsxRW
|
||||
// File Type
|
||||
BYTE fileType;
|
||||
UINT nCodePage;
|
||||
WCHAR wcDelimiter;
|
||||
std::wstring sDelimiter;
|
||||
BYTE saveFileType;
|
||||
SerializeCommon::ReadFileType(sXMLOptions, fileType, nCodePage, wcDelimiter, saveFileType);
|
||||
SerializeCommon::ReadFileType(sXMLOptions, fileType, nCodePage, sDelimiter, saveFileType);
|
||||
|
||||
OOX::Spreadsheet::CXlsx *pXlsx = NULL;
|
||||
switch(fileType)
|
||||
{
|
||||
case BinXlsxRW::c_oFileTypes::CSV:
|
||||
pXlsx = new OOX::Spreadsheet::CXlsx();
|
||||
CSVReader::ReadFromCsvToXlsx(sInputDir, *pXlsx, nCodePage, wcDelimiter);
|
||||
CSVReader::ReadFromCsvToXlsx(sInputDir, *pXlsx, nCodePage, sDelimiter);
|
||||
break;
|
||||
case BinXlsxRW::c_oFileTypes::XLSX:
|
||||
default:
|
||||
@ -3946,8 +3946,8 @@ namespace BinXlsxRW
|
||||
|
||||
if (BinXlsxRW::c_oFileTypes::JSON == saveFileType)
|
||||
{
|
||||
//todo 46 временно CP_UTF8
|
||||
CSVWriter::WriteFromXlsxToCsv(sFileDst, *pXlsx, 46, _T(','), true);
|
||||
//todo 46 временно CP_UTF8
|
||||
CSVWriter::WriteFromXlsxToCsv(sFileDst, *pXlsx, 46, std::wstring(L","), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -81,7 +81,7 @@ namespace CSVReader
|
||||
pCell->setRowCol(nRow, nCol);
|
||||
oRow.m_arrItems.push_back(pCell);
|
||||
}
|
||||
void ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const WCHAR wcDelimiter)
|
||||
void ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& sDelimiter)
|
||||
{
|
||||
// Создадим Workbook
|
||||
oXlsx.CreateWorkbook();
|
||||
@ -169,6 +169,20 @@ namespace CSVReader
|
||||
INT nSize = sFileDataW.length();
|
||||
const WCHAR *pTemp =sFileDataW.c_str();
|
||||
|
||||
WCHAR wcDelimiterLeading = L'\0';
|
||||
WCHAR wcDelimiterTrailing = L'\0';
|
||||
int nDelimiterSize = 0;
|
||||
if (sDelimiter.length() > 0)
|
||||
{
|
||||
wcDelimiterLeading = sDelimiter[0];
|
||||
nDelimiterSize = 1;
|
||||
if (2 == sizeof(wchar_t) && 0xD800 <= wcDelimiterLeading && wcDelimiterLeading <= 0xDBFF && sDelimiter.length() > 1)
|
||||
{
|
||||
wcDelimiterTrailing = sDelimiter[1];
|
||||
nDelimiterSize = 2;
|
||||
}
|
||||
}
|
||||
|
||||
const WCHAR wcNewLineN = _T('\n');
|
||||
const WCHAR wcNewLineR = _T('\r');
|
||||
const WCHAR wcQuote = _T('"');
|
||||
@ -188,7 +202,7 @@ namespace CSVReader
|
||||
for (INT nIndex = 0; nIndex < nSize; ++nIndex)
|
||||
{
|
||||
wcCurrent = pTemp[nIndex];
|
||||
if (wcDelimiter == wcCurrent)
|
||||
if (wcDelimiterLeading == wcCurrent && (L'\0' == wcDelimiterTrailing || (nIndex + 1 < nSize && wcDelimiterTrailing == pTemp[nIndex + 1])))
|
||||
{
|
||||
if (bInQuote)
|
||||
continue;
|
||||
@ -197,7 +211,7 @@ namespace CSVReader
|
||||
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
|
||||
bIsWrap = false;
|
||||
|
||||
nStartCell = nIndex + 1;
|
||||
nStartCell = nIndex + nDelimiterSize;
|
||||
if (nStartCell == nSize)
|
||||
{
|
||||
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
namespace CSVReader
|
||||
{
|
||||
void AddCell(std::wstring &sText, INT nStartCell, std::stack<INT> &oDeleteChars, OOX::Spreadsheet::CRow &oRow, INT nRow, INT nCol, bool bIsWrap);
|
||||
void ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const WCHAR wcDelimiter);
|
||||
void ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& wcDelimiter);
|
||||
}
|
||||
|
||||
#endif //CSV_READER
|
||||
|
||||
@ -3916,10 +3916,10 @@ namespace BinXlsxRW {
|
||||
std::wstring sDstPathCSV = sDstPath;
|
||||
BYTE fileType;
|
||||
UINT nCodePage;
|
||||
WCHAR wcDelimiter;
|
||||
std::wstring sDelimiter;
|
||||
BYTE saveFileType;
|
||||
|
||||
SerializeCommon::ReadFileType(sXMLOptions, fileType, nCodePage, wcDelimiter, saveFileType);
|
||||
SerializeCommon::ReadFileType(sXMLOptions, fileType, nCodePage, sDelimiter, saveFileType);
|
||||
// Делаем для CSV перебивку пути, иначе создается папка с одинаковым имеем (для rels) и файл не создается.
|
||||
|
||||
if (BinXlsxRW::c_oFileTypes::CSV == fileType)
|
||||
@ -3943,7 +3943,7 @@ namespace BinXlsxRW {
|
||||
switch(fileType)
|
||||
{
|
||||
case BinXlsxRW::c_oFileTypes::CSV:
|
||||
CSVWriter::WriteFromXlsxToCsv(sDstPathCSV, oXlsx, nCodePage, wcDelimiter, false);
|
||||
CSVWriter::WriteFromXlsxToCsv(sDstPathCSV, oXlsx, nCodePage, sDelimiter, false);
|
||||
break;
|
||||
case BinXlsxRW::c_oFileTypes::XLSX:
|
||||
default:
|
||||
|
||||
@ -64,7 +64,7 @@ namespace CSVWriter
|
||||
}
|
||||
}
|
||||
}
|
||||
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, std::wstring &sWriteString, UINT &nCodePage, bool bIsEnd)
|
||||
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, const std::wstring &sWriteString, UINT &nCodePage, bool bIsEnd)
|
||||
{
|
||||
if (NULL == pFile || NULL == pWriteBuffer)
|
||||
return;
|
||||
@ -84,7 +84,7 @@ namespace CSVWriter
|
||||
if (nCountChars + nCurrentIndex > c_nSize || bIsEnd)
|
||||
{
|
||||
// Буффер заполнился, пишем
|
||||
if (nCodePage == CP_UTF16)
|
||||
if (nCodePage == 48 && 2 == sizeof(wchar_t))//todo 48 временно CP_UTF16
|
||||
{
|
||||
pFile->WriteFile((BYTE*)*pWriteBuffer, sizeof (WCHAR) * nCurrentIndex);
|
||||
}
|
||||
@ -106,23 +106,23 @@ namespace CSVWriter
|
||||
nCurrentIndex += nCountChars;
|
||||
}
|
||||
}
|
||||
void WriteFromXlsxToCsv(const std::wstring &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const WCHAR wcDelimiter, bool bJSON)
|
||||
void WriteFromXlsxToCsv(const std::wstring &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& sDelimiter, bool bJSON)
|
||||
{
|
||||
NSFile::CFileBinary oFile;
|
||||
oFile.CreateFileW(sFileDst);
|
||||
|
||||
// Нужно записать шапку
|
||||
if (CP_UTF8 == nCodePage)
|
||||
if (46 == nCodePage)//todo 46 временно CP_UTF8
|
||||
{
|
||||
BYTE arUTF8[3] = {0xEF, 0xBB, 0xBF};
|
||||
oFile.WriteFile(arUTF8, 3);
|
||||
}
|
||||
else if (CP_UTF16 == nCodePage)
|
||||
else if (48 == nCodePage)//todo 48 временно CP_UTF16
|
||||
{
|
||||
BYTE arUTF16[2] = {0xFF, 0xFE};
|
||||
oFile.WriteFile(arUTF16, 2);
|
||||
}
|
||||
else if (CP_unicodeFFFE == nCodePage)
|
||||
else if (49 == nCodePage)//todo 49 временно CP_unicodeFFFE
|
||||
{
|
||||
BYTE arBigEndian[2] = {0xFE, 0xFF};
|
||||
oFile.WriteFile(arBigEndian, 2);
|
||||
@ -169,9 +169,8 @@ namespace CSVWriter
|
||||
if (NULL != pWorksheet && pWorksheet->m_oSheetData.IsInit())
|
||||
{
|
||||
OOX::Spreadsheet::CSharedStrings *pSharedStrings = oXlsx.GetSharedStrings();
|
||||
std::wstring sDelimiter = _T(""); sDelimiter += wcDelimiter;
|
||||
std::wstring sEscape = _T("\"\n");
|
||||
sEscape += wcDelimiter;
|
||||
sEscape += sDelimiter;
|
||||
std::wstring sEndJson = std::wstring(_T("]"));
|
||||
std::wstring sQuote = _T("\"");
|
||||
std::wstring sDoubleQuote = _T("\"\"");
|
||||
|
||||
@ -32,20 +32,13 @@
|
||||
#ifndef CSV_WRITER
|
||||
#define CSV_WRITER
|
||||
|
||||
#define CP_UTF16 1200
|
||||
#define CP_unicodeFFFE 1201
|
||||
|
||||
#ifndef CP_UTF8
|
||||
#define CP_UTF8 65001
|
||||
#endif
|
||||
|
||||
#include "../../DesktopEditor/common/File.h"
|
||||
#include "../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h"
|
||||
|
||||
namespace CSVWriter
|
||||
{
|
||||
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, std::wstring &sWriteString, UINT &nCodePage, bool bIsEnd = false);
|
||||
void WriteFromXlsxToCsv(const std::wstring &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const WCHAR wcDelimiter, bool bJSON);
|
||||
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, const std::wstring &sWriteString, UINT &nCodePage, bool bIsEnd = false);
|
||||
void WriteFromXlsxToCsv(const std::wstring &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& wcDelimiter, bool bJSON);
|
||||
}
|
||||
|
||||
#endif //CSV_WRITER
|
||||
|
||||
Reference in New Issue
Block a user