[Libreoffice-commits] core.git: sw/qa sw/source

Patrick Jaap (via logerrit) logerrit at kemper.freedesktop.org
Fri Mar 22 16:02:52 UTC 2019


 sw/qa/extras/ooxmlexport/ooxmlexport4.cxx    |   11 ++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx |   37 +++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 2 deletions(-)

New commits:
commit 4f30b2ab729eb7f024e8078acbc099b25f588e9f
Author:     Patrick Jaap <patrick.jaap at tu-dresden.de>
AuthorDate: Thu Feb 14 10:00:36 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Mar 22 17:02:23 2019 +0100

    FIX: Use correct table x/y postion in docx export
    
    Until now we exported the original x/y position values of the table
    from the grabbag. Ignoring users actions like moving the table around.
    
    Now, we compute the position from the parent frame and write the actual position
    in the docx file.
    
    Change-Id: I25a09f9c7c8fbe49acbd19e2b1440c7fa90b8aff
    Reviewed-on: https://gerrit.libreoffice.org/67969
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index 5a27c6cec264..9fc349496f44 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -1237,6 +1237,17 @@ DECLARE_OOXMLEXPORT_TEST(testTdf81345_045Original,"tdf81345.docx")
 }
 #endif
 
+DECLARE_OOXMLEXPORT_TEST(testDocxTablePosition, "floating-table-position.docx")
+{
+    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+    if (!pXmlDoc)
+        return;
+
+    // the exported positions were wrong due to some missing shifting in the export code
+    assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblPr/w:tblpPr", "tblpX", "3494");
+    assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblPr/w:tblpPr", "tblpY", "4611");
+}
+
 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 0753ae83abf1..467af568afcb 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3802,6 +3802,8 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t
         {
             FastAttributeList *attrListTablePos = FastSerializerHelper::createAttrList( );
             uno::Sequence<beans::PropertyValue> aTablePosition = rGrabBagElement.second.get<uno::Sequence<beans::PropertyValue> >();
+            // look for a surrounding frame and take it's position values
+            const ww8::Frame* pFrame = m_rExport.GetFloatingTableFrame();
             for (sal_Int32 i = 0; i < aTablePosition.getLength(); ++i)
             {
                 if (aTablePosition[i].Name == "vertAnchor" && !aTablePosition[i].Value.get<OUString>().isEmpty())
@@ -3842,11 +3844,42 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t
                 }
                 else if (aTablePosition[i].Name == "tblpX")
                 {
-                    attrListTablePos->add( FSNS( XML_w, XML_tblpX ), OString::number( aTablePosition[i].Value.get<sal_Int32>() ) );
+                    sal_Int32 nValue = 0;
+                    if (pFrame)
+                    {
+                        nValue = pFrame->GetFrameFormat().GetHoriOrient().GetPos();
+                        // we need to revert the additional shift introduced by
+                        // lcl_DecrementHoriOrientPosition() in writerfilter
+                        // 1st: left distance of the table
+                        const SwTableBox * pTabBox = pTableTextNodeInfoInner->getTableBox();
+                        const SwFrameFormat * pFrameFormat = pTabBox->GetFrameFormat();
+                        const SvxBoxItem& rBox = pFrameFormat->GetBox( );
+                        sal_uInt16 nLeftDistance = rBox.GetDistance(SvxBoxItemLine::LEFT);
+                        nValue += nLeftDistance;
+
+                        // 2nd: if a left border is given, revert the shift by half the width
+                        // from lcl_DecrementHoriOrientPosition() in writerfilter
+                        if (const editeng::SvxBorderLine* pLeftBorder = rBox.GetLeft())
+                        {
+                            long nWidth = pLeftBorder->GetWidth();
+                            nValue += (nWidth / 2);
+                        }
+                    }
+                    else
+                        nValue = aTablePosition[i].Value.get<sal_Int32>();
+
+                    attrListTablePos->add( FSNS( XML_w, XML_tblpX ), OString::number( nValue ) );
                 }
                 else if (aTablePosition[i].Name == "tblpY")
                 {
-                    attrListTablePos->add( FSNS( XML_w, XML_tblpY ), OString::number( aTablePosition[i].Value.get<sal_Int32>() ) );
+                    sal_Int32 nValue = 0;
+                    if (pFrame)
+                        // no additional shift occur (like in the tblpX case)
+                        nValue = pFrame->GetFrameFormat().GetVertOrient().GetPos();
+                    else
+                        nValue = aTablePosition[i].Value.get<sal_Int32>();
+
+                    attrListTablePos->add( FSNS( XML_w, XML_tblpY ), OString::number( nValue ) );
                 }
             }
 


More information about the Libreoffice-commits mailing list