Kaydet (Commit) 421e6fc3 authored tarafından Regina Henschel's avatar Regina Henschel Kaydeden (comit) Thorsten Behrens

tdf#118375, tdf#70838 correct position of rotated shape in doc

Word relates the position to the unrotated shape in legacy doc
format. Writer uses the rotated shape. The patch corrects the
difference on import and export.

Change-Id: I25537123656e62d6ffae5118ee8d621a4b5c5be0
Reviewed-on: https://gerrit.libreoffice.org/70152
Tested-by: Jenkins
Reviewed-by: 's avatarRegina Henschel <rb.henschel@t-online.de>
üst 63497d3a
This diff was suppressed by a .gitattributes entry.
...@@ -223,6 +223,29 @@ DECLARE_WW8EXPORT_TEST(testBtlrCell, "btlr-cell.doc") ...@@ -223,6 +223,29 @@ DECLARE_WW8EXPORT_TEST(testBtlrCell, "btlr-cell.doc")
CPPUNIT_ASSERT_EQUAL(text::WritingMode2::TB_RL, getProperty<sal_Int16>(xC1, "WritingMode")); CPPUNIT_ASSERT_EQUAL(text::WritingMode2::TB_RL, getProperty<sal_Int16>(xC1, "WritingMode"));
} }
DECLARE_WW8EXPORT_TEST(testTdf118375export, "tdf118375_240degClockwise.doc")
{
// The input document has one custom shape, which is rotated 240deg. Check
// that it has the same position as in Word.
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent,
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("Could not get XDrawPagesSupplier", xDrawPagesSupplier.is());
uno::Reference<drawing::XDrawPages> xDrawPages(xDrawPagesSupplier->getDrawPages());
uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("Could not get xDrawPage", xDrawPage.is());
uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_MESSAGE("Could not get xShape", xShape.is());
uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps.is());
sal_Int32 nPosX, nPosY;
xShapeProps->getPropertyValue("HoriOrientPosition") >>= nPosX;
xShapeProps->getPropertyValue("VertOrientPosition") >>= nPosY;
// Allow some tolerance because rounding errors through integer arithmethic
// in rotation.
CPPUNIT_ASSERT_DOUBLES_EQUAL(5200.0, static_cast<double>(nPosX), 1.0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1152.0, static_cast<double>(nPosY), 1.0);
}
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -659,6 +659,7 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const ...@@ -659,6 +659,7 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const
WinwordAnchoring::ConvertPosition( rHOr, rVOr, rFormat ); WinwordAnchoring::ConvertPosition( rHOr, rVOr, rFormat );
Point aObjPos; Point aObjPos;
bool bHasHeightWidthSwapped(false);
if (RES_FLYFRMFMT == rFormat.Which()) if (RES_FLYFRMFMT == rFormat.Which())
{ {
SwRect aLayRect(rFormat.FindLayoutRect(false, &aObjPos)); SwRect aLayRect(rFormat.FindLayoutRect(false, &aObjPos));
...@@ -694,6 +695,7 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const ...@@ -694,6 +695,7 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const
const long nHeight = aRect.getHeight(); const long nHeight = aRect.getHeight();
aRect.setWidth( nHeight ); aRect.setWidth( nHeight );
aRect.setHeight( nWidth ); aRect.setHeight( nWidth );
bHasHeightWidthSwapped = true;
} }
} }
} }
...@@ -755,6 +757,34 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const ...@@ -755,6 +757,34 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const
//Nasty swap for bidi if necessary //Nasty swap for bidi if necessary
rWrt.MiserableRTLFrameFormatHack(nLeft, nRight, rFrameFormat); rWrt.MiserableRTLFrameFormatHack(nLeft, nRight, rFrameFormat);
// tdf#70838. Word relates the position to the unrotated rectangle,
// Writer to the rotated one. Because the rotation is around center,
// the difference counts half.
if(pObj && pObj->GetRotateAngle())
{
SwTwips nXOff;
SwTwips nYOff;
SwTwips nSnapWidth = pObj->GetSnapRect().getWidth();
SwTwips nSnapHeight = pObj->GetSnapRect().getHeight();
SwTwips nLogicWidth = pObj->GetLogicRect().getWidth();
SwTwips nLogicHeight = pObj->GetLogicRect().getHeight();
// +1 for to compensate integer arithmetic rounding errors
if(bHasHeightWidthSwapped)
{
nXOff = (nSnapWidth - nLogicHeight + 1) / 2;
nYOff = (nSnapHeight - nLogicWidth + 1) / 2;
}
else
{
nXOff = (nSnapWidth - nLogicWidth + 1) / 2;
nYOff = (nSnapHeight - nLogicHeight + 1) / 2;
}
nLeft += nXOff;
nRight += nXOff;
nTop += nYOff;
nBottom += nYOff;
}
//xaLeft/yaTop/xaRight/yaBottom - rel. to anchor //xaLeft/yaTop/xaRight/yaBottom - rel. to anchor
//(most of) the border is outside the graphic is word, so //(most of) the border is outside the graphic is word, so
//change dimensions to fit //change dimensions to fit
......
...@@ -2530,6 +2530,17 @@ SwFrameFormat* SwWW8ImplReader::Read_GrafLayer( long nGrafAnchorCp ) ...@@ -2530,6 +2530,17 @@ SwFrameFormat* SwWW8ImplReader::Read_GrafLayer( long nGrafAnchorCp )
return nullptr; return nullptr;
} }
// tdf#118375 Word relates position to the unrotated rectangle,
// Writer uses the rotated one.
if (pObject->GetRotateAngle())
{
tools::Rectangle aObjSnapRect(pObject->GetSnapRect()); // recalculates the SnapRect
pF->nXaLeft = aObjSnapRect.Left();
pF->nYaTop = aObjSnapRect.Top();
pF->nXaRight = aObjSnapRect.Right();
pF->nYaBottom = aObjSnapRect.Bottom();
}
bool bDone = false; bool bDone = false;
SdrObject* pOurNewObject = nullptr; SdrObject* pOurNewObject = nullptr;
bool bReplaceable = false; bool bReplaceable = false;
......
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