sw/qa/extras/ooxmlexport/data/lorem_hyperlink.fodt | 40 +++++++++++++++++++++ sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 6 +++ sw/source/filter/ww8/docxattributeoutput.cxx | 21 +++++------ sw/source/filter/ww8/docxattributeoutput.hxx | 2 - 4 files changed, 58 insertions(+), 11 deletions(-)
New commits: commit 619132f022b7a71938069d7c282aaf8b578287e5 Author: Tünde Tóth <toth.tu...@nisz.hu> AuthorDate: Mon Mar 6 15:34:57 2023 +0100 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Mon Mar 13 10:23:48 2023 +0000 tdf#149996 DOCX export: fix hyperlinks in nested paragraphs Close all hyperlinks in the paragraph where they start. Regression from commit 20a3792502120d67b1a9fdea641e15ea504359d3 "fdo#76316 : File gets corrupt after Roundtrip". Change-Id: Ied5be90601f5a494f927d43aa6ff7efd3545f993 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148353 Tested-by: Jenkins Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit 05df784c6febd1d77e95db8ef3dfdc03347a48a3) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148617 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/extras/ooxmlexport/data/lorem_hyperlink.fodt b/sw/qa/extras/ooxmlexport/data/lorem_hyperlink.fodt new file mode 100644 index 000000000000..485f87f130da --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/lorem_hyperlink.fodt @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:officeooo="http://openoffice.org/2009/office" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:styles> + <style:default-style style:family="graphic"> + <style:graphic-properties svg:stroke-color="#3465a4" draw:fill-color="#729fcf" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" draw:start-line-spacing-vertical="0.283cm" draw:end-line-spacing-horizontal="0.283cm" draw:end-line-spacing-vertical="0.283cm" style:writing-mode="lr-tb" style:flow-with-text="false"/> + <style:paragraph-properties style:text-autospace="ideograph-alpha" style:line-break="strict" style:font-independent-line-spacing="false"> + <style:tab-stops/> + </style:paragraph-properties> + <style:text-properties style:use-window-font-color="true" loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="en" fo:country="US" style:letter-kerning="true" style:font-name-asian="NSimSun" style:font-size-asian="10.5pt" style:language-asian="zh" style:country-asian="CN" style:font-name-complex="Lucida Sans1" style:font-size-complex="12pt" style:language-complex="hi" style:country-complex="IN"/> + </style:default-style> + <style:default-style style:family="paragraph"> + <style:paragraph-properties fo:orphans="2" fo:widows="2" fo:hyphenation-ladder-count="no-limit" style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" style:line-break="strict" style:tab-stop-distance="1.251cm" style:writing-mode="page"/> + <style:text-properties style:use-window-font-color="true" loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="en" fo:country="US" style:letter-kerning="true" style:font-name-asian="NSimSun" style:font-size-asian="10.5pt" style:language-asian="zh" style:country-asian="CN" style:font-name-complex="Lucida Sans1" style:font-size-complex="12pt" style:language-complex="hi" style:country-complex="IN" fo:hyphenate="false" fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2" loext:hyphenation-no-caps="false" loext:hyphenation-no-last-word="false" loext:hyphenation-word-char-count="5" loext:hyphenation-zone="no-limit"/> + </style:default-style> + <style:style style:name="Internet_20_link" style:display-name="Internet link" style:family="text"> + <style:text-properties fo:color="#000080" loext:opacity="100%" fo:language="zxx" fo:country="none" style:text-underline-style="solid" style:text-underline-width="auto" style:text-underline-color="font-color" style:language-asian="zxx" style:country-asian="none" style:language-complex="zxx" style:country-complex="none"/> + </style:style> + </office:styles> + <office:automatic-styles> + <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard"> + <style:text-properties officeooo:rsid="00102359" officeooo:paragraph-rsid="00102359"/> + </style:style> + <style:style style:name="P2" style:family="paragraph"> + <style:paragraph-properties style:writing-mode="lr-tb"/> + </style:style> + <style:style style:name="gr1" style:family="graphic"> + <style:graphic-properties draw:textarea-horizontal-align="justify" draw:textarea-vertical-align="middle" draw:auto-grow-height="false" fo:min-height="0.781cm" fo:min-width="0.808cm" style:writing-mode="lr-tb" style:run-through="foreground" style:wrap="run-through" style:number-wrapped-paragraphs="no-limit" style:vertical-pos="from-top" style:vertical-rel="paragraph" style:horizontal-pos="from-left" style:horizontal-rel="paragraph" draw:wrap-influence-on-position="once-concurrent" loext:allow-overlap="true" style:flow-with-text="false"/> + <style:paragraph-properties style:writing-mode="lr-tb"/> + </style:style> + </office:automatic-styles> + <office:body> + <office:text> + <text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#foo" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link">Lorem <draw:custom-shape text:anchor-type="char" draw:z-index="0" draw:name="Shape 1" draw:style-name="gr1" draw:text-style-name="P2" svg:width="1.615cm" svg:height="1.562cm" svg:x="1cm" svg:y="1cm"> + <text:p>1</text:p> + <draw:enhanced-geometry svg:viewBox="0 0 21600 21600" draw:glue-points="10800 0 0 10800 10800 21600 21600 10800" draw:text-areas="5400 5400 16200 16200" draw:type="diamond" draw:enhanced-path="M 10800 0 L 21600 10800 10800 21600 0 10800 10800 0 Z N"/> + </draw:custom-shape>ipsum</text:a></text:p> + </office:text> + </office:body> +</office:document> \ No newline at end of file diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index 4feae4b5d864..04ce5b8d452c 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -872,6 +872,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf152310, "ColorOverwritten.docx") getProperty<Color>(getParagraphOfText(2, xShape), "CharColor")); } +DECLARE_OOXMLEXPORT_TEST(testTdf149996, "lorem_hyperlink.fodt") +{ + // Without the accompanying fix in place, this test would have crashed, + // because the exported file was corrupted. +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index e8b73e338d8e..5bc2f7ba597f 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -530,6 +530,7 @@ sal_Int32 DocxAttributeOutput::StartParagraph(ww8::WW8TableNodeInfo::Pointer_t p m_bParagraphOpened = true; m_bIsFirstParagraph = false; + m_nHyperLinkCount.push(0); return nParaId; } @@ -1062,12 +1063,12 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT /* If m_nHyperLinkCount > 0 that means hyperlink tag is not yet closed. * This is due to nested hyperlink tags. So close it before end of paragraph. */ - if(m_nHyperLinkCount > 0) + if(m_nHyperLinkCount.top() > 0) { - for(sal_Int32 nHyperLinkToClose = 0; nHyperLinkToClose < m_nHyperLinkCount; ++nHyperLinkToClose) + for(sal_Int32 nHyperLinkToClose = 0; nHyperLinkToClose < m_nHyperLinkCount.top(); ++nHyperLinkToClose) m_pSerializer->endElementNS( XML_w, XML_hyperlink ); - m_nHyperLinkCount = 0; } + m_nHyperLinkCount.pop(); if (m_aRunSdt.m_bStartedSdt) { @@ -1658,7 +1659,7 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, sal_In m_pSerializer->endElementNS( XML_w, XML_hyperlink ); m_startedHyperlink = false; m_endPageRef = false; - m_nHyperLinkCount--; + m_nHyperLinkCount.top()--; } m_closeHyperlinkInPreviousRun = false; } @@ -1738,7 +1739,7 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, sal_In m_pSerializer->startElementNS( XML_w, XML_hyperlink, xAttrList ); m_startedHyperlink = true; - m_nHyperLinkCount++; + m_nHyperLinkCount.top()++; } // if there is some redlining in the document, output it @@ -1900,7 +1901,7 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, sal_In m_pSerializer->endElementNS( XML_w, XML_hyperlink ); m_startedHyperlink = false; - m_nHyperLinkCount--; + m_nHyperLinkCount.top()--; } m_closeHyperlinkInThisRun = false; } @@ -6958,8 +6959,8 @@ void DocxAttributeOutput::pushToTableExportContext(DocxTableExportContext& rCont rContext.m_bStartedRunSdt = m_aRunSdt.m_bStartedSdt; m_aRunSdt.m_bStartedSdt = false; - rContext.m_nHyperLinkCount = m_nHyperLinkCount; - m_nHyperLinkCount = 0; + rContext.m_nHyperLinkCount = m_nHyperLinkCount.top(); + m_nHyperLinkCount.top() = 0; } void DocxAttributeOutput::popFromTableExportContext(DocxTableExportContext const & rContext) @@ -6969,7 +6970,7 @@ void DocxAttributeOutput::popFromTableExportContext(DocxTableExportContext const m_tableReference->m_nTableDepth = rContext.m_nTableDepth; m_aParagraphSdt.m_bStartedSdt = rContext.m_bStartedParaSdt; m_aRunSdt.m_bStartedSdt = rContext.m_bStartedRunSdt; - m_nHyperLinkCount = rContext.m_nHyperLinkCount; + m_nHyperLinkCount.top() = rContext.m_nHyperLinkCount; } void DocxAttributeOutput::WriteTextBox(uno::Reference<drawing::XShape> xShape) @@ -10598,7 +10599,6 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, const FSHelperPtr m_closeHyperlinkInThisRun( false ), m_closeHyperlinkInPreviousRun( false ), m_startedHyperlink( false ), - m_nHyperLinkCount(0), m_nFieldsInHyperlink( 0 ), m_bExportingOutline(false), m_nChartCount(0), @@ -10615,6 +10615,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, const FSHelperPtr m_nParaAfterSpacing(0) , m_nStateOfFlyFrame( FLY_NOT_PROCESSED ) { + m_nHyperLinkCount.push(0); } DocxAttributeOutput::~DocxAttributeOutput() diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index b03a8dd9187b..490b215f1598 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -916,7 +916,7 @@ private: bool m_closeHyperlinkInPreviousRun; bool m_startedHyperlink; // Count nested HyperLinks - sal_Int32 m_nHyperLinkCount; + std::stack<sal_Int32> m_nHyperLinkCount; sal_Int16 m_nFieldsInHyperlink; // If the exported numbering rule defines the outlines