[Libreoffice-commits] core.git: sw/inc sw/source xmloff/source

Armin Le Grand (CIB) Armin.Le.Grand at cib.de
Fri Feb 16 09:37:16 UTC 2018


 sw/inc/grfatr.hxx                          |   10 +++++++---
 sw/source/core/graphic/grfatr.cxx          |   28 +++++++++++++++++++++++++++-
 xmloff/source/text/XMLTextFrameContext.cxx |    8 ++++++++
 xmloff/source/text/txtparae.cxx            |    5 +++--
 4 files changed, 45 insertions(+), 6 deletions(-)

New commits:
commit 0e687595295e210e6275eda57a253ca66e8249ce
Author: Armin Le Grand <Armin.Le.Grand at cib.de (CIB)>
Date:   Thu Feb 15 15:41:50 2018 +0100

    tdf#115519: Handle rotation for WriterFlyFrames correctly
    
    Change-Id: I5f29b3640eaf24d63c64edfecd6732f336582640
    Reviewed-on: https://gerrit.libreoffice.org/49826
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Armin Le Grand <Armin.Le.Grand at cib.de>

diff --git a/sw/inc/grfatr.hxx b/sw/inc/grfatr.hxx
index 175bdcd480e3..f9e46068642a 100644
--- a/sw/inc/grfatr.hxx
+++ b/sw/inc/grfatr.hxx
@@ -87,14 +87,18 @@ public:
 
 class SwRotationGrf : public SfxUInt16Item
 {
+private:
     Size aUnrotatedSize;
+
+    // tdf#15529 check and evtl. correct value, it is in 10th
+    // degrees and *has* to be in the range [0 .. 3600[
+    sal_Int16 checkAndCorrectValue(sal_Int16 nValue);
+
 public:
     SwRotationGrf()
         : SfxUInt16Item( RES_GRFATR_ROTATION, 0 )
     {}
-    SwRotationGrf( sal_Int16 nVal, const Size& rSz )
-        : SfxUInt16Item( RES_GRFATR_ROTATION, nVal ), aUnrotatedSize( rSz )
-    {}
+    SwRotationGrf( sal_Int16 nVal, const Size& rSz );
 
     // pure virtual methods from SfxInt16Item
     virtual SfxPoolItem* Clone( SfxItemPool *pPool = nullptr ) const override;
diff --git a/sw/source/core/graphic/grfatr.cxx b/sw/source/core/graphic/grfatr.cxx
index 16565fe405e3..7300f574a26f 100644
--- a/sw/source/core/graphic/grfatr.cxx
+++ b/sw/source/core/graphic/grfatr.cxx
@@ -147,6 +147,31 @@ SfxPoolItem* SwCropGrf::Clone( SfxItemPool* ) const
     return new SwCropGrf( *this );
 }
 
+sal_Int16 SwRotationGrf::checkAndCorrectValue(sal_Int16 nValue)
+{
+    if(nValue < 0)
+    {
+        // smaller zero, modulo (will keep negative) and add one range
+        DBG_ASSERT(false, "SwRotationGrf: Value is in 10th degree and *has* to be in [0 .. 3600[ (!)");
+        return 3600 + (nValue % 3600);
+    }
+    else if (nValue > 3600)
+    {
+        // bigger range, use modulo
+        DBG_ASSERT(false, "SwRotationGrf: Value is in 10th degree and *has* to be in [0 .. 3600[ (!)");
+        return nValue % 3600;
+    }
+
+    return nValue;
+}
+
+SwRotationGrf::SwRotationGrf( sal_Int16 nVal, const Size& rSz )
+    // tdf#15529 check and evtl. correct value
+:   SfxUInt16Item( RES_GRFATR_ROTATION, checkAndCorrectValue(nVal) ),
+    aUnrotatedSize( rSz )
+{
+}
+
 SfxPoolItem* SwRotationGrf::Clone( SfxItemPool * ) const
 {
     return new SwRotationGrf( *this );
@@ -174,7 +199,8 @@ bool SwRotationGrf::PutValue( const uno::Any& rVal, sal_uInt8 )
     if (rVal >>= nValue)
     {
         // sal_uInt16 argument needed
-        SetValue( static_cast<sal_uInt16>(nValue) );
+        // tdf#15529 check and evtl. correct value
+        SetValue(static_cast<sal_uInt16>(checkAndCorrectValue(nValue)));
         return true;
     }
 
diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx
index 63ea2aa937f7..25b6b0441cf5 100644
--- a/xmloff/source/text/XMLTextFrameContext.cxx
+++ b/xmloff/source/text/XMLTextFrameContext.cxx
@@ -1027,6 +1027,14 @@ XMLTextFrameContext_Impl::XMLTextFrameContext_Impl(
                         // to me mirrored using * -1.0, see conversion there)
                         const double fRotate(aDecomposedTransform.getRotate() * (1800.0/M_PI));
                         nRotation = static_cast< sal_Int16 >(basegfx::fround(fRotate) % 3600);
+
+                        // tdf#115519 may be negative, with the above modulo maximal -3599, so
+                        // no loop needed here. nRotation is used in setPropertyValue("GraphicRotation")
+                        // and *has* to be in the range [0 .. 3600[
+                        if(nRotation < 0)
+                        {
+                            nRotation += 3600;
+                        }
                     }
                 }
             }
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 70859d4c4779..16a57ed09d23 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -3078,13 +3078,14 @@ void XMLTextParagraphExport::_exportTextGraphic(
         // we have a right-handed coordinate system, so need to correct this by mirroring
         // the rotation to get the correct transformation. See also case XML_TOK_TEXT_FRAME_TRANSFORM
         // in XMLTextFrameContext_Impl::XMLTextFrameContext_Impl and #i78696#
-        const double fRotate(static_cast< double >(-nRotation) * (M_PI/1800.0));
+        const double fRotate(static_cast< double >(-nRotation) * (F_PI/1800.0));
 
         // transform to rotation center which is the object's center
         aSdXMLImExTransform2D.AddTranslate(-aCenter);
 
         // add rotation itself
-        aSdXMLImExTransform2D.AddRotate(fRotate);
+        // tdf#115529 but correct value modulo 2PI to have it positive and in the range of [0.0 .. 2PI[
+        aSdXMLImExTransform2D.AddRotate(basegfx::normalizeToRange(fRotate, F_2PI));
 
         // back-transform after rotation
         aSdXMLImExTransform2D.AddTranslate(aCenter);


More information about the Libreoffice-commits mailing list