diff --git a/ASCOfficeOdfFileW/OdfFileWTest/OdfFileWTest.cpp b/ASCOfficeOdfFileW/OdfFileWTest/OdfFileWTest.cpp index 8687136373..bd8017c87b 100644 --- a/ASCOfficeOdfFileW/OdfFileWTest/OdfFileWTest.cpp +++ b/ASCOfficeOdfFileW/OdfFileWTest/OdfFileWTest.cpp @@ -96,10 +96,10 @@ HRESULT convert_single(std::wstring srcFileName) Oox2Odf::Converter converter(srcTempPath, type, L"C:\\Windows\\Fonts", NULL); - std::wstring sPassword = L"password"; + std::wstring sPassword = L"";//password"; converter.convert(); - converter.write(dstTempPath, srcTempPath, sPassword); + converter.write(dstTempPath, srcTempPath, sPassword, L"hiuh56f56tfy7g"); NSDirectory::DeleteDirectory(srcTempPath); diff --git a/ASCOfficeOdfFileW/source/OdfFormat/object_package.cpp b/ASCOfficeOdfFileW/source/OdfFormat/object_package.cpp index 447efedaf3..d5790ef747 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/object_package.cpp +++ b/ASCOfficeOdfFileW/source/OdfFormat/object_package.cpp @@ -124,6 +124,15 @@ namespace odf_writer { type_ = t; } + documentID_file::documentID_file(std::wstring v) + { + value_ = v; + } + void documentID_file::write(const std::wstring & RootPath, bool add_padding) + { + simple_element elm(L"documentID", value_, false); + elm.write(RootPath, false); + } mimetype_file::mimetype_file(std::wstring t) { type_ = t; @@ -291,6 +300,14 @@ namespace odf_writer { dynamic_cast(manifest_.get())->add_rels(r); } + void odf_document::set_documentID(const std::wstring &value) + { + add_object(element_ptr(new documentID_file(value))); + + rels rels_; + rels_.add(relationship(std::wstring(L"application/binary"), L"documentID")); + set_rels(rels_); + } odf_document::odf_document(std::wstring type) { diff --git a/ASCOfficeOdfFileW/source/OdfFormat/object_package.h b/ASCOfficeOdfFileW/source/OdfFormat/object_package.h index 447c7e5584..3f241ea2df 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/object_package.h +++ b/ASCOfficeOdfFileW/source/OdfFormat/object_package.h @@ -159,6 +159,17 @@ namespace odf_writer rels rels_; std::wstring type_; + }; + class documentID_file : public element + { + public: + documentID_file(std::wstring value); + + virtual void write(const std::wstring & RootPath, bool add_padding = false); + + private: + std::wstring value_; + }; class mimetype_file : public element { @@ -219,11 +230,12 @@ namespace odf_writer void set_rels(rels & r); virtual void write(const std::wstring & RootPath, bool add_padding = false); - void write_manifest(const std::wstring & RootPath); manifect_file* get_manifest() {return dynamic_cast(manifest_.get());} + void set_documentID(const std::wstring &value); + private: element_ptr base_; std::vector objects_; diff --git a/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.cpp b/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.cpp index 27313a8b4f..6ce39d1a56 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.cpp +++ b/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.cpp @@ -462,10 +462,11 @@ void odf_text_context::end_list() list_state_.levels.pop_back(); } -/////////////////////////////////////////////////////////////////////////////////////////// LIST -void odf_text_context::start_field(int type) +//------------------------------------------------------------------------------------------ LIST + +bool odf_text_context::start_field(int type) { - if (single_paragraph_ == true) return; + if (single_paragraph_ == true) return false; office_element_ptr elm; if (type == 2) @@ -493,11 +494,15 @@ void odf_text_context::start_field(int type) { create_element(L"text", L"date", elm, odf_context_); } + if (elm) { in_field_ = true; start_element(elm); + + return true; } + return false; } void odf_text_context::end_field() diff --git a/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.h b/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.h index bf47d2e46e..a78599c240 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.h +++ b/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.h @@ -80,7 +80,7 @@ public: void start_element (office_element_ptr & elm, office_element_ptr style_elm = office_element_ptr(),std::wstring style_name = L""); void end_element (); - void start_field (int type); + bool start_field (int type); void end_field (); void start_span (bool styled = false); diff --git a/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.cpp b/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.cpp index 9df8891372..77b8c2d44c 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.cpp +++ b/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.cpp @@ -32,6 +32,7 @@ #include +#include #include "../utils.h" @@ -78,10 +79,6 @@ odt_conversion_context::odt_conversion_context(package::odf_document * outputDoc comment_context_(this), notes_context_(this), main_text_context_(NULL), table_context_(this) { - current_field_.enabled = false; - current_field_.started = false; - current_field_.in_span = false; - is_hyperlink_ = false; is_header_ = false; @@ -286,8 +283,18 @@ void odt_conversion_context::end_drawings() } void odt_conversion_context::start_paragraph(bool styled) { - if (current_field_.enabled && !current_field_.result) return; //Стандартное_составное_письмо.docx - + if (!current_fields.empty() && current_fields.back().started == false && !current_fields.back().in_span) + { + //if (!current_fields.empty() && !current_fields.back().result) return; //Стандартное_составное_письмо.docx + switch (current_fields.back().type) + { + case 6: current_fields.back().started = start_bibliography(); break; + case 7: current_fields.back().started = start_alphabetical_index(); break; + case 8: //current_fields.back().started = start_table_index(); break; + case 9: current_fields.back().started = start_illustration_index(); break; + case 10:current_fields.back().started = start_table_of_content(); break; + } + } if (is_paragraph_in_current_section_ && !styled) { styles_context()->create_style(L"", odf_types::style_family::Paragraph, true, false, -1); @@ -345,13 +352,119 @@ void odt_conversion_context::add_paragraph_break(int type) //} } } -void odt_conversion_context::start_hyperlink(std::wstring ref) +bool odt_conversion_context::start_table_of_content() +{ + office_element_ptr elm1, elm2; + + create_element(L"text", L"table-of-content", elm1, this); + text_context()->start_element(elm1); + + add_to_root(); + + create_element(L"text", L"table-of-content-source", elm2, this); + text_context()->start_element(elm2); + text_context()->end_element(); + + start_index_field(); + return true; +} + +bool odt_conversion_context::start_alphabetical_index() +{ + office_element_ptr elm1, elm2; + create_element(L"text", L"alphabetical-index", elm1, this); + text_context()->start_element(elm1); + + add_to_root(); + + create_element(L"text", L"alphabetical-index-source", elm2, this); + text_context()->start_element(elm2); + text_context()->end_element(); + + start_index_field(); + return true; +} + +bool odt_conversion_context::start_illustration_index() +{ + office_element_ptr elm1, elm2; + create_element(L"text", L"illustration-index", elm1, this); + text_context()->start_element(elm1); + + add_to_root(); + + create_element(L"text", L"illustration-index-source", elm2, this); + text_context()->start_element(elm2); + text_context()->end_element(); + + start_index_field(); + return true; +} + +bool odt_conversion_context::start_bibliography() +{ + office_element_ptr elm; + create_element(L"text", L"bibliography", elm, this); + text_context()->start_element(elm); + + add_to_root(); + + create_element(L"text", L"bibliography-source", elm, this); + text_context()->start_element(elm); + text_context()->end_element(); + + start_index_field(); + return true; +} + +bool odt_conversion_context::start_table_index() +{ + end_paragraph(); + + office_element_ptr elm; + create_element(L"text", L"table-index", elm, this); + text_context()->start_element(elm); + + add_to_root(); + + create_element(L"text", L"table-index-source", elm, this); + text_context()->start_element(elm); + text_context()->end_element(); + + start_index_field(); + + start_paragraph(); + return true; +} + +void odt_conversion_context::start_index_field() +{ + if (current_fields.empty()) return; + + office_element_ptr elm1, elm2; + create_element(L"text", L"index-body", elm1, this); + text_context()->start_element(elm1); + + if (false == current_fields.back().title.empty()) + { + create_element(L"text", L"index-title", elm2, this); + text_context()->start_element(elm2); + text_context()->end_element(); + } +} +void odt_conversion_context::end_index_field() +{ + text_context()->end_element(); + text_context()->end_element(); +} + +bool odt_conversion_context::start_hyperlink(std::wstring ref) { office_element_ptr hyperlink_elm; create_element(L"text", L"a", hyperlink_elm, this); text_a* hyperlink = dynamic_cast(hyperlink_elm.get()); - if (!hyperlink)return; + if (!hyperlink)return false; //////////////////////////// @@ -364,26 +477,48 @@ void odt_conversion_context::start_hyperlink(std::wstring ref) text_context()->start_element(hyperlink_elm); is_hyperlink_ = true; + return true; } void odt_conversion_context::end_hyperlink() { if (!is_hyperlink_) return; - //current_level_.pop_back(); text_context()->end_element(); is_hyperlink_ = false; //метка .. для гиперлинков в объектах - там не будет span } + +std::map odt_conversion_context::parse_instr_options(const std::wstring& value) +{ + std::map result; + + std::vector arOptions; + boost::algorithm::split(arOptions, value, boost::algorithm::is_any_of(L"\\"), boost::algorithm::token_compress_on); + + for (size_t i = 0; i < arOptions.size(); i++) + { + std::wstring key = arOptions[i].substr(0, 1); + std::wstring value; + if (arOptions[i].length() > 1) + { + value = arOptions[i].substr(1); + } + result.insert(std::make_pair(key, value)); + } + + return result; +} + void odt_conversion_context::set_field_instr(std::wstring instr) { - if (current_field_.enabled == false) return; + if (current_fields.empty()) return; - current_field_.type = 0; //users field size_t res1 = instr.find(L"HYPERLINK"); - if (std::wstring::npos != res1) //это не поле - это hyperlink + if (std::wstring::npos != res1) { - current_field_.type = 1; + current_fields.back().type = 1; + current_fields.back().in_span = false; std::wstring ref; boost::match_results res; @@ -391,66 +526,103 @@ void odt_conversion_context::set_field_instr(std::wstring instr) if (boost::regex_search(instr, res, r2)) { ref = res[1].str(); - current_field_.value = ref.substr(1, ref.length()-2); + current_fields.back().value = ref.substr(1, ref.length() - 2); } } res1 = instr.find(L"NUMPAGES"); - if (std::wstring::npos != res1 && current_field_.type == 0) + if (std::wstring::npos != res1 && current_fields.back().type == 0) { - current_field_.type = 3; + current_fields.back().type = 3; } res1 = instr.find(L"PAGEREF"); - if (std::wstring::npos != res1 && current_field_.type == 0 ) //это не поле - это bookmark + if (std::wstring::npos != res1 && current_fields.back().type == 0 ) { - current_field_.type = 5; + current_fields.back().type = 5; if (instr.length() > 9) - current_field_.value = instr.substr(9, instr.length()-5); + current_fields.back().value = instr.substr(9, instr.length() - 5); } res1 = instr.find(L"PAGE"); - if (std::wstring::npos != res1 && current_field_.type == 0) + if (std::wstring::npos != res1 && current_fields.back().type == 0) { - current_field_.type = 2; + current_fields.back().type = 2; } res1 = instr.find(L"TIME"); - if (std::wstring::npos != res1 && current_field_.type == 0) + if (std::wstring::npos != res1 && current_fields.back().type == 0) { - current_field_.type = 4; + current_fields.back().type = 4; } res1 = instr.find(L"BIBLIOGRAPHY"); - if (std::wstring::npos != res1 && current_field_.type == 0) + if (std::wstring::npos != res1 && current_fields.back().type == 0) { - current_field_.type = 6; + current_fields.back().type = 6; + current_fields.back().in_span = false; } -////////////////////////////////////////// + res1 = instr.find(L"INDEX"); + if (std::wstring::npos != res1 && current_fields.back().type == 0) + { + current_fields.back().type = 7; + current_fields.back().in_span = false; + } + res1 = instr.find(L"TOC"); + if (std::wstring::npos != res1 && current_fields.back().type == 0) + { + current_fields.back().type = 8; + current_fields.back().in_span = false; + std::map options = parse_instr_options(instr.substr(res1 + 3)); + + std::map::iterator pFind = options.find(L"c"); + if ( pFind != options.end()) + { + current_fields.back().captionSEQ = pFind->second; + } + pFind = options.find(L"h"); + if ( pFind != options.end()) + { + current_fields.back().bHyperlinks = true; + } + pFind = options.find(L"u"); //paragraph outline level + if ( pFind != options.end()) + { + current_fields.back().type = 10; //table of content + } + pFind = options.find(L"o"); + if ( pFind != options.end())//table of content outline levels style + { + current_fields.back().type = 10; + } + pFind = options.find(L"z"); + if ( pFind != options.end())//table of content outline levels style + { + current_fields.back().bHidePageNumbers = true; + } + } + ////////////////////////////////////////// res1 = instr.find(L"@"); if (std::wstring::npos != res1) { - current_field_.format = instr.substr(res1 + 1, instr.length()); + current_fields.back().format = instr.substr(res1 + 1, instr.length()); } - if (current_field_.type == 0) + if (current_fields.back().type == 0) { res1 = instr.find(L" "); if (std::wstring::npos != res1) { - current_field_.name = instr.substr(0, res1); + current_fields.back().name = instr.substr(0, res1); } } } void odt_conversion_context::start_field(bool in_span) { - current_field_.enabled = true; - - current_field_.result = false; - current_field_.in_span = in_span; - current_field_.value.clear(); - current_field_.name.clear(); - current_field_.type = 0; // users field + _field_state field; + current_fields.push_back(field); } void odt_conversion_context::separate_field() { - current_field_.result = true; + if (current_fields.empty()) return; + + current_fields.back().result = true; } void odt_conversion_context::set_master_page_name(std::wstring master_name) { @@ -587,23 +759,27 @@ void odt_conversion_context::add_section_column(std::vectorend_field(); - } - current_field_.value = L""; - current_field_.format = L""; - current_field_.name = L""; + if (current_fields.empty()) return; - current_field_.result = false; - current_field_.enabled = false; - current_field_.started = false; - current_field_.in_span = false; + if (current_fields.back().started) + { + switch(current_fields.back().type) + { + case 1: end_hyperlink(); break; + case 6: + case 7: + case 8: + case 9: + case 10: end_index_field(); break; + default: + text_context()->end_field(); + } + } + current_fields.pop_back(); } void odt_conversion_context::end_paragraph() { - if (current_field_.enabled && !current_field_.result) return; //Стандартное_составное_письмо.docx + if (!current_fields.empty() && !current_fields.back().result) return; //Стандартное_составное_письмо.docx text_context()->end_paragraph(); @@ -706,11 +882,10 @@ void odt_conversion_context::start_run(bool styled) { if (is_hyperlink_ && text_context_.size() > 0) return; - - if (current_field_.started == false && current_field_.type > 1 && current_field_.enabled == true && !current_field_.in_span) + if (!current_fields.empty() && current_fields.back().started == false && !current_fields.back().in_span) { - text_context()->start_field(current_field_.type); - current_field_.started = true; + if (current_fields.back().type == 1) current_fields.back().started = start_hyperlink(current_fields.back().value); + else if (current_fields.back().type < 6) current_fields.back().started = text_context()->start_field(current_fields.back().type); } text_context()->start_span(styled); @@ -722,25 +897,27 @@ void odt_conversion_context::start_run(bool styled) props->apply_from(dynamic_cast(drop_cap_state_.text_properties.get())); } - if (current_field_.started == false && current_field_.type > 1 && current_field_.enabled == true && current_field_.in_span)//поле стартуется в span - нужно для сохранения стиля + if (!current_fields.empty() && current_fields.back().started == false && current_fields.back().in_span)//поле стартуется в span - нужно для сохранения стиля { - text_context()->start_field(current_field_.type); - current_field_.started = true; + current_fields.back().started = text_context()->start_field(current_fields.back().type); } } void odt_conversion_context::end_run() { if (is_hyperlink_ && text_context_.size() > 0) return; - if (current_field_.in_span && current_field_.started== true && current_field_.enabled ==true) end_field(); + if (!current_fields.empty() && current_fields.back().started == true && current_fields.back().in_span) + { + end_field(); + } text_context()->end_span(); - if (current_field_.started== false && current_field_.type == 1 && current_field_.enabled ==true) - { - start_hyperlink(current_field_.value); - current_field_.started = true; - } + //if (current_field_.enabled == true && current_field_.started== false && current_field_.type == 1) + //{ + // start_hyperlink(current_field_.value); + // current_field_.started = true; + //} } //-------------------------------------------------------------------------------------------------------- bool odt_conversion_context::start_comment(int oox_comm_id) diff --git a/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.h b/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.h index f5616750c1..d9037a8150 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.h +++ b/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.h @@ -90,14 +90,24 @@ public: void add_paragraph_break(int type); - void start_hyperlink (std::wstring ref); + bool start_hyperlink (std::wstring ref); void end_hyperlink (); + bool start_table_of_content (); + bool start_bibliography (); + bool start_alphabetical_index (); + bool start_illustration_index (); + bool start_table_index (); + + void start_index_field(); + void end_index_field(); + void start_field (bool in_span); void end_field (); void separate_field (); void set_field_instr (std::wstring instr); - + std::map parse_instr_options(const std::wstring& value); + void start_run (bool styled = false); void end_run (); @@ -186,15 +196,22 @@ private: struct _field_state { + int type = 0; + std::wstring name; - bool enabled; - int type; std::wstring value; + std::wstring format; - bool started; - bool in_span; + bool started = false; + bool in_span = false; bool result; - }current_field_; + bool bHyperlinks = false; + bool bHidePageNumbers = false; + std::wstring captionSEQ; + std::wstring title; + }; + + std::vector<_field_state> current_fields; struct _text_changes_state { diff --git a/ASCOfficeOdfFileW/source/OdfFormat/text_elements.cpp b/ASCOfficeOdfFileW/source/OdfFormat/text_elements.cpp index 1983ccb2c4..57856c420c 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/text_elements.cpp +++ b/ASCOfficeOdfFileW/source/OdfFormat/text_elements.cpp @@ -379,25 +379,30 @@ void text_table_of_content::serialize(std::wostream & _Wostream) { text_section_attr_.serialize(CP_GET_XML_NODE()); - if (text_index_body_) - text_index_body_->serialize(CP_XML_STREAM()); + if (table_of_content_source_) + table_of_content_source_->serialize(CP_XML_STREAM()); - if (text_table_of_content_source_) - text_table_of_content_source_->serialize(CP_XML_STREAM()); + if (index_body_) + index_body_->serialize(CP_XML_STREAM()); } } } void text_table_of_content::create_child_element( const std::wstring & Ns, const std::wstring & Name) { - if CP_CHECK_NAME(L"text", L"index-body") - { - CP_CREATE_ELEMENT(text_index_body_); - } + if (L"text" == Ns && L"table-of-content-source" == Name) CP_CREATE_ELEMENT(table_of_content_source_); + else if CP_CHECK_NAME(L"text", L"index-body") CP_CREATE_ELEMENT(index_body_); } void text_table_of_content::add_child_element( const office_element_ptr & child_element) { - text_index_body_ = child_element; + if (!child_element) return; + + ElementType type = child_element->get_type(); + + if (type == typeTextTableOfContentSource) + table_of_content_source_= child_element; + else if (type == typeTextIndexBody) + index_body_ = child_element; } //-------------------------------------------------------------------------------------------------------- @@ -616,7 +621,7 @@ const wchar_t * text_table_index::name = L"table-index"; void text_table_index::create_child_element(const std::wstring & Ns, const std::wstring & Name) { - if (L"text" == Ns && L"index-body_" == Name) CP_CREATE_ELEMENT(index_body_); + if (L"text" == Ns && L"index-body" == Name) CP_CREATE_ELEMENT(index_body_); else if (L"text" == Ns && L"table-index-source" == Name)CP_CREATE_ELEMENT(table_index_source_); } @@ -654,7 +659,7 @@ const wchar_t * text_illustration_index::name = L"illustration-index"; void text_illustration_index::create_child_element(const std::wstring & Ns, const std::wstring & Name) { - if (L"text" == Ns && L"index-body_" == Name) CP_CREATE_ELEMENT(index_body_); + if (L"text" == Ns && L"index-body" == Name) CP_CREATE_ELEMENT(index_body_); else if (L"text" == Ns && L"illustration-index-source" == Name) CP_CREATE_ELEMENT(illustration_index_source_); } @@ -687,12 +692,50 @@ void text_illustration_index::serialize(std::wostream & _Wostream) } } //------------------------------------------------------------ +const wchar_t * text_user_index::ns = L"text"; +const wchar_t * text_user_index::name = L"user-index"; + +void text_user_index::create_child_element(const std::wstring & Ns, const std::wstring & Name) +{ + if (L"text" == Ns && L"index-body" == Name) CP_CREATE_ELEMENT(index_body_); + else if (L"text" == Ns && L"user-index-source" == Name) CP_CREATE_ELEMENT(user_index_source_); +} + +void text_user_index::add_child_element( const office_element_ptr & child_element) +{ + if (!child_element) return; + + ElementType type = child_element->get_type(); + + if (type == typeTextUserIndexSource) + user_index_source_= child_element; + else if (type == typeTextIndexBody) + index_body_= child_element; +} + +void text_user_index::serialize(std::wostream & _Wostream) +{ + CP_XML_WRITER(_Wostream) + { + CP_XML_NODE_SIMPLE() + { + section_attr_.serialize(CP_GET_XML_NODE()); + + if (user_index_source_) + user_index_source_->serialize(CP_XML_STREAM()); + + if (index_body_) + index_body_->serialize(CP_XML_STREAM()); + } + } +} +//------------------------------------------------------------ const wchar_t * text_alphabetical_index::ns = L"text"; const wchar_t * text_alphabetical_index::name = L"alphabetical-index"; void text_alphabetical_index::create_child_element(const std::wstring & Ns, const std::wstring & Name) { - if (L"text" == Ns && L"index-body_" == Name) CP_CREATE_ELEMENT(index_body_); + if (L"text" == Ns && L"index-body" == Name) CP_CREATE_ELEMENT(index_body_); else if (L"text" == Ns && L"alphabetical-index-source" == Name) CP_CREATE_ELEMENT(alphabetical_index_source_); } @@ -730,7 +773,7 @@ const wchar_t * text_bibliography::name = L"bibliography"; void text_bibliography::create_child_element(const std::wstring & Ns, const std::wstring & Name) { - if (L"text" == Ns && L"index-body_" == Name) CP_CREATE_ELEMENT(index_body_); + if (L"text" == Ns && L"index-body" == Name) CP_CREATE_ELEMENT(index_body_); else if (L"text" == Ns && L"bibliography-source" == Name) CP_CREATE_ELEMENT(bibliography_source_); } @@ -898,6 +941,62 @@ void text_illustration_index_source::serialize(std::wostream & _Wostream) } } //---------------------------------------------------------------------------------------------------------- +const wchar_t * text_user_index_source::ns = L"text"; +const wchar_t * text_user_index_source::name = L"user-index-source"; + +void text_user_index_source::create_child_element(const std::wstring & Ns, const std::wstring & Name) +{ + if (L"text" == Ns && L"index-title-template" == Name) CP_CREATE_ELEMENT(index_title_template_); + else CP_CREATE_ELEMENT(entry_templates_); +} + +void text_user_index_source::add_child_element( const office_element_ptr & child_element) +{ + if (!child_element) return; + + ElementType type = child_element->get_type(); + + if (type == typeTextIndexTitleTemplate) + index_title_template_ = child_element; + else + entry_templates_.push_back(child_element); +} + +void text_user_index_source::serialize(std::wostream & _Wostream) +{ + CP_XML_WRITER(_Wostream) + { + CP_XML_NODE_SIMPLE() + { + CP_XML_ATTR_OPT(L"text:index-name", index_name_); + CP_XML_ATTR_OPT(L"text:copy-outline-levels", copy_outline_levels_); + + CP_XML_ATTR_OPT(L"text:use-chart-objects", use_chart_objects_); + CP_XML_ATTR_OPT(L"text:use-draw-objects", use_draw_objects_); + CP_XML_ATTR_OPT(L"text:use-graphics", use_graphics_); + CP_XML_ATTR_OPT(L"text:use-floating-frames", use_floating_frames_); + CP_XML_ATTR_OPT(L"text:use-index-marks", use_index_marks_); + CP_XML_ATTR_OPT(L"text:use-index_source_styles", use_index_source_styles_); + CP_XML_ATTR_OPT(L"text:use-objects", use_objects_); + CP_XML_ATTR_OPT(L"text:use-tables", use_tables_); + CP_XML_ATTR_OPT(L"text:relative_tab-stop-position", relative_tab_stop_position_); + CP_XML_ATTR_OPT(L"text:index-scope", index_scope_); // chapter or document + + if (index_title_template_) + index_title_template_->serialize(CP_XML_STREAM()); + + for (size_t i = 0 ; i < index_source_styles_.size(); i++) + { + index_source_styles_[i]->serialize(CP_XML_STREAM()); + } + for (size_t i = 0 ; i < entry_templates_.size(); i++) + { + entry_templates_[i]->serialize(CP_XML_STREAM()); + } + } + } +} +//---------------------------------------------------------------------------------------------------------- const wchar_t * alphabetical_index_source::ns = L"text"; const wchar_t * alphabetical_index_source::name = L"alphabetical-index-source"; @@ -995,6 +1094,9 @@ const wchar_t * text_table_index_entry_template::name = L"table-index-entry-te const wchar_t * text_table_of_content_entry_template::ns = L"text"; const wchar_t * text_table_of_content_entry_template::name = L"table-of-content-entry-template"; //---------------------------------------------------------------------------------------------------------- +const wchar_t * text_user_index_entry_template::ns = L"text"; +const wchar_t * text_user_index_entry_template::name = L"user-index-entry-template"; +//---------------------------------------------------------------------------------------------------------- const wchar_t * text_bibliography_entry_template::ns = L"text"; const wchar_t * text_bibliography_entry_template::name = L"bibliography-entry-template"; diff --git a/ASCOfficeOdfFileW/source/OdfFormat/text_elements.h b/ASCOfficeOdfFileW/source/OdfFormat/text_elements.h index b2cfd2669b..2eec9372c1 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/text_elements.h +++ b/ASCOfficeOdfFileW/source/OdfFormat/text_elements.h @@ -272,8 +272,8 @@ public: text_section_attr text_section_attr_; - office_element_ptr text_table_of_content_source_; - office_element_ptr text_index_body_; + office_element_ptr table_of_content_source_; + office_element_ptr index_body_; }; CP_REGISTER_OFFICE_ELEMENT2(text_table_of_content); @@ -555,6 +555,30 @@ public: }; CP_REGISTER_OFFICE_ELEMENT2(text_alphabetical_index); +//--------------------------------------------------------------------------------------------------- +// text:user-index +//--------------------------------------------------------------------------------------------------- +class text_user_index : public office_element_impl +{ +public: + static const wchar_t * ns; + static const wchar_t * name; + static const xml::NodeType xml_type = xml::typeElement; + static const ElementType type = typeTextUserIndex; + + 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); + + odf_types::section_attlists section_attr_; + office_element_ptr user_index_source_; + office_element_ptr index_body_; + +}; +CP_REGISTER_OFFICE_ELEMENT2(text_user_index); //------------------------------------------------------------------------------------------------------------ // text:bibliography //------------------------------------------------------------------------------------------------------------ @@ -928,6 +952,54 @@ public: }; CP_REGISTER_OFFICE_ELEMENT2(text_illustration_index_entry_template); //--------------------------------------------------------------------------------------------------- +//text:user-index-source +//--------------------------------------------------------------------------------------------------- +class text_user_index_source: public office_element_impl +{ +public: + static const wchar_t * ns; + static const wchar_t * name; + static const xml::NodeType xml_type = xml::typeElement; + static const ElementType type = typeTextUserIndexSource; + 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); + + _CP_OPT(std::wstring) index_name_; + _CP_OPT(odf_types::Bool) copy_outline_levels_; + _CP_OPT(odf_types::Bool) relative_tab_stop_position_; + _CP_OPT(odf_types::Bool) use_chart_objects_; + _CP_OPT(odf_types::Bool) use_draw_objects_; + _CP_OPT(odf_types::Bool) use_graphics_; + _CP_OPT(odf_types::Bool) use_floating_frames_; + _CP_OPT(odf_types::Bool) use_index_marks_; + _CP_OPT(odf_types::Bool) use_index_source_styles_; + _CP_OPT(odf_types::Bool) use_objects_; + _CP_OPT(odf_types::Bool) use_tables_; + _CP_OPT(std::wstring) index_scope_; // chapter or document: + + office_element_ptr index_title_template_; + office_element_ptr_array entry_templates_; + office_element_ptr_array index_source_styles_; +}; +CP_REGISTER_OFFICE_ELEMENT2(text_user_index_source); +//--------------------------------------------------------------------------------------------------- +//text:user-index-entry-template +//--------------------------------------------------------------------------------------------------- +class text_user_index_entry_template : public common_entry_template +{ +public: + static const wchar_t * ns; + static const wchar_t * name; + static const xml::NodeType xml_type = xml::typeElement; + static const ElementType type = typeTextUserIndexEntryTemplate; + CPDOCCORE_DEFINE_VISITABLE() +}; +CP_REGISTER_OFFICE_ELEMENT2(text_user_index_entry_template); +//--------------------------------------------------------------------------------------------------- //text:alphabetical-index-source //--------------------------------------------------------------------------------------------------- class alphabetical_index_source : public office_element_impl diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp index 53d80dbcfb..7346430e78 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp @@ -101,13 +101,13 @@ namespace Oox2Odf impl_->convertDocument(); } - void Converter::write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password) const + void Converter::write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID) const { if (!impl_)return; if (impl_->bUserStopConvert) return; - return impl_->write(out_path, temp_path, password); + return impl_->write(out_path, temp_path, password, documentID); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -126,10 +126,15 @@ bool OoxConverter::UpdateProgress(long nComplete) return FALSE; } -void OoxConverter::write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password) +void OoxConverter::write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID) { if (!output_document)return; + if (false == documentID.empty()) + { + output_document->set_documentID(documentID); + } + if (password.empty()) { output_document->write(out_path); diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.h b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.h index 00091e7216..33a193a47d 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.h +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.h @@ -343,7 +343,7 @@ namespace Oox2Odf public: virtual void convertDocument() = 0; - void write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password); + void write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID); OoxConverter(const ProgressCallback* CallBack = NULL){ oox_current_child_document = NULL; diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp index 101d877a90..60baf4b098 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp @@ -861,9 +861,9 @@ void DocxConverter::convert(OOX::Logic::CFldSimple *oox_fld) if (oox_fld->m_sInstr.IsInit()) odt_context->set_field_instr(oox_fld->m_sInstr.get2()); - for (std::vector::iterator it = oox_fld->m_arrItems.begin(); it != oox_fld->m_arrItems.end(); ++it) + for (size_t i = 0; i < oox_fld->m_arrItems.size(); ++i) { - convert(*it); + convert(oox_fld->m_arrItems[i]); } } odt_context->end_field(); diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Oox2OdfConverter.h b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Oox2OdfConverter.h index e58e26a364..859eff7e8e 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Oox2OdfConverter.h +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Oox2OdfConverter.h @@ -46,7 +46,7 @@ namespace Oox2Odf void convert(); - void write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password) const; + void write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID) const; OoxConverter * get_ooxConverter() { return impl_; } diff --git a/X2tConverter/src/ASCConverters.cpp b/X2tConverter/src/ASCConverters.cpp index 4032387871..b7dd188c03 100644 --- a/X2tConverter/src/ASCConverters.cpp +++ b/X2tConverter/src/ASCConverters.cpp @@ -1890,18 +1890,19 @@ namespace NExtractTools std::wstring sTempUnpackedODP = sTemp + FILE_SEPARATOR_STR + _T("odp_unpacked"); NSDirectory::CreateDirectory(sTempUnpackedODP); - std::wstring password = params.getSavePassword(); - Oox2Odf::Converter converter(sPptxDir, _T("presentation"), params.getFontPath(), NULL); int nRes = 0; try { - converter.convert(); - converter.write(sTempUnpackedODP, sTemp, password); + std::wstring password = params.getSavePassword(); + std::wstring documentID = params.getDocumentID(); + + converter.convert(); + converter.write(sTempUnpackedODP, sTemp, password, documentID); - COfficeUtils oCOfficeUtils(NULL); - nRes = (S_OK == oCOfficeUtils.CompressFileOrDirectory(sTempUnpackedODP, sTo, false, password.empty() ? Z_DEFLATED : 0)) ? 0 : AVS_FILEUTILS_ERROR_CONVERT; + COfficeUtils oCOfficeUtils(NULL); + nRes = (S_OK == oCOfficeUtils.CompressFileOrDirectory(sTempUnpackedODP, sTo, false, password.empty() ? Z_DEFLATED : 0)) ? 0 : AVS_FILEUTILS_ERROR_CONVERT; }catch(...) { nRes = AVS_FILEUTILS_ERROR_CONVERT; @@ -2465,10 +2466,11 @@ namespace NExtractTools int nRes = 0; try { - std::wstring password = params.getSavePassword(); - + std::wstring password = params.getSavePassword(); + std::wstring documentID = params.getDocumentID(); + converter.convert(); - converter.write(sTempUnpackedODT, sTemp, password); + converter.write(sTempUnpackedODT, sTemp, password, documentID); COfficeUtils oCOfficeUtils(NULL); nRes = (S_OK == oCOfficeUtils.CompressFileOrDirectory(sTempUnpackedODT, sTo, false, password.empty() ? Z_DEFLATED : 0)) ? 0 : AVS_FILEUTILS_ERROR_CONVERT; @@ -2502,10 +2504,11 @@ namespace NExtractTools { Oox2Odf::Converter converter(sXlsxDir, L"spreadsheet", params.getFontPath(), NULL); - std::wstring password = params.getSavePassword(); + std::wstring password = params.getSavePassword(); + std::wstring documentID = params.getDocumentID(); converter.convert(); - converter.write(sTempUnpackedODS, sTemp, password); + converter.write(sTempUnpackedODS, sTemp, password, documentID); COfficeUtils oCOfficeUtils(NULL); int nRes = (S_OK == oCOfficeUtils.CompressFileOrDirectory(sTempUnpackedODS, sTo, false, password.empty() ? Z_DEFLATED : 0)) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;