Kaydet (Commit) af843af4 authored tarafından Mike Kaganski's avatar Mike Kaganski

tdf#121844: properly implement autoTxRot support

... after commit cf7b97d1

Change-Id: If46265f49a85d92254fedb719d76ff7319c092cc
Reviewed-on: https://gerrit.libreoffice.org/64396
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 70769fc8
......@@ -802,20 +802,34 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
break;
}
// ECMA-376-1:2016 21.4.7.5 ST_AutoTextRotation (Auto Text Rotation)
const sal_Int32 nautoTxRot = maMap.count(XML_autoTxRot) ? maMap.find(XML_autoTxRot)->second : XML_upr;
sal_Int32 nShapeRot = rShape->getRotation();
while (nShapeRot < 0)
nShapeRot += 360 * PER_DEGREE;
while (nShapeRot > 360 * PER_DEGREE)
nShapeRot -= 360 * PER_DEGREE;
switch(nautoTxRot)
{
case XML_upr:
{
if (rShape->getRotation())
pTextBody->getTextProperties().moRotation = -F_PI180*90*rShape->getRotation();
int n90x = 0;
if (nShapeRot >= 315 * PER_DEGREE)
/* keep 0 */;
else if (nShapeRot > 225 * PER_DEGREE)
n90x = -3;
else if (nShapeRot >= 135 * PER_DEGREE)
n90x = -2;
else if (nShapeRot > 45 * PER_DEGREE)
n90x = -1;
pTextBody->getTextProperties().moRotation = n90x * 90 * PER_DEGREE;
}
break;
case XML_grav:
{
if (rShape->getRotation()==90*F_PI180 || rShape->getRotation()==180*F_PI180)
pTextBody->getTextProperties().moRotation = 180*F_PI180;
if (nShapeRot > (90 * PER_DEGREE) && nShapeRot < (270 * PER_DEGREE))
pTextBody->getTextProperties().moRotation = -180 * PER_DEGREE;
}
break;
case XML_none:
......
......@@ -28,6 +28,7 @@ public:
void testDir();
void testMaxDepth();
void testRotation();
void testTextAutoRotation();
void testPyramid();
void testChevron();
void testCycle();
......@@ -56,6 +57,7 @@ public:
CPPUNIT_TEST(testDir);
CPPUNIT_TEST(testMaxDepth);
CPPUNIT_TEST(testRotation);
CPPUNIT_TEST(testTextAutoRotation);
CPPUNIT_TEST(testPyramid);
CPPUNIT_TEST(testChevron);
CPPUNIT_TEST(testCycle);
......@@ -240,6 +242,95 @@ void SdImportTestSmartArt::testRotation()
xDocShRef->DoClose();
}
void SdImportTestSmartArt::testTextAutoRotation()
{
sd::DrawDocShellRef xDocShRef = loadURL(
m_directories.getURLFromSrc("sd/qa/unit/data/pptx/smartart-autoTxRot.pptx"), PPTX);
auto testText = [&](int pageNo, sal_Int32 txtNo, const OUString& expTx, sal_Int32 expShRot,
sal_Int32 expTxRot) {
OString msgText = "Page: " + OString::number(pageNo) + " text: " + OString::number(txtNo);
uno::Reference<drawing::XShapes> xShapeGroup(getShapeFromPage(0, pageNo, xDocShRef),
uno::UNO_QUERY_THROW);
uno::Reference<text::XText> xTxt(xShapeGroup->getByIndex(txtNo), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE(msgText.getStr(), expTx, xTxt->getString());
uno::Reference<beans::XPropertySet> xTxtProps(xTxt, uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE(msgText.getStr(), expShRot,
xTxtProps->getPropertyValue("RotateAngle").get<sal_Int32>());
auto aGeomPropSeq = xTxtProps->getPropertyValue("CustomShapeGeometry")
.get<uno::Sequence<beans::PropertyValue>>();
comphelper::SequenceAsHashMap aCustomShapeGeometry(aGeomPropSeq);
auto it = aCustomShapeGeometry.find("TextPreRotateAngle");
if (it == aCustomShapeGeometry.end())
{
CPPUNIT_ASSERT_EQUAL_MESSAGE(msgText.getStr(), sal_Int32(0), expTxRot);
}
else
{
CPPUNIT_ASSERT_EQUAL_MESSAGE(msgText.getStr(), expTxRot, it->second.get<sal_Int32>());
}
};
// Slide 1: absent autoTxRot => defaults to "upr"
testText(0, 0, "a", 0, 0);
testText(0, 1, "b", 33750, 0);
testText(0, 2, "c", 31500, 0);
testText(0, 3, "d", 29250, 90);
testText(0, 4, "e", 27000, 90);
testText(0, 5, "f", 24750, 90);
testText(0, 6, "g", 22500, 180);
testText(0, 7, "h", 20250, 180);
testText(0, 8, "i", 18000, 180);
testText(0, 9, "j", 15750, 180);
testText(0, 10, "k", 13500, 180);
testText(0, 11, "l", 11250, 270);
testText(0, 12, "m", 9000, 270);
testText(0, 13, "n", 6750, 270);
testText(0, 14, "o", 4500, 0);
testText(0, 15, "p", 2250, 0);
// Slide 2: autoTxRot == "none"
testText(1, 0, "a", 0, 0);
testText(1, 1, "b", 33750, 0);
testText(1, 2, "c", 31500, 0);
testText(1, 3, "d", 29250, 0);
testText(1, 4, "e", 27000, 0);
testText(1, 5, "f", 24750, 0);
testText(1, 6, "g", 22500, 0);
testText(1, 7, "h", 20250, 0);
testText(1, 8, "i", 18000, 0);
testText(1, 9, "j", 15750, 0);
testText(1, 10, "k", 13500, 0);
testText(1, 11, "l", 11250, 0);
testText(1, 12, "m", 9000, 0);
testText(1, 13, "n", 6750, 0);
testText(1, 14, "o", 4500, 0);
testText(1, 15, "p", 2250, 0);
// Slide 3: autoTxRot == "grav"
testText(2, 0, "a", 0, 0);
testText(2, 1, "b", 33750, 0);
testText(2, 2, "c", 31500, 0);
testText(2, 3, "d", 29250, 0);
testText(2, 4, "e", 27000, 0);
testText(2, 5, "f", 24750, 180);
testText(2, 6, "g", 22500, 180);
testText(2, 7, "h", 20250, 180);
testText(2, 8, "i", 18000, 180);
testText(2, 9, "j", 15750, 180);
testText(2, 10, "k", 13500, 180);
testText(2, 11, "l", 11250, 180);
testText(2, 12, "m", 9000, 0);
testText(2, 13, "n", 6750, 0);
testText(2, 14, "o", 4500, 0);
testText(2, 15, "p", 2250, 0);
xDocShRef->DoClose();
}
void SdImportTestSmartArt::testBasicProcess()
{
//FIXME : so far this only introduce the test document, but the actual importer was not fixed yet.
......
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