[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - sw/inc sw/qa sw/source

Michael Stahl mstahl at redhat.com
Mon Nov 6 15:10:28 UTC 2017


 sw/inc/unodraw.hxx                                  |    4 +--
 sw/qa/extras/odfimport/data/Word2010AsCharShape.odt |binary
 sw/qa/extras/odfimport/odfimport.cxx                |    9 +++++++
 sw/source/core/unocore/unodraw.cxx                  |   23 +++++++++++++-------
 sw/source/uibase/uno/unotxdoc.cxx                   |    4 +--
 5 files changed, 29 insertions(+), 11 deletions(-)

New commits:
commit 0edc289c7660bd2556ce46f6492163bbf0e1a340
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu Nov 2 22:13:32 2017 +0100

    sw: ODF import: default as-char shapes to vertical-pos="top"
    
    The problem is that we don't render ShapesWithWrapping.odt
    the same as Word does:
    
    https://beta.opendocumentformat.org/rendercompare/upload/223/86/191/1
    
    The first shape in the file is anchored "as-char" and has no
    style:vertical-rel or style:vertical-pos attribute affecting it.
    
    If Word would write either style:vertical-rel="baseline" or
    style:vertical-pos="top" explicitly, the rendering in LO would
    be the same.
    
    So the problem is that, for drawing shapes (note, text frames are
    images, embedded objects handled differently), LO's default
    vertical alignment is different, it is hard-coded in
    SwShapeDescriptor_Impl::GetVOrient() as
    SwFormatVertOrient(0, text::VertOrientation::NONE, text::RelOrientation::FRAME)
    
    This effectively positions as-char shapes *below* the baseline,
    which, while technically allowed, isn't really a good default.
    
    So fix this by making the default alignment dependent on the anchor
    type, so that as-char shapes sit on top of the baseline.
    
    The ODF filter sets the anchor type before inserting the shape in
    XMLTextShapeImportHelper::addShape(), however as it turns out the
    various MSO filters insert the shape before setting the anchor,
    which means the new default in SwXShape has an unwanted effect
    on them, as inserting the shape causes the default to be created.
    
    ... this backport does not include the various changes to MSO
    filters but instead just checks that we're in ODF import.
    
    Change-Id: Ifcabd96a037515f7803f5474ec995f968b3b4de1
    (cherry picked from commit c79467ba954987f1d239c594c1e1b3af3f5515f6)
    Reviewed-on: https://gerrit.libreoffice.org/44239
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/inc/unodraw.hxx b/sw/inc/unodraw.hxx
index 132d74eb8234..123b4e771745 100644
--- a/sw/inc/unodraw.hxx
+++ b/sw/inc/unodraw.hxx
@@ -214,7 +214,7 @@ protected:
     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
 
 public:
-    SwXShape(css::uno::Reference< css::uno::XInterface > & xShape);
+    SwXShape(css::uno::Reference< css::uno::XInterface > & xShape, SwDoc * pDoc = nullptr);
 
     static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
@@ -274,7 +274,7 @@ class SwXGroupShape :
 protected:
     virtual ~SwXGroupShape() override;
 public:
-    SwXGroupShape(css::uno::Reference< css::uno::XInterface > & xShape);
+    SwXGroupShape(css::uno::Reference< css::uno::XInterface > & xShape, SwDoc * pDoc = nullptr);
 
     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
     virtual void SAL_CALL acquire(  ) throw() override;
diff --git a/sw/qa/extras/odfimport/data/Word2010AsCharShape.odt b/sw/qa/extras/odfimport/data/Word2010AsCharShape.odt
new file mode 100644
index 000000000000..06c917f6a825
Binary files /dev/null and b/sw/qa/extras/odfimport/data/Word2010AsCharShape.odt differ
diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx
index 9f871c08ea4e..f51e22b6db11 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -20,6 +20,7 @@
 #include <com/sun/star/text/XTextSection.hpp>
 #include <com/sun/star/text/XTextTable.hpp>
 #include <com/sun/star/text/PageNumberType.hpp>
+#include <com/sun/star/text/VertOrientation.hpp>
 
 #include <wrtsh.hxx>
 #include <ndtxt.hxx>
@@ -792,6 +793,14 @@ DECLARE_ODFIMPORT_TEST(testTdf100033_1, "tdf100033_1.odt")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
 }
 
