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

Michael Stahl mstahl at redhat.com
Sat May 24 09:38:40 PDT 2014


 include/filter/msfilter/msdffimp.hxx     |   26 ++++++++++++------------
 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 ++++++++++++++++++-------------
 5 files changed, 70 insertions(+), 29 deletions(-)

New commits:
commit 19b159416d7725ee3e304f5ca67e7d3926d0df92
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat May 24 18:17:55 2014 +0200

    SvxMSDffImportRec: these members are all 32bit "signed integers"
    
    Change-Id: Iee1dab4895970628e5f5c4ee6070f7f67ba2df8c

diff --git a/include/filter/msfilter/msdffimp.hxx b/include/filter/msfilter/msdffimp.hxx
index c290948..adba4b7 100644
--- a/include/filter/msfilter/msdffimp.hxx
+++ b/include/filter/msfilter/msdffimp.hxx
@@ -237,19 +237,19 @@ struct MSFILTER_DLLPUBLIC SvxMSDffImportRec
     sal_uInt32      *pYRelTo;
     sal_uInt32      nLayoutInTableCell;
     sal_uInt32      nFlags;
-    long            nTextRotationAngle;
-    long            nDxTextLeft;    ///< distance of text box from surrounding shape
-    long            nDyTextTop;
-    long            nDxTextRight;
-    long            nDyTextBottom;
-    long            nDxWrapDistLeft;
-    long            nDyWrapDistTop;
-    long            nDxWrapDistRight;
-    long            nDyWrapDistBottom;
-    long            nCropFromTop;
-    long            nCropFromBottom;
-    long            nCropFromLeft;
-    long            nCropFromRight;
+    sal_Int32       nTextRotationAngle;
+    sal_Int32       nDxTextLeft;    ///< distance of text box from surrounding shape
+    sal_Int32       nDyTextTop;
+    sal_Int32       nDxTextRight;
+    sal_Int32       nDyTextBottom;
+    sal_Int32       nDxWrapDistLeft;
+    sal_Int32       nDyWrapDistTop;
+    sal_Int32       nDxWrapDistRight;
+    sal_Int32       nDyWrapDistBottom;
+    sal_Int32       nCropFromTop;
+    sal_Int32       nCropFromBottom;
+    sal_Int32       nCropFromLeft;
+    sal_Int32       nCropFromRight;
     MSDffTxId       aTextId;        ///< identifier for text boxes
     sal_uLong       nNextShapeId;   ///< for linked text boxes
     sal_uLong       nShapeId;
commit 6d431ffb682d0e64b75b6267f369822ff0b0617e
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.
    
    Change-Id: I0e01b9d9a05d90e868699832085a06ba5aab7e54

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 d014dba..5857559 100644
--- a/sw/qa/extras/ww8export/ww8export.cxx
+++ b/sw/qa/extras/ww8export/ww8export.cxx
@@ -17,6 +17,7 @@
 #include <com/sun/star/view/XViewSettingsSupplier.hpp>
 #include <com/sun/star/table/ShadowFormat.hpp>
 #include <com/sun/star/table/TableBorder2.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 a5bf48a..0471950 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -2182,9 +2182,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 b4f28ab..ec4bf38 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -1972,6 +1972,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 )
@@ -1994,23 +2001,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