summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2018-11-13 18:00:50 +0100
committerMiklos Vajna <vmiklos@collabora.com>2018-11-13 19:23:32 +0100
commitb389aafee9cfba9dc4dfa552347be39ff9fe41b2 (patch)
tree402ed40b923405e35e296c6d4fed77f8ff18775e
parent1b50fa88b148739a7b192ba70f08af2c6e326fd2 (diff)
oox smartart, accent process: add support for reading values from constraints
And also add support for merging parent and own constraints in the layout. This fixes the lack of vertical position difference between the two pairs of shapes in the bugdoc. Change-Id: I3a91c9b0da5eed78a87116ebe0e2751a73e1508f Reviewed-on: https://gerrit.libreoffice.org/63340 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.cxx38
-rw-r--r--sd/qa/unit/data/pptx/smartart-accent-process.pptxbin0 -> 46472 bytes
-rw-r--r--sd/qa/unit/import-tests-smartart.cxx40
3 files changed, 70 insertions, 8 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 763eca855d91..162cc32d12b1 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -55,6 +55,15 @@ oox::OptValue<sal_Int32> findProperty(const oox::drawingml::LayoutPropertyMap& r
return oRet;
}
+
+/**
+ * Determines if nUnit is a font unit (measured in points) or not (measured in
+ * millimeters).
+ */
+bool isFontUnit(sal_Int32 nUnit)
+{
+ return nUnit == oox::XML_primFontSz || nUnit == oox::XML_secFontSz;
+}
}
namespace oox { namespace drawingml {
@@ -273,10 +282,9 @@ void ConstraintAtom::accept( LayoutAtomVisitor& rVisitor )
void ConstraintAtom::parseConstraint(std::vector<Constraint>& rConstraints) const
{
// accepting only basic equality constraints
- if (!maConstraint.msForName.isEmpty() &&
- (maConstraint.mnOperator == XML_none || maConstraint.mnOperator == XML_equ) &&
- maConstraint.mnType != XML_none &&
- maConstraint.mfValue == 0)
+ if (!maConstraint.msForName.isEmpty()
+ && (maConstraint.mnOperator == XML_none || maConstraint.mnOperator == XML_equ)
+ && maConstraint.mnType != XML_none)
{
rConstraints.push_back(maConstraint);
}
@@ -291,7 +299,7 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
const std::vector<Constraint>& rOwnConstraints ) const
{
// Algorithm result may depend on the parent constraints as well.
- std::vector<Constraint> aParentConstraints;
+ std::vector<Constraint> aMergedConstraints;
const LayoutNode* pParent = getLayoutNode().getParentLayoutNode();
if (pParent)
{
@@ -299,10 +307,12 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
{
auto pConstraintAtom = dynamic_cast<ConstraintAtom*>(pChild.get());
if (pConstraintAtom)
- pConstraintAtom->parseConstraint(aParentConstraints);
+ pConstraintAtom->parseConstraint(aMergedConstraints);
}
}
- const std::vector<Constraint>& rConstraints = rOwnConstraints.empty() ? aParentConstraints : rOwnConstraints;
+ aMergedConstraints.insert(aMergedConstraints.end(), rOwnConstraints.begin(),
+ rOwnConstraints.end());
+ const std::vector<Constraint>& rConstraints = aMergedConstraints;
switch(mnType)
{
@@ -328,7 +338,19 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
if (aRefType != aRef->second.end())
aProperties[rConstr.msForName][rConstr.mnType] = aRefType->second * rConstr.mfFactor;
else
- aProperties[rConstr.msForName][rConstr.mnType] = 0; // TODO: val
+ {
+ // Values are never in EMU, while oox::drawingml::Shape
+ // position and size are always in EMU.
+ double fUnitFactor = 0;
+ if (isFontUnit(rConstr.mnRefType))
+ // Points -> EMU.
+ fUnitFactor = EMU_PER_PT;
+ else
+ // Millimeters -> EMU.
+ fUnitFactor = EMU_PER_HMM * 100;
+ aProperties[rConstr.msForName][rConstr.mnType]
+ = rConstr.mfValue * fUnitFactor;
+ }
}
}
diff --git a/sd/qa/unit/data/pptx/smartart-accent-process.pptx b/sd/qa/unit/data/pptx/smartart-accent-process.pptx
new file mode 100644
index 000000000000..de556bdc6066
--- /dev/null
+++ b/sd/qa/unit/data/pptx/smartart-accent-process.pptx
Binary files differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 3e3c6c3691b2..898350abfba5 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -43,6 +43,7 @@ public:
void testVertialBoxList();
void testVertialBracketList();
void testTableList();
+ void testAccentProcess();
CPPUNIT_TEST_SUITE(SdImportTestSmartArt);
@@ -70,6 +71,7 @@ public:
CPPUNIT_TEST(testVertialBoxList);
CPPUNIT_TEST(testVertialBracketList);
CPPUNIT_TEST(testTableList);
+ CPPUNIT_TEST(testAccentProcess);
CPPUNIT_TEST_SUITE_END();
};
@@ -450,6 +452,44 @@ void SdImportTestSmartArt::testTableList()
xDocShRef->DoClose();
}
+void SdImportTestSmartArt::testAccentProcess()
+{
+ sd::DrawDocShellRef xDocShRef = loadURL(
+ m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-accent-process.pptx"), PPTX);
+ uno::Reference<drawing::XShapes> xGroup(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xGroup.is());
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), xGroup->getCount());
+ uno::Reference<drawing::XShape> xGroupShape(xGroup, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xGroupShape.is());
+
+ // The pair if a parent (text + shape) and a child, so 3 shapes in total.
+ uno::Reference<drawing::XShapes> xFirstPair(xGroup->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFirstPair.is());
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), xFirstPair->getCount());
+
+ uno::Reference<text::XText> xFirstParentText(xFirstPair->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFirstParentText.is());
+ CPPUNIT_ASSERT_EQUAL(OUString("a"), xFirstParentText->getString());
+ uno::Reference<drawing::XShape> xFirstParent(xFirstParentText, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFirstParentText.is());
+ int nFirstParentTop = xFirstParent->getPosition().Y;
+
+ uno::Reference<text::XText> xFirstChildText(xFirstPair->getByIndex(2), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFirstChildText.is());
+ CPPUNIT_ASSERT_EQUAL(OUString("b"), xFirstChildText->getString());
+ uno::Reference<drawing::XShape> xFirstChild(xFirstChildText, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFirstChildText.is());
+ int nFirstChildTop = xFirstChild->getPosition().Y;
+
+ // First child is below the first parent.
+ // Without the accompanying fix in place, this test would have failed with
+ // 'Expected less than: 3881, Actual : 3881', i.e. xFirstChild was not
+ // below xFirstParent (a good position is 9081).
+ CPPUNIT_ASSERT_LESS(nFirstChildTop, nFirstParentTop);
+
+ xDocShRef->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt);
CPPUNIT_PLUGIN_IMPLEMENT();