+DECLARE_ODFIMPORT_TEST(testWordAsCharShape, "Word2010AsCharShape.odt")
+{
+    // As-char shape had VertOrient "from-top"/NONE default from GetVOrient()
+    uno::Reference<drawing::XShape> const xShape(getShape(1));
+    CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, getProperty<text::TextContentAnchorType>(xShape, "AnchorType"));
+    CPPUNIT_ASSERT_EQUAL(text::VertOrientation::TOP, getProperty<sal_Int16>(xShape, "VertOrient"));
+}
+
 DECLARE_ODFIMPORT_TEST(testTdf100033_2, "tdf100033_2.odt")
 {
     // Test document have three different frames anchored to different paragraphs -> import all frames
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index 63d50325deed..4d9e3a29df3d 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -72,6 +72,7 @@ using namespace ::com::sun::star;
 
 class SwShapeDescriptor_Impl
 {
+    bool m_isInXMLImport;
     SwFormatHoriOrient*    pHOrient;
     SwFormatVertOrient*    pVOrient;
     SwFormatAnchor*        pAnchor;
@@ -94,7 +95,8 @@ public:
     bool    bInitializedPropertyNotifier;
 
 public:
-    SwShapeDescriptor_Impl() :
+    SwShapeDescriptor_Impl(SwDoc *const pDoc) :
+        m_isInXMLImport(pDoc && pDoc->IsInXMLImport()),
      // #i32349# - no defaults, in order to determine on
      // adding a shape, if positioning attributes are set or not.
      pHOrient( nullptr ),
@@ -148,8 +150,15 @@ public:
         {
             if(bCreate && !pVOrient)
             {
-                // #i26791#
-                pVOrient = new SwFormatVertOrient( 0, text::VertOrientation::NONE, text::RelOrientation::FRAME );
+                if (m_isInXMLImport &&
+                    (!GetAnchor(true) || pAnchor->GetAnchorId() == RndStdIds::FLY_AS_CHAR))
+                {   // for as-char, NONE ("from-top") is not a good default
+                    pVOrient = new SwFormatVertOrient(0, text::VertOrientation::TOP, text::RelOrientation::FRAME);
+                }
+                else
+                {   // #i26791#
+                    pVOrient = new SwFormatVertOrient(0, text::VertOrientation::NONE, text::RelOrientation::FRAME);
+                }
             }
             return pVOrient;
         }
@@ -878,10 +887,10 @@ namespace
     }
 }
 
-SwXShape::SwXShape(uno::Reference< uno::XInterface > & xShape) :
+SwXShape::SwXShape(uno::Reference< uno::XInterface > & xShape, SwDoc *const pDoc) :
     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_SHAPE)),
     m_pPropertyMapEntries(aSwMapProvider.GetPropertyMapEntries(PROPERTY_MAP_TEXT_SHAPE)),
-    pImpl(new SwShapeDescriptor_Impl()),
+    pImpl(new SwShapeDescriptor_Impl(pDoc)),
     m_bDescriptor(true)
 {
     if(xShape.is())  // default Ctor
@@ -2698,8 +2707,8 @@ css::drawing::PolyPolygonBezierCoords SwXShape::ConvertPolyPolygonBezierToLayout
     return aConvertedPath;
 }
 
-SwXGroupShape::SwXGroupShape(uno::Reference< XInterface > & xShape) :
-        SwXShape(xShape)
+SwXGroupShape::SwXGroupShape(uno::Reference< XInterface > & xShape, SwDoc *const pDoc) :
+        SwXShape(xShape, pDoc)
 {
 #if OSL_DEBUG_LEVEL > 0
     uno::Reference<XShapes> xShapes(xShapeAgg, uno::UNO_QUERY);
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 45606c4193f9..180c57b734cc 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -1682,11 +1682,11 @@ css::uno::Reference<css::uno::XInterface> SwXTextDocument::create(
     if (rServiceName == "com.sun.star.drawing.GroupShape"
         || rServiceName == "com.sun.star.drawing.Shape3DSceneObject")
     {
-        return *new SwXGroupShape(xTmp);
+        return *new SwXGroupShape(xTmp, pDocShell->GetDoc());
     }
     if (rServiceName.startsWith("com.sun.star.drawing."))
     {
-        return *new SwXShape(xTmp);
+        return *new SwXShape(xTmp, pDocShell->GetDoc());
     }
     return xTmp;
 }


More information about the Libreoffice-commits mailing list