Skip to content

Commit

Permalink
MCGR: Make MCGR default for oox im/export, cleanup
Browse files Browse the repository at this point in the history
Following an error in CppunitTest_chart2_export3 I updated
the transparency definition at WriteGradientFill and
corrected usages.

Had to correct/adapt some Chart UnitTests. Some of these
changes are temporary since this will/has to change when
ODF MCGR im/export is integrated. I checked that all of
these cases actually work, comparing im LO and MSO.

Adapted some Chart2ImportTest to directly compare/check
now for the fully imported tranparence gradient with
available higher precision.

Adapted OoxDrawingmlTest testGradientMultiStepTransparency
to use new MCGR capabilities.

Adapted testTextframeGradient and tested the turn-around
with rtf gradients. These are a little bit limited and
needed some extra care.

Adapted testTextframeGradient.
Adapted SdOOXMLExportTest1, testTdf94238
Adapted SdOOXMLExportTest1, testTdf128345GradientAxial
Adapted SdOOXMLExportTest2, testTdf105739
Adapted SdOOXMLExportTest3, testTdf127372
Adapted SdOOXMLExportTest3, testTdf127379
Adapted SdMiscTest, testFillGradient
Adapted testTextframeGradient
Adapted ScFiltersTest3, testTdf129789
Adapted SdUiImpressTest, testPageFillGradient

Adapted SdOOXMLExportTest1, testTdf128345GradientLinear by
using better double-to-integer rounding (basegfx::fround) in
DrawingML::WriteGradientStop. After double calculations
this makes the tansition to integer correct and stable. Also
took back change at testTdf128345ChartArea_CG_TS_export
which showed the same flaw before.

2nd look @testTdf128345Legend_CS_TG_axial_export made me
add that stuff again and adapt the axial ColorStop adding
in the export to not export the middle enty twice. Extended
test a little bit, too.
Only do not add value if it starts at 0.0 aka StartColor,
else adding it is corect.

Adapted some tests CPPUNIT_ASSERT to CPPUNIT_ASSERT_EQUAL
after being pointed to it from gerrit_linux_clang_dbgutil
build.

Change-Id: I4a993053da8960035671b655e67908f36e59b5fe
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150763
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <[email protected]>
  • Loading branch information
Armin Le Grand (allotropia) authored and alalg committed May 3, 2023
1 parent f1fd3e3 commit bb19817
Show file tree
Hide file tree
Showing 26 changed files with 526 additions and 723 deletions.
33 changes: 27 additions & 6 deletions chart2/qa/extras/chart2geometry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ void Chart2GeometryTest::testTdf128345ChartArea_CG_TS_export()
// Without the patch the transparency was lost in saved pptx file.
loadFromURL(u"odp/tdf128345_ChartArea_CG_TS.odp");

// MCGR: Similar to testTdf128345Legend_CS_TG_axial_export:
// Checked that it works with the existing import file,
// but will change with ODF MCGR im/export again.
// Adapting for now, but need to re-check values after
// ODF im/export for MCGR is integrated

// Make sure the chart area has a transparency in gradient stops in saved pptx file.
save("Impress MS PowerPoint 2007 XML");
xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
Expand All @@ -188,6 +194,12 @@ void Chart2GeometryTest::testTdf128345ChartArea_CG_TS_import()
// Make sure chart area has transparency when pptx document is opened and resaved as odp.
// As of Aug 2020, the import generates a transparency gradient. When import is changed to
// generate solid transparency, the test needs to be adapted.

// MCGR: Similar to testTdf128345Legend_CS_TG_axial_export:
// Checked that it works with the existing import file,
// but will change with ODF MCGR im/export again. We will need to
// update the *.odp input file. Disable unclear values for now and
// adapt when ODF im/export for MCGR is integrated
loadFromURL(u"pptx/tdf128345_ChartArea_CG_TS.pptx");

// Find transparency gradient name
Expand Down Expand Up @@ -216,7 +228,7 @@ void Chart2GeometryTest::testTdf128345ChartArea_CG_TS_import()
assertXPath(pXmlDoc2, sStart + " and @draw:start='30%']");
assertXPath(pXmlDoc2, sStart + " and @draw:end='30%']");
assertXPath(pXmlDoc2, sStart + " and @draw:angle='30deg']");
assertXPath(pXmlDoc2, sStart + " and @draw:border='20%']");
assertXPath(pXmlDoc2, sStart + " and @draw:border='0%']"); // MCGR: no border anymore 20% -> 0%
}

void Chart2GeometryTest::testTdf128345ChartWall_CS_TG_export()
Expand Down Expand Up @@ -283,13 +295,21 @@ void Chart2GeometryTest::testTdf128345Legend_CS_TG_axial_export()
CPPUNIT_ASSERT(pXmlDoc);

OString sPathStart("//c:chartSpace/c:chart/c:legend/c:spPr/a:gradFill");
assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs", 3); // axial
// no element for 0% transparent

