diff options
Diffstat (limited to 'xmloff/qa/unit/style.cxx')
-rw-r--r-- | xmloff/qa/unit/style.cxx | 206 |
1 files changed, 205 insertions, 1 deletions
diff --git a/xmloff/qa/unit/style.cxx b/xmloff/qa/unit/style.cxx index 88e7177f3b91..9f67fb9d20d6 100644 --- a/xmloff/qa/unit/style.cxx +++ b/xmloff/qa/unit/style.cxx @@ -11,8 +11,13 @@ #include <test/unoapixml_test.hxx> -#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/awt/ColorStop.hpp> +#include <com/sun/star/awt/Gradient2.hpp> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/rendering/RGBColor.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <officecfg/Office/Common.hxx> @@ -25,6 +30,7 @@ class XmloffStyleTest : public UnoApiXmlTest { public: XmloffStyleTest(); + uno::Reference<drawing::XShape> getShape(sal_uInt8 nShapeIndex); }; XmloffStyleTest::XmloffStyleTest() @@ -32,6 +38,17 @@ XmloffStyleTest::XmloffStyleTest() { } +uno::Reference<drawing::XShape> XmloffStyleTest::getShape(sal_uInt8 nShapeIndex) +{ + uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, + uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPages> xDrawPages(xDrawPagesSupplier->getDrawPages()); + uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(nShapeIndex), + uno::UNO_QUERY_THROW); + return xShape; +} + CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testFillImageBase64) { // Load a flat ODG that has base64-encoded bitmap as a fill style. @@ -310,6 +327,193 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPosRelTopMargin) } } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testMCGR_OldToNew) +{ + // The file contains a shape with linear gradient fill from red #ff0000 to yellow #ffff00, + // named 'red2yellow' + loadFromURL(u"MCGR_OldToNew.odg"); + + // saveAndReload includes validation and must not fail with the new elements and attributes. + saveAndReload("draw8"); + + // Examine file markup + // For compatibilty the file should still have the old attributes 'start-color' and 'end-color' + xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); + OString sPath = "/office:document-styles/office:styles/draw:gradient[@draw:name='red2yellow']"; + assertXPath(pXmlDoc, sPath, "start-color", "#ff0000"); + assertXPath(pXmlDoc, sPath, "end-color", "#ffff00"); + + // And it must have the new 'gradient-stop' elements. + // The prefix 'loext' needs to be adapted, when the element is available in ODF strict. + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[1]", "offset", "0"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[1]", "color-type", "rgb"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[1]", "color-value", "#ff0000"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[2]", "offset", "1"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[2]", "color-type", "rgb"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[2]", "color-value", "#ffff00"); + + // Examine reloaded file + uno::Reference<drawing::XShape> xShape(getShape(0)); + CPPUNIT_ASSERT(xShape.is()); + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY); + + // The old properties need to be still available, as they might be used in macros. + OUString sGradientName; + xShapeProperties->getPropertyValue("FillGradientName") >>= sGradientName; + CPPUNIT_ASSERT_EQUAL(OUString(u"red2yellow"), sGradientName); + awt::Gradient2 aGradient; + xShapeProperties->getPropertyValue("FillGradient") >>= aGradient; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xFF0000), aGradient.StartColor); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xFFFF00), aGradient.EndColor); + + // Test new properties + auto aColorStopSeq = aGradient.ColorStops; + awt::ColorStop aColorStop = aColorStopSeq[0]; + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopOffset); + CPPUNIT_ASSERT_EQUAL(1.0, aColorStop.StopColor.Red); + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopColor.Green); + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopColor.Blue); + aColorStop = aColorStopSeq[1]; + CPPUNIT_ASSERT_EQUAL(1.0, aColorStop.StopOffset); + CPPUNIT_ASSERT_EQUAL(1.0, aColorStop.StopColor.Red); + CPPUNIT_ASSERT_EQUAL(1.0, aColorStop.StopColor.Green); + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopColor.Blue); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testMCGR_OldToNew_opacity) +{ + // The file contains a shape with solid fill and a radial transparency gradient with start 90%, + // end 0%, border 20% and center at 50%|50%. There is only one draw:opacity element in file. + loadFromURL(u"MCGR_OldToNew_opacity.odg"); + + // saveAndReload includes validation and must not fail with the new elements and attributes. + saveAndReload("draw8"); + + // Examine file markup + // For compatibilty the file should still have the old attributes. + xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); + OString sPath = "/office:document-styles/office:styles/draw:opacity"; + assertXPath(pXmlDoc, sPath, "start", "10%"); // UI 90% transparency + assertXPath(pXmlDoc, sPath, "end", "100%"); // UI 0% transparency + assertXPath(pXmlDoc, sPath, "border", "20%"); + assertXPath(pXmlDoc, sPath, "cx", "50%"); + assertXPath(pXmlDoc, sPath, "cy", "50%"); + assertXPath(pXmlDoc, sPath, "style", "radial"); + + // And it must have the new 'opacity-stop' elements. + // The prefix 'loext' needs to be adapted, when the element is available in ODF strict. + OString sFirstStop = sPath + "/loext:opacity-stop[1]"; + assertXPath(pXmlDoc, sFirstStop, "offset", "0"); + // Because of converting through color, the grade of opacity is not exact "0.1" + double fOpacity = getXPathContent(pXmlDoc, sFirstStop + "/@svg:stop-opacity").toDouble(); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.1, fOpacity, 0.002); + + assertXPath(pXmlDoc, sPath + "/loext:opacity-stop[2]", "offset", "1"); + assertXPath(pXmlDoc, sPath + "/loext:opacity-stop[2]", "stop-opacity", "1"); + + // Examine reloaded file + uno::Reference<drawing::XShape> xShape(getShape(0)); + CPPUNIT_ASSERT(xShape.is()); + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY); + + // The old properties need to be still available, as they might be used in macros. + awt::Gradient2 aGradient; + xShapeProperties->getPropertyValue("FillTransparenceGradient") >>= aGradient; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xE5E5E5), aGradient.StartColor); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aGradient.EndColor); + CPPUNIT_ASSERT_EQUAL(sal_Int16(20), aGradient.Border); + CPPUNIT_ASSERT_EQUAL(sal_Int16(50), aGradient.XOffset); + CPPUNIT_ASSERT_EQUAL(sal_Int16(50), aGradient.YOffset); + CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_RADIAL, aGradient.Style); + + // Test new properties + auto aColorStopSeq = aGradient.ColorStops; + awt::ColorStop aColorStop = aColorStopSeq[0]; + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopOffset); + // Rounding error because of converting through color: 90% => 0.9 * 255 => 229 + // 299.0 / 255.0 = 0.898039215686275 + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.9, aColorStop.StopColor.Red, 0.002); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.9, aColorStop.StopColor.Green, 0.002); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.9, aColorStop.StopColor.Blue, 0.002); + aColorStop = aColorStopSeq[1]; + CPPUNIT_ASSERT_EQUAL(1.0, aColorStop.StopOffset); + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopColor.Red); + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopColor.Green); + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopColor.Blue); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testMCGR_threeStops) +{ + // The file contains a shape with square gradient fill from red #ff0000 over teal #0099bb to + // yellow #ffff00, named 'threeStops'. It has 45deg rotation, center 0%|50%, border 10%. + loadFromURL(u"MCGR_threeStops.fodt"); + + // saveAndReload includes validation and must not fail with the new elements and attributes. + saveAndReload("draw8"); + + // Examine file markup + // For compatibilty the file should still have the old attributes 'start-color' and 'end-color' + xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); + OString sPath = "/office:document-styles/office:styles/draw:gradient[@draw:name='threeStops']"; + assertXPath(pXmlDoc, sPath, "start-color", "#ff0000"); + assertXPath(pXmlDoc, sPath, "end-color", "#ffff00"); + assertXPath(pXmlDoc, sPath, "style", "square"); + assertXPath(pXmlDoc, sPath, "cx", "0%"); + assertXPath(pXmlDoc, sPath, "cy", "50%"); + assertXPath(pXmlDoc, sPath, "angle", "45deg"); + assertXPath(pXmlDoc, sPath, "border", "10%"); + + // And it must have the new 'gradient-stop' elements. + // The prefix 'loext' needs to be adapted, when the element is available in ODF strict. + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[1]", "offset", "0"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[1]", "color-type", "rgb"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[1]", "color-value", "#ff0000"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[2]", "offset", "0.3"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[2]", "color-type", "rgb"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[2]", "color-value", "#0099bb"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[3]", "offset", "1"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[3]", "color-type", "rgb"); + assertXPath(pXmlDoc, sPath + "/loext:gradient-stop[3]", "color-value", "#ffff00"); + + // Examine reloaded file + uno::Reference<drawing::XShape> xShape(getShape(0)); + CPPUNIT_ASSERT(xShape.is()); + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY); + + // The old properties need to be still available, as they might be used in macros. + OUString sGradientName; + xShapeProperties->getPropertyValue("FillGradientName") >>= sGradientName; + CPPUNIT_ASSERT_EQUAL(OUString(u"threeStops"), sGradientName); + awt::Gradient2 aGradient; + xShapeProperties->getPropertyValue("FillGradient") >>= aGradient; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xFF0000), aGradient.StartColor); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xFFFF00), aGradient.EndColor); + CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_SQUARE, aGradient.Style); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aGradient.XOffset); + CPPUNIT_ASSERT_EQUAL(sal_Int16(50), aGradient.YOffset); + CPPUNIT_ASSERT_EQUAL(sal_Int16(450), aGradient.Angle); + CPPUNIT_ASSERT_EQUAL(sal_Int16(10), aGradient.Border); + + // Test new properties + auto aColorStopSeq = aGradient.ColorStops; + awt::ColorStop aColorStop = aColorStopSeq[0]; + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopOffset); + CPPUNIT_ASSERT_EQUAL(1.0, aColorStop.StopColor.Red); + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopColor.Green); + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopColor.Blue); + aColorStop = aColorStopSeq[1]; + CPPUNIT_ASSERT_EQUAL(0.3, aColorStop.StopOffset); + // 0x99 = 153 => 153/255 = 0.6, 0xbb = 187 => 187/255 = 0.733... + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopColor.Red); + CPPUNIT_ASSERT_EQUAL(0.6, aColorStop.StopColor.Green); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.733333333333333, aColorStop.StopColor.Blue, 0.0000001); + aColorStop = aColorStopSeq[2]; + CPPUNIT_ASSERT_EQUAL(1.0, aColorStop.StopOffset); + CPPUNIT_ASSERT_EQUAL(1.0, aColorStop.StopColor.Red); + CPPUNIT_ASSERT_EQUAL(1.0, aColorStop.StopColor.Green); + CPPUNIT_ASSERT_EQUAL(0.0, aColorStop.StopColor.Blue); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |