sw/qa/extras/ooxmlexport/data/tdf131539.odt |binary sw/qa/extras/ooxmlexport/data/tdf133035.docx |binary sw/qa/extras/ooxmlexport/data/tdf133065.odt |binary sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 45 +++++++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 76 +++++++++++++++++++++++++-- 5 files changed, 117 insertions(+), 4 deletions(-)
New commits: commit 5833acad1fe8a43ca532b7bb3136d93476532726 Author: Michael Stahl <[email protected]> AuthorDate: Thu Jan 13 12:27:20 2022 +0100 Commit: Michael Stahl <[email protected]> CommitDate: Thu Jan 13 17:22:29 2022 +0100 sw: DOCX export: don't export numPr to style, but only... ... if the outline level doesn't have numbering. This should fix the originally reported vague problem, in case it really is a problem. Change-Id: I12a7bc4cd9455e84b596b8e403421f04a515d393 diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 8e894d68117c..6d76edcd13de 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -8154,9 +8154,11 @@ void DocxAttributeOutput::ParaNumRule_Impl( const SwTextNode* pTextNd, sal_Int32 const sal_Int32 nTableSize = m_rExport.m_pUsedNumTable ? m_rExport.m_pUsedNumTable->size() : 0; const SwNumRule* pRule = nNumId > 0 && nNumId <= nTableSize ? (*m_rExport.m_pUsedNumTable)[nNumId-1] : nullptr; const bool bOutlineRule = pRule && pRule->IsOutlineRule(); + const bool bIsNumbered(pRule && pRule->Get(nLvl).GetNumberingType() != SVX_NUM_NUMBER_NONE); // Do not export outline rules (Chapter Numbering) as paragraph properties, only as style properties. - if ( !pTextNd || !bOutlineRule ) + // Only export them as style properties if the outline level actually applies numbering. + if ((!pTextNd && bIsNumbered) || !bOutlineRule) { m_pSerializer->startElementNS(XML_w, XML_numPr); m_pSerializer->singleElementNS(XML_w, XML_ilvl, commit 286cced269e44e1393caad792a184eecd5455b1a Author: Michael Stahl <[email protected]> AuthorDate: Wed Jan 12 20:39:21 2022 +0100 Commit: Michael Stahl <[email protected]> CommitDate: Thu Jan 13 12:29:18 2022 +0100 Revert "sw: DOCX export: don't export numPr to style from outline numrule" This reverts commit b6b63c7ce92f7cc830593dbdd639cfde4951b971. This doesn't work if there actually is numbering. Change-Id: I9a801d92d70733c13deaca1d624cb3cc60d43ac2 diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index f987ca7dfff0..8e894d68117c 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -8147,7 +8147,7 @@ void DocxAttributeOutput::ParaHyphenZone( const SvxHyphenZoneItem& rHyphenZone ) FSNS( XML_w, XML_val ), OString::boolean( !rHyphenZone.IsHyphen() ) ); } -void DocxAttributeOutput::ParaNumRule_Impl(const SwTextNode*, sal_Int32 nLvl, sal_Int32 nNumId) +void DocxAttributeOutput::ParaNumRule_Impl( const SwTextNode* pTextNd, sal_Int32 nLvl, sal_Int32 nNumId ) { if ( USHRT_MAX != nNumId ) { @@ -8155,9 +8155,8 @@ void DocxAttributeOutput::ParaNumRule_Impl(const SwTextNode*, sal_Int32 nLvl, sa const SwNumRule* pRule = nNumId > 0 && nNumId <= nTableSize ? (*m_rExport.m_pUsedNumTable)[nNumId-1] : nullptr; const bool bOutlineRule = pRule && pRule->IsOutlineRule(); - // Do not export outline rules (Chapter Numbering) as paragraph properties, - // neither as style properties - there's w:outlineLvl for that. - if (!bOutlineRule) + // Do not export outline rules (Chapter Numbering) as paragraph properties, only as style properties. + if ( !pTextNd || !bOutlineRule ) { m_pSerializer->startElementNS(XML_w, XML_numPr); m_pSerializer->singleElementNS(XML_w, XML_ilvl, commit e6f6cac6a36c1a63950871dfba22ad9565c0a0c6 Author: Attila Bakos <[email protected]> AuthorDate: Thu May 14 15:48:21 2020 +0200 Commit: Michael Stahl <[email protected]> CommitDate: Wed Jan 12 20:38:10 2022 +0100 tdf#133065 tdf#133602 DOCX export: fix OLE wrap regression caused by commit 2150fdc7d0f63288ac56c33cb898589512057642 (tdf#131539 DOCX export: fix position of OLE objects). The wrap setting of the anchored OLE object were not preserved. Note: It needs also z-order export for background mode. Co-authored-by: Tibor Nagy Change-Id: I7f8c48019157dda00bcc97a490c5f582eccf1b22 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94220 Tested-by: László Németh <[email protected]> Reviewed-by: László Németh <[email protected]> (cherry picked from commit 4bdff3c731a9f8ef11ffdae804a99a47f119ee50) diff --git a/sw/qa/extras/ooxmlexport/data/tdf133065.odt b/sw/qa/extras/ooxmlexport/data/tdf133065.odt new file mode 100644 index 000000000000..a5e1b3587a5d Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf133065.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 08ac6fb4ed86..193a1990b622 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -77,6 +77,33 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf123873, "tdf123873.docx") p_XmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:drawing/wp:anchor/wp:wrapTopAndBottom"); } +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(Tdf133065, "tdf133065.odt") +{ + auto pxmldoc = parseExport("word/document.xml"); + CPPUNIT_ASSERT(pxmldoc); + OUString aVal; + + aVal = getXPath(pxmldoc, "/w:document/w:body/w:p[3]/w:r[2]/w:object/v:shape/w10:wrap", "type"); + CPPUNIT_ASSERT(aVal.indexOf("square") > -1); + aVal = getXPath(pxmldoc, "/w:document/w:body/w:p[3]/w:r[2]/w:object/v:shape/w10:wrap", "side"); + CPPUNIT_ASSERT(aVal.indexOf("left") > -1); + + aVal = getXPath(pxmldoc, "/w:document/w:body/w:p[8]/w:r[2]/w:object/v:shape/w10:wrap", "type"); + CPPUNIT_ASSERT(aVal.indexOf("square") > -1); + aVal = getXPath(pxmldoc, "/w:document/w:body/w:p[8]/w:r[2]/w:object/v:shape/w10:wrap", "side"); + CPPUNIT_ASSERT(aVal.indexOf("right") > -1); + + aVal = getXPath(pxmldoc, "/w:document/w:body/w:p[12]/w:r[2]/w:object/v:shape/w10:wrap", "type"); + CPPUNIT_ASSERT(aVal.indexOf("square") > -1); + aVal = getXPath(pxmldoc, "/w:document/w:body/w:p[12]/w:r[2]/w:object/v:shape/w10:wrap", "side"); + CPPUNIT_ASSERT(aVal.indexOf("largest") > -1); + + aVal = getXPath(pxmldoc, "/w:document/w:body/w:p[20]/w:r[2]/w:object/v:shape/w10:wrap", "type"); + CPPUNIT_ASSERT(aVal.indexOf("topAndBottom") > -1); + + aVal = getXPath(pxmldoc, "/w:document/w:body/w:p[24]/w:r[2]/w:object/v:shape/w10:wrap", "type"); + CPPUNIT_ASSERT(aVal.indexOf("square") > -1); +} DECLARE_OOXMLIMPORT_TEST(testTdf129888vml, "tdf129888vml.docx") { diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index ef65e060583b..f987ca7dfff0 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -5573,6 +5573,31 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S FSNS( XML_r, XML_id ), sImageId.toUtf8(), FSNS( XML_o, XML_title ), "" ); + //export wrap settings + if(rFlyFrameFormat && rFlyFrameFormat->GetAnchor().GetAnchorId() != RndStdIds::FLY_AS_CHAR) + { + const SwFormatSurround aWrap = rFlyFrameFormat->GetSurround(); + bool bIsCountur = aWrap.IsContour(); + + if (aWrap.GetSurround() == text::WrapTextMode::WrapTextMode_NONE) + m_pSerializer->singleElementNS(XML_w10, XML_wrap, XML_type, "topAndBottom"); + if (aWrap.GetSurround() == text::WrapTextMode::WrapTextMode_PARALLEL && !bIsCountur) + m_pSerializer->singleElementNS(XML_w10, XML_wrap, XML_type, "square"); + if (aWrap.GetSurround() == text::WrapTextMode::WrapTextMode_PARALLEL && bIsCountur) + m_pSerializer->singleElementNS(XML_w10, XML_wrap, XML_type, "tight"); + if (aWrap.GetSurround() == text::WrapTextMode::WrapTextMode_DYNAMIC && !bIsCountur) + m_pSerializer->singleElementNS(XML_w10, XML_wrap, XML_type, "square", XML_side, "largest"); + if (aWrap.GetSurround() == text::WrapTextMode::WrapTextMode_LEFT && !bIsCountur) + m_pSerializer->singleElementNS(XML_w10, XML_wrap, XML_type, "square", XML_side, "left"); + if (aWrap.GetSurround() == text::WrapTextMode::WrapTextMode_RIGHT && !bIsCountur) + m_pSerializer->singleElementNS(XML_w10, XML_wrap, XML_type, "square", XML_side, "right"); + if (aWrap.GetSurround() == text::WrapTextMode::WrapTextMode_DYNAMIC && bIsCountur) + m_pSerializer->singleElementNS(XML_w10, XML_wrap, XML_type, "tight", XML_side, "largest"); + if (aWrap.GetSurround() == text::WrapTextMode::WrapTextMode_LEFT && bIsCountur) + m_pSerializer->singleElementNS(XML_w10, XML_wrap, XML_type, "tight", XML_side, "left"); + if (aWrap.GetSurround() == text::WrapTextMode::WrapTextMode_RIGHT && bIsCountur) + m_pSerializer->singleElementNS(XML_w10, XML_wrap, XML_type, "tight", XML_side, "right"); + } m_pSerializer->endElementNS( XML_v, XML_shape ); // OLE object definition commit bda711f33d9ec67a3b3507cf256fdf5d85b9ae23 Author: Attila Bakos <[email protected]> AuthorDate: Thu May 14 12:38:28 2020 +0200 Commit: Michael Stahl <[email protected]> CommitDate: Wed Jan 12 20:38:09 2022 +0100 tdf#133035 DOCX export: fix position of unnamed OLE Position export depended on OLE object names, instead of the type of anchoring. Follow-up of commit 2150fdc7d0f63288ac56c33cb898589512057642 (tdf#131539 DOCX export: fix position of OLE objects). Co-authored-by: Tibor Nagy (NISZ) Change-Id: Ib98a19cb012047f37a5830c81541ef00c55589dd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94190 Tested-by: László Németh <[email protected]> Reviewed-by: László Németh <[email protected]> (cherry picked from commit 45fe51bca2ab534cfe1139b734d839728225d6d9) diff --git a/sw/qa/extras/ooxmlexport/data/tdf133035.docx b/sw/qa/extras/ooxmlexport/data/tdf133035.docx new file mode 100644 index 000000000000..c28c119dbccc Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf133035.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 387924997f78..08ac6fb4ed86 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -189,6 +189,14 @@ DECLARE_OOXMLEXPORT_TEST(testTdf78352, "tdf78352.docx") CPPUNIT_ASSERT_LESS(150, nWidth); } +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(Tdf133035, "tdf133035.docx") +{ + auto pxml = parseExport("word/document.xml"); + CPPUNIT_ASSERT(pxml); + OUString aXmlVal = getXPath(pxml, "/w:document/w:body/w:p[1]/w:r[1]/w:object/v:shape", "style"); + CPPUNIT_ASSERT(aXmlVal.indexOf("margin-left:186.6pt") > -1); +} + DECLARE_OOXMLEXPORT_TEST(testTdf120315, "tdf120315.docx") { // tdf#120315 cells of the second column weren't vertically merged diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index f5d1587f1fca..ef65e060583b 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -5521,7 +5521,7 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S //This string will store the relative position for aPos OString aAnch; - if (!rFlyFrameFormat->GetName().isEmpty()) + if (rFlyFrameFormat && rFlyFrameFormat->GetAnchor().GetAnchorId() != RndStdIds::FLY_AS_CHAR) { //Get the horizontal alignment of the OLE via the frame format, to aHAlign OString aHAlign = convertToOOXMLHoriOrient(rFlyFrameFormat->GetHoriOrient().GetHoriOrient(), commit e541841852ded9ad1b8323c31cba9df37fab93a4 Author: Attila Bakos <[email protected]> AuthorDate: Thu Apr 9 17:10:22 2020 +0200 Commit: Michael Stahl <[email protected]> CommitDate: Wed Jan 12 20:38:09 2022 +0100 tdf#131539 DOCX export: fix position of OLE objects Keeping position of OLE objects anchored to text as a character. Co-developer: Tibor Nagy (NISZ) Change-Id: I9699250ae5c418f9994ea2a7a3b102681b042214 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91983 Tested-by: László Németh <[email protected]> Reviewed-by: László Németh <[email protected]> (cherry picked from commit 2150fdc7d0f63288ac56c33cb898589512057642) diff --git a/sw/qa/extras/ooxmlexport/data/tdf131539.odt b/sw/qa/extras/ooxmlexport/data/tdf131539.odt new file mode 100644 index 000000000000..d0e446522a0a Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf131539.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 01303d3e9937..387924997f78 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -497,6 +497,16 @@ DECLARE_OOXMLEXPORT_TEST(testHyphenationAuto, "hyphenation.odt") assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:pPrDefault/w:pPr/w:suppressAutoHyphens", "val", "true"); } +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf131539, "tdf131539.odt") +{ + //The positions of OLE objects were not exported, check if now it is exported correctly + xmlDocPtr p_XmlDoc = parseExport("word/document.xml"); + CPPUNIT_ASSERT(p_XmlDoc); + OUString aXmlVal = getXPath(p_XmlDoc, "/w:document/w:body/w:p[4]/w:r[1]/w:object/v:shape", "style"); + // This data was missing + CPPUNIT_ASSERT(aXmlVal.indexOf("margin-left:139.95")>-1); +} + 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 7874dcfa6d92..f5d1587f1fca 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -5515,11 +5515,53 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S m_pSerializer->startElementNS(XML_w, XML_object); } + //tdf#131539: Export OLE positions in docx: + //This string will store the position output for the xml + OString aPos; + //This string will store the relative position for aPos + OString aAnch; + + if (!rFlyFrameFormat->GetName().isEmpty()) + { + //Get the horizontal alignment of the OLE via the frame format, to aHAlign + OString aHAlign = convertToOOXMLHoriOrient(rFlyFrameFormat->GetHoriOrient().GetHoriOrient(), + rFlyFrameFormat->GetHoriOrient().IsPosToggle()); + //Get the vertical alignment of the OLE via the frame format to aVAlign + OString aVAlign = convertToOOXMLVertOrient(rFlyFrameFormat->GetVertOrient().GetVertOrient()); + + //Get the relative horizontal positions for the anchors + OString aHAnch = convertToOOXMLHoriOrientRel(rFlyFrameFormat->GetHoriOrient().GetRelationOrient()); + //Get the relative vertical positions for the anchors + OString aVAnch = convertToOOXMLVertOrientRel(rFlyFrameFormat->GetVertOrient().GetRelationOrient()); + + //Choice that the horizontal position is relative or not + if (!aHAlign.isEmpty()) + aHAlign = ";mso-position-horizontal:" + aHAlign; + aHAlign = ";mso-position-horizontal-relative:" + aHAnch; + + //Choice that the vertical position is relative or not + if (!aVAlign.isEmpty()) + aVAlign = ";mso-position-vertical:" + aVAlign; + aVAlign = ";mso-position-vertical-relative:" + aVAnch; + + //Set the anchoring information into one string for aPos + aAnch = aHAlign + aVAlign; + + //Query the positions to aPos from frameformat + aPos = + "position:absolute;margin-left:" + OString::number(double(rFlyFrameFormat->GetHoriOrient().GetPos()) / 20) + + "pt;margin-top:" + OString::number(double(rFlyFrameFormat->GetVertOrient().GetPos()) / 20) + "pt;"; + } + OString sShapeStyle = "width:" + OString::number( double( rSize.Width() ) / 20 ) + "pt;height:" + OString::number( double( rSize.Height() ) / 20 ) + "pt"; //from VMLExport::AddRectangleDimensions(), it does: value/20 OString sShapeId = "ole_" + sId; + //Export anchor setting, if it exists + if (!aPos.isEmpty() && !aAnch.isEmpty()) + sShapeStyle = aPos + sShapeStyle + aAnch; + // shape definition m_pSerializer->startElementNS( XML_v, XML_shape, XML_id, sShapeId.getStr(),
