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

Mike Kaganski mike.kaganski at collabora.com
Mon Nov 23 03:32:40 PST 2015


 sw/qa/extras/ooxmlimport/data/tdf60351.docx        |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx           |   24 ++++++++++++
 writerfilter/source/dmapper/GraphicImport.cxx      |   39 +++++++++++++++------
 writerfilter/source/dmapper/WrapPolygonHandler.cxx |   23 ++++++++++++
 writerfilter/source/dmapper/WrapPolygonHandler.hxx |    1 
 5 files changed, 76 insertions(+), 11 deletions(-)

New commits:
commit d59ef5b2ddb9249905fecf941be6ec83251d12de
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Sat Nov 21 16:18:38 2015 +1000

    tdf#60351: Use Wrap Polygon also for PROP_SIZE_PIXEL
    
    Since commit 2b5bf2f1c57d6585ec898c4c44a74c5b47f09ab9
    "graphic import improved" from 2006-11-20 by Oliver Specht,
    there is an unused code reading pixel size (PROP_SIZE_PIXEL) of an
    image in a part of GraphicImport::createGraphicObject() that imports
    the wrap polygon.
    When there's no PROP_SIZE100th_M_M in graphic, the imported wrap
    polygon was simply dropped, and then automatic contour was generated
    for graphic. Now we import contour correctly in this case.
    
    Also, as paragraph background overlaps non-opaque graphics,
    we need to set opaque to true regardless of behindDoc value of
    wp:anchor.
    
    Change-Id: Ifa5eec9f8ccaf5ba051732b6e4f965ae8606a1cf
    Reviewed-on: https://gerrit.libreoffice.org/20103
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/sw/qa/extras/ooxmlimport/data/tdf60351.docx b/sw/qa/extras/ooxmlimport/data/tdf60351.docx
new file mode 100644
index 0000000..b61294d
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf60351.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 8a11157..4eb7007 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -2931,6 +2931,30 @@ DECLARE_OOXMLIMPORT_TEST(testTdf95775, "tdf95775.docx")
     // This must not fail in layout
 }
 
+DECLARE_OOXMLIMPORT_TEST(testTdf60351, "tdf60351.docx")
+{
+    // Get the first image in the document and check its contour polygon.
+    // It should contain 6 points. Check their coordinates.
+    uno::Reference<beans::XPropertySet> xPropertySet(getShape(1), uno::UNO_QUERY);
+    css::drawing::PointSequenceSequence aPolyPolygon;
+    xPropertySet->getPropertyValue("ContourPolyPolygon") >>= aPolyPolygon;
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aPolyPolygon.getLength());
+    const css::drawing::PointSequence& aPolygon = aPolyPolygon[0];
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(6),   aPolygon.getLength());
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),   aPolygon[0].X);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),   aPolygon[0].Y);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(316), aPolygon[1].X);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),   aPolygon[1].Y);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(316), aPolygon[2].X);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(316), aPolygon[2].Y);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(158), aPolygon[3].X);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(298), aPolygon[3].Y);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),   aPolygon[4].X);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(316), aPolygon[4].Y);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),   aPolygon[5].X);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),   aPolygon[5].Y);
+}
+
 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 9cd8852..c5adee7 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1136,7 +1136,7 @@ uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const b
         if(xGraphic.is())
         {
             uno::Reference< beans::XPropertySet > xGraphicObjectProperties(
-            m_xTextFactory->createInstance("com.sun.star.text.TextGraphicObject"),
+                m_xTextFactory->createInstance("com.sun.star.text.TextGraphicObject"),
                 uno::UNO_QUERY_THROW);
             xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_GRAPHIC), uno::makeAny( xGraphic ));
             xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE),
@@ -1320,20 +1320,37 @@ uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const b
 
             //there seems to be no way to detect the original size via _real_ API
             uno::Reference< beans::XPropertySet > xGraphicProperties( xGraphic, uno::UNO_QUERY_THROW );
-            awt::Size aGraphicSize, aGraphicSizePixel;
-            xGraphicProperties->getPropertyValue(getPropertyName( PROP_SIZE100th_M_M )) >>= aGraphicSize;
-            xGraphicProperties->getPropertyValue(getPropertyName( PROP_SIZE_PIXEL )) >>= aGraphicSizePixel;
 
