Skip to content

Commit

Permalink
fix bug #66622
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaSubbotina committed Feb 27, 2024
1 parent 147d8ca commit 9bb45aa
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 2 deletions.
27 changes: 27 additions & 0 deletions OdfFile/Reader/Converter/docx_conversion_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,15 @@ void docx_conversion_context::end_document()
output_document_->get_docProps_files().set_app(package::simple_element::create(L"app.xml", dump_settings_app()));
output_document_->get_docProps_files().set_core(package::simple_element::create(L"core.xml", dump_settings_core()));

std::wstring settings_custom = dump_settings_custom();
if (false == settings_custom.empty())
{
output_document_->get_docProps_files().set_custom(package::simple_element::create(L"custom.xml", settings_custom));
output_document_->get_content_types_file().content()->add_override(L"/docProps/custom.xml", L"application/vnd.openxmlformats-officedocument.custom-properties+xml");
output_document_->get_rels_files().add(
relationship(L"rCstmId", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties", L"docProps/custom.xml"));
}

for (size_t i = 0; i < charts_.size(); i++)
{
package::chart_content_ptr content = package::chart_content::create();
Expand Down Expand Up @@ -899,6 +908,24 @@ std::wstring docx_conversion_context::dump_settings_app()
}
return output.str();
}
std::wstring docx_conversion_context::dump_settings_custom()
{
std::wstring user_defined = odf_document_->odf_context().DocProps().dump_user_defined();
if (user_defined.empty()) return L"";

std::wstringstream output;
CP_XML_WRITER(output)
{
CP_XML_NODE(L"Properties")
{
CP_XML_ATTR(L"xmlns", L"http://schemas.openxmlformats.org/officeDocument/2006/custom-properties");
CP_XML_ATTR(L"xmlns:vt", L"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");

CP_XML_STREAM() << user_defined;
}
}
return output.str();
}
std::wstring docx_conversion_context::dump_settings_core()
{
std::wstringstream output;
Expand Down
1 change: 1 addition & 0 deletions OdfFile/Reader/Converter/docx_conversion_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ class docx_conversion_context : boost::noncopyable
std::wstring dump_settings_document();
std::wstring dump_settings_app();
std::wstring dump_settings_core();
std::wstring dump_settings_custom();

bool next_dump_page_properties_;
bool next_dump_section_;
Expand Down
7 changes: 6 additions & 1 deletion OdfFile/Reader/Converter/oox_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ simple_element_ptr simple_element::create(const std::wstring & FileName, const s
//-----------------------------------------------------------------------------------------------
docProps_files::docProps_files()
{

}
std::wstring docProps_files::create_core()
{
Expand Down Expand Up @@ -358,6 +357,10 @@ void docProps_files::set_core(element_ptr Element)
{
core_ = Element;
}
void docProps_files::set_custom(element_ptr Element)
{
custom_ = Element;
}
void docProps_files::write(const std::wstring & RootPath)
{
std::wstring path = RootPath + FILE_SEPARATOR_STR + L"docProps";
Expand All @@ -368,6 +371,8 @@ void docProps_files::write(const std::wstring & RootPath)

core_->write(path);
app_->write(path);

if (custom_) custom_->write(path);
}
//---------------------------------------------------------------------------------------------------
media::media(mediaitems_ptr & _mediaitems, NSFonts::IApplicationFonts *pAppFonts) : mediaItems_(_mediaitems), appFonts_(pAppFonts)
Expand Down
2 changes: 2 additions & 0 deletions OdfFile/Reader/Converter/oox_package.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class docProps_files : public element

void set_app(element_ptr Element);
void set_core(element_ptr Element);
void set_custom(element_ptr Element);

virtual void write(const std::wstring & RootPath);

Expand All @@ -212,6 +213,7 @@ class docProps_files : public element

element_ptr core_;
element_ptr app_;
element_ptr custom_;
};
class document : public element
{
Expand Down
5 changes: 4 additions & 1 deletion OdfFile/Reader/Format/paragraph_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,10 @@ void text_user_defined::docx_convert(oox::docx_conversion_context & Context)
if (!value.empty())
text_ = text::create(value) ;

docx_serialize_run(text_, Context);
if (text_name_)
docx_serialize_field(XmlUtils::EncodeXmlString(L"DOCPROPERTY \"" + *text_name_ + L"\""), text_, Context, false);
else
docx_serialize_run(text_, Context);
}
//-----------------------------------------------------------------------------------------------
// text:bibliography-mark
Expand Down
23 changes: 23 additions & 0 deletions OdfFile/Reader/Format/styles_lite_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include "styles_lite_container.h"
#include "office_settings.h"
#include "..\..\Common\xml\simple_xml_writer.h"

namespace cpdoccore {

Expand Down Expand Up @@ -107,6 +108,28 @@ std::wstring doc_props_container::get_user_defined(const std::wstring & name)

return pFind != impl_->map_user_defineds.end() ? pFind->second : L"";
}
std::wstring doc_props_container::dump_user_defined()
{
std::wstringstream output;

CP_XML_WRITER(output)
{
for (std::map<std::wstring, std::wstring>::iterator it = impl_->map_user_defineds.begin(); it != impl_->map_user_defineds.end(); ++it)
{
CP_XML_NODE(L"property")
{
CP_XML_ATTR(L"fmtid", L"{D5CDD505-2E9C-101B-9397-08002B2CF9AE}");
CP_XML_ATTR(L"name", it->first);
CP_XML_ATTR(L"pid", 2);
CP_XML_NODE(L"vt:lpwstr")
{
CP_XML_STREAM() << it->second;
}
}
}
}
return output.str();
}

//----------------------------------------------------------------------------------
struct settings_value
Expand Down
1 change: 1 addition & 0 deletions OdfFile/Reader/Format/styles_lite_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class doc_props_container

void add_user_defined(const std::wstring & name, const std::wstring & value);
std::wstring get_user_defined(const std::wstring & name);
std::wstring dump_user_defined();

std::wstring dc_creator_;
std::wstring dc_date_;
Expand Down

0 comments on commit 9bb45aa

Please sign in to comment.