summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Le Grand <Armin.Le.Grand@cib.de (CIB)>2018-02-15 15:41:50 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2018-02-18 02:13:37 +0100
commit3369410324fdcc221339685154f3168544c5817d (patch)
treea0b949bc966a1d46fe1d673333267d747df14dc6
parent7bffc6f745c86124326472b3719c2cb63869ef55 (diff)
tdf#115529: Handle rotation for WriterFlyFrames correctly
Change-Id: I5f29b3640eaf24d63c64edfecd6732f336582640 Reviewed-on: https://gerrit.libreoffice.org/49826 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Armin Le Grand <Armin.Le.Grand@cib.de> Reviewed-on: https://gerrit.libreoffice.org/49853 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r--sw/inc/grfatr.hxx10
-rw-r--r--sw/source/core/graphic/grfatr.cxx28
-rw-r--r--xmloff/source/text/XMLTextFrameContext.cxx8
-rw-r--r--xmloff/source/text/txtparae.cxx5
4 files changed, 45 insertions, 6 deletions
diff --git a/sw/inc/grfatr.hxx b/sw/inc/grfatr.hxx
index b05c11b4dff9..71496f49f7ea 100644
--- a/sw/inc/grfatr.hxx
+++ b/sw/inc/grfatr.hxx
@@ -91,14 +91,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 545ee807ea0c..ef437d4ad2e7 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( (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 a7c806a185c8..118207cd00a4 100644
--- a/xmloff/source/text/XMLTextFrameContext.cxx
+++ b/xmloff/source/text/XMLTextFrameContext.cxx
@@ -1026,6 +1026,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 e8fefb009a3a..89351f976236 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -3082,13 +3082,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);