Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinFormat - fix bug #47488, ... #438

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions ASCOfficeDocxFile2/BinWriter/BinWriters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3174,7 +3174,7 @@ void BinaryDocumentTableWriter::WriteDocumentContent(const std::vector<OOX::Writ
{
OOX::Media* pAltChunkFile = static_cast<OOX::Media*>(pFile.operator ->());

WriteAltChunk(*pAltChunkFile);
WriteAltChunk(*pAltChunkFile, m_oParamsWriter.m_pStyles);
}
}
}break;
Expand Down Expand Up @@ -3344,7 +3344,7 @@ void BinaryDocumentTableWriter::WriteBackground (OOX::WritingElement* pElement)
}
}

void BinaryDocumentTableWriter::WriteAltChunk(OOX::Media& oAltChunkFile)
void BinaryDocumentTableWriter::WriteAltChunk(OOX::Media& oAltChunkFile, OOX::CStyles* styles)
{
if (false == oAltChunkFile.IsExist()) return;

Expand Down Expand Up @@ -3386,9 +3386,31 @@ void BinaryDocumentTableWriter::WriteAltChunk(OOX::Media& oAltChunkFile)
case AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML:
{
CHtmlFile2 htmlConvert;
htmlConvert.SetTmpDirectory(sTempDir);
CHtmlParams paramsHtml;

result = (S_OK == htmlConvert.OpenHtml(file_name_inp, sResultDocxDir));
htmlConvert.SetTmpDirectory(sTempDir);

if (styles)
{
if (styles->m_oDocDefaults.IsInit())
{
paramsHtml.m_sdocDefaults = styles->m_oDocDefaults->toXML();
}
std::map<SimpleTypes::EStyleType, size_t>::iterator pFind = styles->m_mapStyleDefaults.find(SimpleTypes::styletypeParagraph);
if (pFind != styles->m_mapStyleDefaults.end())
{
if (styles->m_arrStyle[pFind->second])
{
//change styleId

OOX::CStyle updateStyle (*styles->m_arrStyle[pFind->second]);
updateStyle.m_sStyleId = L"normal";
paramsHtml.m_sNormal = updateStyle.toXML();
}
}
}

result = (S_OK == htmlConvert.OpenHtml(file_name_inp, sResultDocxDir, &paramsHtml));
}break;
case AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT:
{
Expand Down
2 changes: 1 addition & 1 deletion ASCOfficeDocxFile2/BinWriter/BinWriters.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ namespace BinDocxRW
//---------------------------------
BinaryDocumentTableWriter(ParamsWriter& oParamsWriter, ParamsDocumentWriter& oParamsDocumentWriter, std::map<int, bool>* mapIgnoreComments, BinaryHeaderFooterTableWriter* oBinaryHeaderFooterTableWriter);

void WriteAltChunk(OOX::Media& oAltChunk);
void WriteAltChunk(OOX::Media& oAltChunk, OOX::CStyles* styles);
void WriteVbaProject(OOX::VbaProject& oVbaProject);
void Write(std::vector<OOX::WritingElement*> & aElems);
void WriteDocumentContent(const std::vector<OOX::WritingElement*> & aElems);
Expand Down
2 changes: 2 additions & 0 deletions ASCOfficeOdfFile/include/odf/odf_elements_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ enum ElementType
typeTextIndexTitleTemplate,

typeTextNotesConfiguration,
typeTextLinenumberingConfiguration,
typeTextLinenumberingSeparator,

typeStyleFontFace,

Expand Down
8 changes: 7 additions & 1 deletion ASCOfficeOdfFile/src/docx/docx_conversion_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,11 @@ void docx_conversion_context::start_process_style_content()

void docx_conversion_context::process_section(std::wostream & strm, odf_reader::style_columns * columns)//from page layout
{
if (root()->odf_context().pageLayoutContainer().linenumbering())
{
root()->odf_context().pageLayoutContainer().linenumbering()->docx_serialize(strm, *this);
}

int count_columns = 1;
bool sep_columns = false;

Expand Down Expand Up @@ -1277,8 +1282,9 @@ void docx_conversion_context::process_section(std::wostream & strm, odf_reader::
}
}
}

CP_XML_WRITER(strm)
{
{
CP_XML_NODE(L"w:cols")
{
CP_XML_ATTR(L"w:equalWidth", width_space.empty());
Expand Down
2 changes: 1 addition & 1 deletion ASCOfficeOdfFile/src/docx/docx_conversion_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace cpdoccore {
class office_element;
class style_columns;
class form_element;
class text_linenumbering_configuration;

namespace text
{
Expand Down Expand Up @@ -1062,7 +1063,6 @@ class docx_conversion_context : boost::noncopyable
std::map<std::wstring, std::vector<odf_reader::office_element_ptr>> mapAlphabeticals;

std::vector<std::wstring> arBibliography;

};

}
Expand Down
11 changes: 8 additions & 3 deletions ASCOfficeOdfFile/src/odf/odf_document_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ void odf_document::Impl::parse_meta(office_element *element)
void odf_document::Impl::parse_styles(office_element *element)
{
text_outline_style *outlineStyle = NULL;
text_linenumbering_configuration *linenumberingStyle = NULL;

do
{
Expand Down Expand Up @@ -900,9 +901,14 @@ void odf_document::Impl::parse_styles(office_element *element)

if (docStyles->text_outline_style_)
{
outlineStyle = dynamic_cast<text_outline_style *>(docStyles->text_outline_style_.get());
outlineStyle = dynamic_cast<text_outline_style *>(docStyles->text_outline_style_.get());
context_->listStyleContainer().add_outline_style(outlineStyle);
}
if (docStyles->text_linenumbering_configuration_)
{
linenumberingStyle = dynamic_cast<text_linenumbering_configuration *>(docStyles->text_linenumbering_configuration_.get());
context_->pageLayoutContainer().add_linenumbering(linenumberingStyle);
}

for (size_t i = 0; i < docStyles->text_notes_configuration_.size(); i++)
{
office_element_ptr & elm = docStyles->text_notes_configuration_[i];
Expand Down Expand Up @@ -1096,7 +1102,6 @@ void odf_document::Impl::parse_styles(office_element *element)
while (false);

context_->listStyleContainer().add_outline_style(outlineStyle);

}

bool odf_document::Impl::docx_convert(oox::docx_conversion_context & Context)
Expand Down
4 changes: 4 additions & 0 deletions ASCOfficeOdfFile/src/odf/odfcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ class page_layout_container
style_presentation_page_layout * presentation_page_layout_by_name(const std::wstring & Name);

bool compare_page_properties(const std::wstring & master1, const std::wstring & master2);

void add_linenumbering(odf_reader::text_linenumbering_configuration *linenumbering) { linenumberingcConfiguration = linenumbering; }
odf_reader::text_linenumbering_configuration *linenumbering() { return linenumberingcConfiguration; }
private:
std::vector<style_presentation_page_layout*> presentation_page_layouts_;
instances_array instances_;
Expand All @@ -271,6 +274,7 @@ class page_layout_container

boost::unordered_map<std::wstring, int> presentation_page_layout_names_;

odf_reader::text_linenumbering_configuration *linenumberingcConfiguration = NULL;
};


Expand Down
82 changes: 72 additions & 10 deletions ASCOfficeOdfFile/src/odf/styles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ void styles::add_child_element( xml::sax * Reader, const std::wstring & Ns, cons
{
CP_CREATE_ELEMENT_SIMPLE(number_styles_);
}
else
else
{
CP_NOT_APPLICABLE_ELM_SIMPLE(L"styles");
}
Expand Down Expand Up @@ -1398,10 +1398,10 @@ void style_page_layout_properties::docx_serialize(std::wostream & strm, oox::doc
}
else
CP_XML_ATTR(L"w:val", L"continuous");
}
}

std::wstring masterPageName = Context.get_master_page_name();
bool res = Context.get_headers_footers().write_sectPr(masterPageName, change_page_layout, strm);
bool res = Context.get_headers_footers().write_sectPr(masterPageName, change_page_layout, CP_XML_STREAM());

if (res == false)
{
Expand All @@ -1417,7 +1417,7 @@ void style_page_layout_properties::docx_serialize(std::wostream & strm, oox::doc

oox::section_context::_section & section = Context.get_section_context().get_last();

attlist_.docx_convert_serialize(strm, Context, section.margin_left_, section.margin_right_);
attlist_.docx_convert_serialize(CP_XML_STREAM(), Context, section.margin_left_, section.margin_right_);
//todooo при появлении еще накладок - переписать !!
}
}
Expand Down Expand Up @@ -1824,8 +1824,8 @@ void header_footer_impl::xlsx_serialize(std::wostream & _Wostream, oox::xlsx_con
}
}
}
/// text:notes-configuration
//////////////////////////////////////////////////////////////////////////////////////////////////
// text:notes-configuration
//-------------------------------------------------------------------------------------------------------
const wchar_t * text_notes_configuration::ns = L"text";
const wchar_t * text_notes_configuration::name = L"notes-configuration";

Expand All @@ -1844,20 +1844,82 @@ void text_notes_configuration::add_attributes( const xml::attributes_wc_ptr & At
CP_APPLY_ATTR(L"text:footnotes-position", text_footnotes_position_);

}

void text_notes_configuration::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
{

if CP_CHECK_NAME(L"text", L"note-continuation-notice-forward")
CP_CREATE_ELEMENT(text_note_continuation_notice_forward_);
else if CP_CHECK_NAME(L"text", L"note-continuation-notice-backward")
CP_CREATE_ELEMENT(text_note_continuation_notice_backward_);
else
CP_NOT_APPLICABLE_ELM();
}
// text:linenumbering-configuration
//-------------------------------------------------------------------------------------------------------
const wchar_t * text_linenumbering_configuration::ns = L"text";
const wchar_t * text_linenumbering_configuration::name = L"linenumbering-configuration";

/// style:presentation-page-layout
//////////////////////////////////////////////////////////////////////////////////////////////////
void text_linenumbering_configuration::add_attributes(const xml::attributes_wc_ptr & Attributes)
{
CP_APPLY_ATTR(L"text:style-name", text_style_name_);
CP_APPLY_ATTR(L"text:number-lines", text_number_lines_, true);
CP_APPLY_ATTR(L"style:num-format", style_num_format_);
CP_APPLY_ATTR(L"style:num-letter-sync", style_num_letter_sync_);
CP_APPLY_ATTR(L"text:count-empty-lines", text_count_empty_lines_);
CP_APPLY_ATTR(L"text:count-in-text-boxes", text_count_in_text_boxes_);
CP_APPLY_ATTR(L"text:increment", text_increment_);
CP_APPLY_ATTR(L"text:number-position", text_number_position_); //inner, left, outer, right
CP_APPLY_ATTR(L"text:offset", text_offset_);
CP_APPLY_ATTR(L"text:restart-on-page", text_restart_on_page_);
}
void text_linenumbering_configuration::add_child_element(xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
{
if CP_CHECK_NAME(L"text", L"linenumbering-separator")
CP_CREATE_ELEMENT(text_linenumbering_separator_);
}

void text_linenumbering_configuration::docx_serialize(std::wostream & strm, oox::docx_conversion_context & Context)
{
if (!text_number_lines_) return;

CP_XML_WRITER(strm)
{
CP_XML_NODE(L"w:lnNumType")
{
if (text_increment_)
{
CP_XML_ATTR(L"w:countBy", *text_increment_);
}
if (text_restart_on_page_ && (*text_restart_on_page_))
{
CP_XML_ATTR(L"w:restart", L"newPage");
}
else
{
CP_XML_ATTR(L"w:restart", L"continuous");
}
if (text_offset_)
{
CP_XML_ATTR(L"w:distance", 20. * text_offset_->get_value_unit(length::pt));
}
}
}
}
// text:linenumbering-separator
//-------------------------------------------------------------------------------------------------------
const wchar_t * text_linenumbering_separator::ns = L"text";
const wchar_t * text_linenumbering_separator::name = L"linenumbering-separator";

void text_linenumbering_separator::add_attributes(const xml::attributes_wc_ptr & Attributes)
{
CP_APPLY_ATTR(L"text:increment", text_increment_);
}
void text_linenumbering_separator::add_text(const std::wstring & Text)
{
text_ = Text;
}

// style:presentation-page-layout
//-------------------------------------------------------------------------------------------------------
const wchar_t * style_presentation_page_layout::ns = L"style";
const wchar_t * style_presentation_page_layout::name = L"presentation-page-layout";

Expand Down
Loading