diff options
-rw-r--r-- | svx/qa/unit/data/theme.pptx | bin | 28788 -> 29572 bytes | |||
-rw-r--r-- | svx/qa/unit/styles.cxx | 19 | ||||
-rw-r--r-- | svx/source/styles/ColorSets.cxx | 48 |
3 files changed, 53 insertions, 14 deletions
diff --git a/svx/qa/unit/data/theme.pptx b/svx/qa/unit/data/theme.pptx Binary files differindex 74397b3ea67a..ebed899cd42c 100644 --- a/svx/qa/unit/data/theme.pptx +++ b/svx/qa/unit/data/theme.pptx diff --git a/svx/qa/unit/styles.cxx b/svx/qa/unit/styles.cxx index 565d981e6e2e..3881fe1d1006 100644 --- a/svx/qa/unit/styles.cxx +++ b/svx/qa/unit/styles.cxx @@ -62,6 +62,14 @@ sal_Int32 GetShapeTextColor(const uno::Reference<text::XTextRange>& xShape) return nColor; } +/// Get the solid fill color of xShape. +sal_Int32 GetShapeFillColor(const uno::Reference<beans::XPropertySet>& xShape) +{ + sal_Int32 nColor{}; + xShape->getPropertyValue("FillColor") >>= nColor; + return nColor; +} + CPPUNIT_TEST_FIXTURE(Test, testThemeChange) { // Given a document, with a first slide and blue shape text from theme: @@ -81,6 +89,12 @@ CPPUNIT_TEST_FIXTURE(Test, testThemeChange) uno::Reference<text::XTextRange> xShape3(xDrawPageShapes->getByIndex(2), uno::UNO_QUERY); // Blue, darker. CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x2f5597), GetShapeTextColor(xShape3)); + // Shape fill: + uno::Reference<beans::XPropertySet> xShape4(xDrawPageShapes->getByIndex(4), uno::UNO_QUERY); + // Blue. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x4472c4), GetShapeFillColor(xShape4)); + // Set theme index to accent 1 till PPTX import is missing. + xShape4->setPropertyValue("FillColorTheme", uno::makeAny(static_cast<sal_Int16>(4))); // When changing the master slide of slide 1 to use the theme of the second master slide: uno::Reference<drawing::XMasterPageTarget> xDrawPage2( @@ -104,6 +118,11 @@ CPPUNIT_TEST_FIXTURE(Test, testThemeChange) CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0xd5eda2), GetShapeTextColor(xShape2)); // Green, darker. CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x6c911d), GetShapeTextColor(xShape3)); + // Shape fill: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 9486886 (#90c226, green) + // - Actual : 4485828 (#4472c4, blue) + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x90c226), GetShapeFillColor(xShape4)); } } diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx index 97c79b58bcc6..5dcd089fd4ba 100644 --- a/svx/source/styles/ColorSets.cxx +++ b/svx/source/styles/ColorSets.cxx @@ -65,33 +65,53 @@ void UpdateTextPortionColorSet(const uno::Reference<beans::XPropertySet>& xPorti uno::makeAny(static_cast<sal_Int32>(aColor))); } -void UpdateSdrObject(svx::Theme* pTheme, SdrObject* pObject) +void UpdateFillColorSet(const uno::Reference<beans::XPropertySet>& xShape, svx::ColorSet& rColorSet) { - svx::ColorSet* pColorSet = pTheme->GetColorSet(); - if (!pColorSet) + if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILLCOLOR_THEME)) { return; } - uno::Reference<text::XTextRange> xShape(pObject->getUnoShape(), uno::UNO_QUERY); - if (!xShape.is()) + sal_Int16 nFillColorTheme = -1; + xShape->getPropertyValue(UNO_NAME_FILLCOLOR_THEME) >>= nFillColorTheme; + if (nFillColorTheme < 0 || nFillColorTheme > 11) + { + return; + } + + Color aColor = rColorSet.getColor(nFillColorTheme); + xShape->setPropertyValue(UNO_NAME_FILLCOLOR, uno::makeAny(static_cast<sal_Int32>(aColor))); +} + +void UpdateSdrObject(svx::Theme* pTheme, SdrObject* pObject) +{ + svx::ColorSet* pColorSet = pTheme->GetColorSet(); + if (!pColorSet) { - // E.g. group shapes have no text. return; } - uno::Reference<container::XEnumerationAccess> xText(xShape->getText(), uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); - while (xParagraphs->hasMoreElements()) + uno::Reference<drawing::XShape> xShape = pObject->getUnoShape(); + uno::Reference<text::XTextRange> xShapeText(xShape, uno::UNO_QUERY); + if (xShapeText.is()) { - uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); - while (xPortions->hasMoreElements()) + // E.g. group shapes have no text. + uno::Reference<container::XEnumerationAccess> xText(xShapeText->getText(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); + while (xParagraphs->hasMoreElements()) { - uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), uno::UNO_QUERY); - UpdateTextPortionColorSet(xPortion, *pColorSet); + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + while (xPortions->hasMoreElements()) + { + uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), uno::UNO_QUERY); + UpdateTextPortionColorSet(xPortion, *pColorSet); + } } } + + uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); + UpdateFillColorSet(xShapeProps, *pColorSet); } } |