// MCGR: three entries due to axial being mirrored+expanded to linear
assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs", 3);

// MCGR: start entry, no transparence, pos zero
assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[1]/a:srgbClr/a:alpha", 0);
// 100% transparent = opacity 0. It comes from "axial", therefore it is in the middle.
assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[1]", "pos", "0");

// MCGR: middle entry, 100% transparence, pos 0.5
assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[2]/a:srgbClr/a:alpha", "val", "0");
assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[2]", "pos", "50000");

// MCGR: end entry, no transparence, pos 1.0
assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[3]/a:srgbClr/a:alpha", 0);
assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[3]", "pos", "100000");
}

void Chart2GeometryTest::testTdf128345Legend_CS_TG_axial_import()
Expand Down Expand Up @@ -320,8 +340,9 @@ void Chart2GeometryTest::testTdf128345Legend_CS_TG_axial_import()
const OString sAttribute("@draw:name='" + OU2O(sOUOpacityName) + "'");
const OString sStart("//office:document-styles/office:styles/draw:opacity[" + sAttribute);
assertXPath(pXmlDoc2, sStart + "]", 1);
assertXPath(pXmlDoc2, sStart + " and @draw:style='axial']");
assertXPath(pXmlDoc2, sStart + " and @draw:start='0%']");
// MCGR: Needs odf im/export for MCGR, then adapt.
assertXPath(pXmlDoc2, sStart + " and @draw:style='linear']"); // MCGR: axial -> linear
assertXPath(pXmlDoc2, sStart + " and @draw:start='100%']"); // MCGR: 0% -> 100%
assertXPath(pXmlDoc2, sStart + " and @draw:end='100%']");
}

Expand Down
34 changes: 27 additions & 7 deletions chart2/qa/extras/chart2import.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
#include <iterator>

#include <com/sun/star/util/Color.hpp>
#include <com/sun/star/awt/Gradient.hpp>
#include <com/sun/star/awt/Gradient2.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <basegfx/utils/gradienttools.hxx>

class Chart2ImportTest : public ChartTest
{
Expand Down Expand Up @@ -618,12 +619,23 @@ CPPUNIT_TEST_FIXTURE(Chart2ImportTest, testBnc889755)
//tdf#139940 - the title's gradient was lost and was filled with solid blue, instead of a "blue underline".
uno::Reference<drawing::XDrawPagesSupplier> xDoc(mxComponent, uno::UNO_QUERY_THROW);
uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW);

// Shape "Title 3"
// MCGR: Use the whole completely imported transparency gradient to check for correctness
uno::Reference<beans::XPropertySet> xShapeProps(xPage->getByIndex(4), uno::UNO_QUERY_THROW);
awt::Gradient aTransparence;
awt::Gradient2 aTransparence;
xShapeProps->getPropertyValue("FillTransparenceGradient") >>= aTransparence;
CPPUNIT_ASSERT(aTransparence.StartColor != aTransparence.EndColor);
CPPUNIT_ASSERT_EQUAL(COL_WHITE, Color(ColorTransparency, aTransparence.StartColor));

basegfx::ColorStops aColorStops;
basegfx::utils::fillColorStopsFromGradient2(aColorStops, aTransparence);

CPPUNIT_ASSERT_EQUAL(size_t(3), aColorStops.size());
CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[0].getStopOffset(), 0.0));
CPPUNIT_ASSERT_EQUAL(aColorStops[0].getStopColor(), basegfx::BColor(0.25, 0.25, 0.25));
CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[1].getStopOffset(), 0.070000000000000007));
CPPUNIT_ASSERT_EQUAL(aColorStops[1].getStopColor(), basegfx::BColor(0.25, 0.25, 0.25));
CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[2].getStopOffset(), 0.080000000000000002));
CPPUNIT_ASSERT_EQUAL(aColorStops[2].getStopColor(), basegfx::BColor(1.0, 1.0, 1.0));
}

CPPUNIT_TEST_FIXTURE(Chart2ImportTest, testBnc882383)
Expand Down Expand Up @@ -652,14 +664,22 @@ CPPUNIT_TEST_FIXTURE(Chart2ImportTest, testTransparencyGradientValue)
xPropertySet->getPropertyValue("FillTransparenceGradientName") >>= sTranspGradientName;
CPPUNIT_ASSERT(!sTranspGradientName.isEmpty());

awt::Gradient aTransparenceGradient;
awt::Gradient2 aTransparenceGradient;
uno::Reference< lang::XMultiServiceFactory > xFact(xChartDoc, uno::UNO_QUERY);
CPPUNIT_ASSERT(xFact.is());
uno::Reference< container::XNameAccess > xTransparenceGradient(xFact->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY);
uno::Any rTransparenceValue = xTransparenceGradient->getByName(sTranspGradientName);
CPPUNIT_ASSERT(rTransparenceValue >>= aTransparenceGradient);
CPPUNIT_ASSERT_EQUAL(sal_Int32(3355443), aTransparenceGradient.EndColor);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5000268), aTransparenceGradient.StartColor);

basegfx::ColorStops aColorStops;
basegfx::utils::fillColorStopsFromGradient2(aColorStops, aTransparenceGradient);

// MCGR: Use the whole completely imported transparency gradient to check for correctness
CPPUNIT_ASSERT_EQUAL(size_t(2), aColorStops.size());
CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[0].getStopOffset(), 0.0));
CPPUNIT_ASSERT_EQUAL(aColorStops[0].getStopColor(), basegfx::BColor(0.3, 0.3, 0.3));
CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[1].getStopOffset(), 1.0));
CPPUNIT_ASSERT_EQUAL(aColorStops[1].getStopColor(), basegfx::BColor(0.2, 0.2, 0.2));
}

CPPUNIT_TEST_FIXTURE(Chart2ImportTest, testSimpleStrictXLSX)
Expand Down
8 changes: 2 additions & 6 deletions include/oox/export/drawingml.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ public:
void WriteColor( const OUString& sColorSchemeName, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
void WriteColor( const ::Color nColor, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
void WriteColorTransformations( const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
void WriteGradientStop(sal_uInt16 nStop, ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT);
void WriteGradientStop2(double fOffset, const basegfx::BColor& rColor, const basegfx::BColor& rAlpha);
void WriteGradientStop(double fOffset, const basegfx::BColor& rColor, const basegfx::BColor& rAlpha);
void WriteLineArrow( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, bool bLineStart );
void WriteConnectorConnections( sal_Int32 nStartGlueId, sal_Int32 nEndGlueId, sal_Int32 nStartID, sal_Int32 nEndID );

Expand All @@ -377,10 +376,7 @@ public:
*/
void WriteGradientFill(
const css::awt::Gradient2* pColorGradient, sal_Int32 nFixColor,
const css::awt::Gradient2* pTransparenceGradient, sal_Int32 nFixTransparence);
void WriteGradientFill2(
const css::awt::Gradient2* pColorGradient, sal_Int32 nFixColor,
const css::awt::Gradient2* pTransparenceGradient, sal_Int32 nFixTransparence);
const css::awt::Gradient2* pTransparenceGradient, double fFixTransparence = 0.0);

void WriteGrabBagGradientFill( const css::uno::Sequence< css::beans::PropertyValue >& aGradientStops, const css::awt::Gradient2& rGradient);

Expand Down
1 change: 1 addition & 0 deletions oox/CppunitTest_oox_drawingml.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ $(eval $(call gb_CppunitTest_use_libraries,oox_drawingml, \
tl \
unotest \
utl \
basegfx \
))

$(eval $(call gb_CppunitTest_use_sdk_api,oox_drawingml))
Expand Down
1 change: 1 addition & 0 deletions oox/CppunitTest_oox_shape.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $(eval $(call gb_CppunitTest_use_libraries,oox_shape, \
test \
unotest \
utl \
basegfx \
))

$(eval $(call gb_CppunitTest_use_sdk_api,oox_shape))
Expand Down
13 changes: 10 additions & 3 deletions oox/qa/unit/drawingml.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <test/unoapi_test.hxx>

#include <com/sun/star/awt/Gradient.hpp>
#include <com/sun/star/awt/Gradient2.hpp>
#include <com/sun/star/awt/Rectangle.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XNamed.hpp>
Expand All @@ -35,6 +35,7 @@
#include <docmodel/theme/Theme.hxx>

#include <comphelper/sequenceashashmap.hxx>
#include <basegfx/utils/gradienttools.hxx>

using namespace ::com::sun::star;

Expand Down Expand Up @@ -181,15 +182,21 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testGradientMultiStepTransparency)
uno::Reference<container::XNamed> xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("Rectangle 4"), xShape->getName());
uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
awt::Gradient aTransparence;
awt::Gradient2 aTransparence;
xShapeProps->getPropertyValue("FillTransparenceGradient") >>= aTransparence;

// Without the accompanying fix in place, this test would have failed with:
// - Expected: 16777215 (COL_WHITE)
// - Actual : 3487029 (0x353535)
// i.e. the end transparency was not 100%, but was 21%, leading to an unexpected visible line on
// the right of this shape.
CPPUNIT_ASSERT_EQUAL(COL_WHITE, Color(ColorTransparency, aTransparence.EndColor));
// MCGR: Use the completely imported transparency gradient to check for correctness
basegfx::ColorStops aColorStops;
basegfx::utils::fillColorStopsFromGradient2(aColorStops, aTransparence);

CPPUNIT_ASSERT_EQUAL(size_t(5), aColorStops.size());
CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[4].getStopOffset(), 1.0));
CPPUNIT_ASSERT_EQUAL(aColorStops[4].getStopColor(), basegfx::BColor(0.0, 0.0, 0.0));
}

CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testShapeTextAlignment)
Expand Down
Loading

0 comments on commit bb19817

Please sign in to comment.