-            uno::Any aContourPolyPolygon;
-            if( aGraphicSize.Width && aGraphicSize.Height &&
-                m_pImpl->mpWrapPolygon.get() != nullptr)
+            if (m_pImpl->mpWrapPolygon.get() != nullptr)
             {
-                WrapPolygon::Pointer_t pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygon(aGraphicSize);
-                aContourPolyPolygon <<= pCorrected->getPointSequenceSequence();
+                uno::Any aContourPolyPolygon;
+                awt::Size aGraphicSize;
+                WrapPolygon::Pointer_t pCorrected;
+                xGraphicProperties->getPropertyValue(getPropertyName(PROP_SIZE100th_M_M)) >>= aGraphicSize;
+                if (aGraphicSize.Width && aGraphicSize.Height)
+                {
+                    pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygon(aGraphicSize);
+                }
+                else
+                {
+                    xGraphicProperties->getPropertyValue(getPropertyName(PROP_SIZE_PIXEL)) >>= aGraphicSize;
+                    if (aGraphicSize.Width && aGraphicSize.Height)
+                    {
+                        pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygonPixel(aGraphicSize);
+                    }
+                }
+                if (pCorrected)
+                {
+                    aContourPolyPolygon <<= pCorrected->getPointSequenceSequence();
+                    xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_CONTOUR_POLY_POLYGON),
+                        aContourPolyPolygon);
+                    // We should bring it to front, even if wp:anchor's behindDoc="1",
+                    // because otherwise paragraph background (if set) overlaps the graphic
+                    // TODO: if paragraph's background becomes bottommost, then remove this hack
+                    xGraphicObjectProperties->setPropertyValue("Opaque", uno::makeAny(true));
+                }
             }
 
-            xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_CONTOUR_POLY_POLYGON),
-                                                           aContourPolyPolygon);
 
             if(m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_INLINE || m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
             {
diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.cxx b/writerfilter/source/dmapper/WrapPolygonHandler.cxx
index 8a66e82..02732cf 100644
--- a/writerfilter/source/dmapper/WrapPolygonHandler.cxx
+++ b/writerfilter/source/dmapper/WrapPolygonHandler.cxx
@@ -111,6 +111,29 @@ WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSr
     return pResult;
 }
 
+WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygonPixel(const awt::Size & rSrcSize)
+{
+    WrapPolygon::Pointer_t pResult;
+
+    /*
+    * https://msdn.microsoft.com/en-us/library/ee342530.aspx
+    *
+    * Image wrapping polygons in Microsoft Word use a fixed coordinate space
+    * that is 21600 units x 21600 units. Coordinate (0,0) is the upper left
+    * corner of the image and coordinate (21600,21600) is the lower right
+    * corner of the image. Microsoft Word scales the size of the wrapping
+    * polygon units to fit the size of the image. The 21600 value is a legacy
+    * artifact from the drawing layer of early versions of Microsoft Office.
+    */
+    const long nWrap100Percent = 21600;
+
+    Fraction aScaleX(rSrcSize.Width, nWrap100Percent);
+    Fraction aScaleY(rSrcSize.Height, nWrap100Percent);
+    pResult = scale(aScaleX, aScaleY);
+
+    return pResult;
+}
+
 drawing::PointSequenceSequence WrapPolygon::getPointSequenceSequence() const
 {
     drawing::PointSequenceSequence aPolyPolygon(1L);
diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.hxx b/writerfilter/source/dmapper/WrapPolygonHandler.hxx
index e6f9175..d5122c5 100644
--- a/writerfilter/source/dmapper/WrapPolygonHandler.hxx
+++ b/writerfilter/source/dmapper/WrapPolygonHandler.hxx
@@ -50,6 +50,7 @@ public:
     WrapPolygon::Pointer_t move(const css::awt::Point & rMove);
     WrapPolygon::Pointer_t scale(const Fraction & rFractionX, const Fraction & rFractionY);
     WrapPolygon::Pointer_t correctWordWrapPolygon(const css::awt::Size & rSrcSize);
+    WrapPolygon::Pointer_t correctWordWrapPolygonPixel(const css::awt::Size & rSrcSize);
     css::drawing::PointSequenceSequence getPointSequenceSequence() const;
 };
 


More information about the Libreoffice-commits mailing list