Kaydet (Commit) 0e687595 authored tarafından Armin Le Grand's avatar Armin Le Grand Kaydeden (comit) Armin Le Grand

tdf#115519: Handle rotation for WriterFlyFrames correctly

Change-Id: I5f29b3640eaf24d63c64edfecd6732f336582640
Reviewed-on: https://gerrit.libreoffice.org/49826Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarArmin Le Grand <Armin.Le.Grand@cib.de>
üst 3b93b176
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
}
}
}
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment