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

Michael Stahl mstahl at redhat.com
Sun May 25 12:38:10 PDT 2014


 sw/qa/extras/ww8export/data/fdo77454.doc |binary
 sw/qa/extras/ww8export/ww8export.cxx     |   24 ++++++++++++++++++++++
 sw/source/filter/ww8/wrtw8esh.cxx        |   16 ++++++++++++---
 sw/source/filter/ww8/ww8graf.cxx         |   33 ++++++++++++++++++-------------
 4 files changed, 57 insertions(+), 16 deletions(-)

New commits:
commit 18959222dd3161df03e3f7213cf497819260d69f
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat May 24 18:02:31 2014 +0200

    fdo#77454: fix WW8 import/export of negative image crop
    
    The negative crop values were imported as large positive values, which
    caused the image to be rendered with 1 pixel width after commit
    2e5167528f7566dd9b000e50fc1610b7bf99132a.
    
    (cherry picked from commit 6d431ffb682d0e64b75b6267f369822ff0b0617e)
    
    Conflicts:
    	sw/qa/extras/ww8export/ww8export.cxx
    
    Change-Id: I0e01b9d9a05d90e868699832085a06ba5aab7e54
    Reviewed-on: https://gerrit.libreoffice.org/9470
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/qa/extras/ww8export/data/fdo77454.doc b/sw/qa/extras/ww8export/data/fdo77454.doc
new file mode 100644
index 0000000..4e2d7b2
Binary files /dev/null and b/sw/qa/extras/ww8export/data/fdo77454.doc differ
diff --git a/sw/qa/extras/ww8export/ww8export.cxx b/sw/qa/extras/ww8export/ww8export.cxx
index 111af79..a9e8871 100644
--- a/sw/qa/extras/ww8export/ww8export.cxx
+++ b/sw/qa/extras/ww8export/ww8export.cxx
@@ -16,6 +16,7 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/view/XViewSettingsSupplier.hpp>
 #include <com/sun/star/table/ShadowFormat.hpp>
+#include <com/sun/star/text/GraphicCrop.hpp>
 
 class Test : public SwModelTestBase
 {
@@ -150,6 +151,29 @@ DECLARE_WW8EXPORT_TEST(testCharacterBorder, "charborder.odt")
     }
 }
 
+DECLARE_WW8EXPORT_TEST(testFdo77454, "fdo77454.doc")
+{
+    {
+        // check negative crops round-trip
+        text::GraphicCrop const crop =
+            getProperty<text::GraphicCrop>(getShape(1), "GraphicCrop");
+        CPPUNIT_ASSERT_EQUAL(sal_Int32( -439), crop.Left);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(-7040), crop.Right);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32( -220), crop.Top);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(-7040), crop.Bottom);
+    }
+
+    {
+        // check positive crops round-trip
+        text::GraphicCrop const crop =
+            getProperty<text::GraphicCrop>(getShape(2), "GraphicCrop");
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(  326), crop.Left);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32( 1208), crop.Right);
+        CPPUNIT_ASSERT(abs(sal_Int32(1635) -  crop.Top) <= 2);
+        CPPUNIT_ASSERT(abs(sal_Int32(  95) - crop.Bottom) <= 2);
+    }
+}
+
 DECLARE_WW8EXPORT_TEST(testFdo59530, "fdo59530.doc")
 {
     // See ooxmlexport's testFdo38244().
diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx
index e3b5542..9729d23 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -2228,9 +2228,19 @@ sal_Int32 SwBasicEscherEx::ToFract16(sal_Int32 nVal, sal_uInt32 nMax) const
 {
     if (nMax)
     {
-        sal_Int32 nMSVal = (nVal / 65536) * nMax;
-        nMSVal += (nVal * 65536 ) / nMax;
-        return nMSVal;
+        if (nVal >= 0)
+        {
+            sal_Int32 nMSVal = (nVal / 65536) * nMax;
+            nMSVal += (nVal * 65536) / nMax;
+            return nMSVal;
+        } else {
+            // negative fraction does not have "-0", fractional part is always
+            // positive:  -0.4 represented as -1 + 0.6
+            sal_Int32 const nDiv = (nVal / sal_Int32(nMax)) - 1;
+            sal_uInt32 nMSVal = (nDiv << 16) & 0xffff0000;
+            nMSVal += (nVal * 65536) / sal_Int32(nMax) + (-nDiv * 65536);
+            return nMSVal;
+        }
     }
     return 0;
 }
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index 6ff803e..8051810 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -1991,6 +1991,13 @@ void SwWW8ImplReader::MapWrapIntoFlyFmt(SvxMSDffImportRec* pRecord,
     }
 }
 
+static sal_Int32 lcl_ConvertCrop(sal_uInt32 const nCrop, sal_Int32 const nSize)
+{
+    // cast to sal_Int32 to handle negative crop properly
+    return ((static_cast<sal_Int32>(nCrop) >> 16) * nSize)
+              + (((nCrop & 0xffff) * nSize) >> 16) ;
+}
+
 void
 SwWW8ImplReader::SetAttributesAtGrfNode(SvxMSDffImportRec const*const pRecord,
     SwFrmFmt *pFlyFmt, WW8_FSPA *pF )
@@ -2013,23 +2020,23 @@ SwWW8ImplReader::SetAttributesAtGrfNode(SvxMSDffImportRec const*const pRecord,
             pRecord->nCropFromLeft || pRecord->nCropFromRight )
         {
             SwCropGrf aCrop;            // Cropping is stored in 'fixed floats'
-                                        // 16.16 (it est fraction times total
+                                        // 16.16 (fraction times total
             if( pRecord->nCropFromTop ) //        image width or height resp.)
-                aCrop.SetTop( static_cast< sal_Int32 >(
-                (   ( (pRecord->nCropFromTop    >> 16   ) * rHeight )
-                  + (((pRecord->nCropFromTop    & 0xffff) * rHeight ) >> 16) )));
+            {
+                aCrop.SetTop(lcl_ConvertCrop(pRecord->nCropFromTop, rHeight));
+            }
             if( pRecord->nCropFromBottom )
-                aCrop.SetBottom( static_cast< sal_Int32 >(
-                (   ( (pRecord->nCropFromBottom >> 16   ) * rHeight )
-                  + (((pRecord->nCropFromBottom & 0xffff) * rHeight ) >> 16) )));
+            {
+                aCrop.SetBottom(lcl_ConvertCrop(pRecord->nCropFromBottom, rHeight));
+            }
             if( pRecord->nCropFromLeft )
-                aCrop.SetLeft( static_cast< sal_Int32 >(
-                (   ( (pRecord->nCropFromLeft   >> 16   ) * rWidth  )
-                  + (((pRecord->nCropFromLeft   & 0xffff) * rWidth  ) >> 16) )));
+            {
+                aCrop.SetLeft(lcl_ConvertCrop(pRecord->nCropFromLeft, rWidth));
+            }
             if( pRecord->nCropFromRight )
-                aCrop.SetRight( static_cast< sal_Int32 >(
-                (   ( (pRecord->nCropFromRight  >> 16   ) * rWidth  )
-                  + (((pRecord->nCropFromRight  & 0xffff) * rWidth  ) >> 16) )));
+            {
+                aCrop.SetRight(lcl_ConvertCrop(pRecord->nCropFromRight,rWidth));
+            }
 
             pGrfNd->SetAttr( aCrop );
         }


More information about the Libreoffice-commits mailing list