From 07fb94655f4745eb4e80bf6e8d4cdd95371f23bb Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Sat, 9 Jul 2016 07:53:32 +0300 Subject: tdf#99090 docx export page-break only inside a paragraph If a paragraph hadn't been started yet, a w:r was being written directly in the /document/body which caused MSWord to complain about a corrupt document. Change-Id: Ie7f629869aab0f3d2405660a033c3f23bbd6baca Reviewed-on: https://gerrit.libreoffice.org/26771 Tested-by: Jenkins Reviewed-by: Justin Luth Reviewed-by: Miklos Vajna --- .../ooxmlexport/data/tdf99090_pgbrkAfterTable.docx | Bin 0 -> 14726 bytes sw/qa/extras/ooxmlexport/ooxmlexport4.cxx | 7 +++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 16 +++++++++++++++- sw/source/filter/ww8/docxattributeoutput.hxx | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 sw/qa/extras/ooxmlexport/data/tdf99090_pgbrkAfterTable.docx diff --git a/sw/qa/extras/ooxmlexport/data/tdf99090_pgbrkAfterTable.docx b/sw/qa/extras/ooxmlexport/data/tdf99090_pgbrkAfterTable.docx new file mode 100755 index 000000000000..c914f350ea6f Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf99090_pgbrkAfterTable.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx index c4ab555cde6a..b837ae299803 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx @@ -965,6 +965,13 @@ DECLARE_OOXMLEXPORT_TEST(testTdf92521, "tdf92521.odt") assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:sectPr", 1); } +DECLARE_OOXMLEXPORT_TEST(testTdf99090_pgbrkAfterTable, "tdf99090_pgbrkAfterTable.docx") +{ + if (xmlDocPtr pXmlDoc = parseExport("word/document.xml")) + // There should be a regular page break that's in the middle of the document: right after the table. + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:br", 1); +} + DECLARE_OOXMLEXPORT_TEST(testTdf96750_landscapeFollow, "tdf96750_landscapeFollow.docx") { uno::Reference xStyle(getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index f4d2c8168410..84b6c74c5f39 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1065,6 +1065,16 @@ void DocxAttributeOutput::EndParagraphProperties(const SfxItemSet& rParagraphMar m_nColBreakStatus = COLBRK_NONE; } + if ( m_bPostponedPageBreak ) + { + m_pSerializer->startElementNS( XML_w, XML_r, FSEND ); + m_pSerializer->singleElementNS( XML_w, XML_br, + FSNS( XML_w, XML_type ), "page", FSEND ); + m_pSerializer->endElementNS( XML_w, XML_r ); + + m_bPostponedPageBreak = false; + } + // merge the properties _before_ the run (strictly speaking, just // after the start of the paragraph) m_pSerializer->mergeTopMarks(Tag_StartParagraphProperties, sax_fastparser::MergeMarks::PREPEND); @@ -5417,13 +5427,16 @@ void DocxAttributeOutput::SectionBreak( sal_uInt8 nC, const WW8_SepInfo* pSectio m_pSectionInfo.reset( new WW8_SepInfo( *pSectionInfo )); } } - else + else if ( m_bParagraphOpened ) { m_pSerializer->startElementNS( XML_w, XML_r, FSEND ); m_pSerializer->singleElementNS( XML_w, XML_br, FSNS( XML_w, XML_type ), "page", FSEND ); m_pSerializer->endElementNS( XML_w, XML_r ); } + else + m_bPostponedPageBreak = true; + break; default: OSL_TRACE( "Unknown section break to write: %d", nC ); @@ -8456,6 +8469,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri m_bAlternateContentChoiceOpen( false ), m_bPostponedProcessingFly( false ), m_nColBreakStatus( COLBRK_NONE ), + m_bPostponedPageBreak( false ), m_nTextFrameLevel( 0 ), m_closeHyperlinkInThisRun( false ), m_closeHyperlinkInPreviousRun( false ), diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index ab0a43aced06..6c17e76c5038 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -810,6 +810,10 @@ private: // beginning of the next paragraph DocxColBreakStatus m_nColBreakStatus; + // Remember that a page break has to be opened at the + // beginning of the next paragraph + bool m_bPostponedPageBreak; + std::vector m_aFramesOfParagraph; sal_Int32 m_nTextFrameLevel; -- cgit v1.2.3