[Libreoffice-commits] core.git: Branch 'distro/nisz/libreoffice-6-4' - sw/qa writerfilter/source

Szabolcs Toth (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 31 11:47:04 UTC 2020


 sw/qa/extras/ooxmlexport/data/tdf120760_ZOrderInHeader.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport5.cxx                   |   16 +++++++++++
 writerfilter/source/dmapper/GraphicImport.cxx               |   17 +++++++++---
 3 files changed, 29 insertions(+), 4 deletions(-)

New commits:
commit eab422c01c5595479c7aa33d13cb633bd5a4cafe
Author:     Szabolcs Toth <szabolcs450 at gmail.com>
AuthorDate: Thu Jun 18 15:58:32 2020 +0200
Commit:     Gabor Kelemen <kelemen.gabor2 at nisz.hu>
CommitDate: Fri Jul 31 13:46:31 2020 +0200

    tdf#120760 DOCX shape import: fix Z-order with behindDoc
    
    DrawingML attribute relativeHeight contains z-indices
    for shape Z-order, but this depends on behindDoc, too.
    
    We can use z-index = relativeHeight - MAX_INT32 on shapes
    with behindDoc=true, as a simple workaround to get correct
    Z-order, because unsigned relativeHeight values stored in
    sal_Int32, and MIN_INT32 <= -MAX_INT32, and the temporary
    negative z-indices will converted by GraphicZOrderHelper.
    
    Note: this commit doesn't fix the old writerfilter
    implementation problem, that DOCX relativeHeight is an
    unsignedInt value according to W3C XML Schema, i.e. its
    maximal value is 4294967295 (MAX_UINT32), not 2147483647
    (MAX_INT32).
    
    Co-authored-by: Balázs Regényi
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96614
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>
    (cherry picked from commit 6479096dc2bd40215ff80273b4d27cadb2688cb1)
    
    Change-Id: I54a72a95bc69b307b2835636fff376b0aa9bc45c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99832
    Tested-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
    Reviewed-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf120760_ZOrderInHeader.docx b/sw/qa/extras/ooxmlexport/data/tdf120760_ZOrderInHeader.docx
new file mode 100644
index 000000000000..77a6d48dd866
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf120760_ZOrderInHeader.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index bfdab8a541aa..c5441fae765a 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -1236,6 +1236,22 @@ DECLARE_OOXMLEXPORT_TEST(testTdf112287, "tdf112287.docx")
     assertXPath(pXmlDocument, "/w:document/w:body/w:p[2]/w:pPr/w:framePr","vAnchor","margin");
 }
 
+DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testZOrderInHeader, "tdf120760_ZOrderInHeader.docx")
+{
+    // tdf#120760 Check that the Z-Order of the background is smaller than the front shape's.
+    xmlDocPtr pXml = parseExport("word/header1.xml");
+    if (!pXml)
+        return;
+
+    // Get the Z-Order of the background image and of the shape in front of it.
+    sal_Int32 nBackground = getXPath(pXml, "/w:hdr/w:p[1]/w:r[1]/w:drawing/wp:anchor", "relativeHeight").toInt32();
+    sal_Int32 nFrontShape = getXPath(pXml, "/w:hdr/w:p[1]/w:r[1]/mc:AlternateContent[2]"
+        "/mc:Choice/w:drawing/wp:anchor", "relativeHeight").toInt32();
+
+    // Assert that background is in the back.
+    CPPUNIT_ASSERT(nBackground < nFrontShape);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 8ebc0cdc3a43..16c65cdc1097 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -202,6 +202,7 @@ public:
     bool      bLayoutInCell;
     bool bAllowOverlap = true;
     bool      bOpaque;
+    bool      bBehindDoc;
     bool      bContour;
     bool      bContourOutside;
     WrapPolygon::Pointer_t mpWrapPolygon;
@@ -267,6 +268,7 @@ public:
         ,nWrap(text::WrapTextMode_NONE)
         ,bLayoutInCell(true)
         ,bOpaque( !rDMapper.IsInHeaderFooter() )
+        ,bBehindDoc(false)
         ,bContour(false)
         ,bContourOutside(true)
         ,nLeftMargin(319)
@@ -364,10 +366,15 @@ public:
     {
         if (zOrder >= 0)
         {
+            // tdf#120760 Send objects with behinddoc=true to the back.
+            sal_Int32 nZOrder = zOrder;
+            if (bBehindDoc && rDomainMapper.IsInHeaderFooter())
+                nZOrder -= SAL_MAX_INT32;
             GraphicZOrderHelper* pZOrderHelper = rDomainMapper.graphicZOrderHelper();
             bool bOldStyle = eGraphicImportType == GraphicImportType::IMPORT_AS_DETECTED_INLINE;
-            xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_Z_ORDER), uno::makeAny(pZOrderHelper->findZOrder(zOrder, bOldStyle)));
-            pZOrderHelper->addItem(xGraphicObjectProperties, zOrder);
+            xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_Z_ORDER),
+                uno::makeAny(pZOrderHelper->findZOrder(nZOrder, bOldStyle)));
+            pZOrderHelper->addItem(xGraphicObjectProperties, nZOrder);
         }
     }
 
@@ -602,8 +609,11 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
             m_pImpl->zOrder = nIntValue;
         break;
         case NS_ooxml::LN_CT_Anchor_behindDoc: // 90989; - in background
-            if( nIntValue > 0 )
+            if (nIntValue > 0)
+            {
                 m_pImpl->bOpaque = false;
+                m_pImpl->bBehindDoc = true;
+            }
         break;
         case NS_ooxml::LN_CT_Anchor_locked: // 90990; - ignored
         break;
@@ -1394,7 +1404,6 @@ uno::Reference<text::XTextContent> GraphicImport::createGraphicObject(uno::Refer
 
             xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_BACK_COLOR ),
                 uno::makeAny( GraphicImport_Impl::nFillColor ));
-
             m_pImpl->applyZOrder(xGraphicObjectProperties);
 
             //there seems to be no way to detect the original size via _real_ API


More information about the Libreoffice-commits mailing list