summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2022-04-18 19:31:26 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2022-04-26 21:13:09 +0200
commita9d8f86488dcd44bef4d6f8cee1d6c803f237f9c (patch)
treeedf50eeeed96fda26d15caee059e5dbe9abc04c4 /svx
parent74a42203fc1f90726cf1219139df5c00e6978914 (diff)
tdf#148501 color shades only for filled PolyPolygons
For shading parts of a shape not of Type 'ooxml-*', ColorData is used, introduced about 2005. For 'mso_spt*' shapes they are set directly, for others they are encoded as 'col-********' into the Type value. During OOo time two changes were made, resulting in the bugs, that colors are assigned to wrong segments and that shadings are too dark. More details are in the bug report. With this patch the colors are assigned to the correct segments again. The too dark colors are visible in our preset shapes 'Octagon Bevel'. The shape 'Diamond Bevel' with corrected color assignment is also affected. Both need new ColorData. Since it is important for Libreoffice to have good compatibility with OOXML, I have decided to use only the four shading values available in OOXML. In the long run, these shapes should be replaced by ones that contain the shading information inside the <enhanced-path> element. Change-Id: I4b8323c45bf702fc371d6e6c82dd9102d0fd9929 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133132 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133153
Diffstat (limited to 'svx')
-rw-r--r--svx/qa/unit/customshapes.cxx58
-rw-r--r--svx/qa/unit/data/tdf148501_OctagonBevel.odpbin0 -> 15018 bytes
-rw-r--r--svx/source/customshapes/EnhancedCustomShape2d.cxx18
3 files changed, 74 insertions, 2 deletions
diff --git a/svx/qa/unit/customshapes.cxx b/svx/qa/unit/customshapes.cxx
index ca6ece320afa..690d6c02aa45 100644
--- a/svx/qa/unit/customshapes.cxx
+++ b/svx/qa/unit/customshapes.cxx
@@ -18,6 +18,7 @@
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/point/b2dpoint.hxx>
+#include <comphelper/propertyvalue.hxx>
#include <sfx2/request.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/viewsh.hxx>
@@ -31,12 +32,15 @@
#include <svx/unoapi.hxx>
#include <unotools/mediadescriptor.hxx>
#include <unotools/tempfile.hxx>
+#include <vcl/filter/PngImageReader.hxx>
+#include <vcl/BitmapReadAccess.hxx>
#include <cppunit/TestAssert.h>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/drawing/XDrawPage.hpp>
+#include <com/sun/star/drawing/GraphicExportFilter.hpp>
#include <com/sun/star/awt/Rectangle.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XStorable.hpp>
@@ -1156,6 +1160,60 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf136176)
}
}
}
+
+CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf148501_OctagonBevel)
+{
+ // The document contains a shape "Octagon Bevel". It should use shadings 40%, 20%, -20%, -40%
+ // from left-top to bottom-right. The test examines actual color, not the geometry.
+ // Load document
+ OUString aURL = m_directories.getURLFromSrc(sDataDirectory) + "tdf148501_OctagonBevel.odp";
+ mxComponent = loadFromDesktop(aURL, "com.sun.star.presentation.PresentationDocument");
+
+ // Generate bitmap from shape
+ uno::Reference<drawing::XShape> xShape = getShape(0);
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+
+ uno::Reference<uno::XComponentContext> xContext = getComponentContext();
+ CPPUNIT_ASSERT(xContext.is());
+ uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
+ = drawing::GraphicExportFilter::create(xContext);
+
+ uno::Sequence<beans::PropertyValue> aDescriptor{
+ comphelper::makePropertyValue("URL", aTempFile.GetURL()),
+ comphelper::makePropertyValue("FilterName", OUString("PNG"))
+ };
+
+ uno::Reference<lang::XComponent> xSourceDocument(xShape, uno::UNO_QUERY_THROW);
+ xGraphicExporter->setSourceDocument(xSourceDocument);
+ xGraphicExporter->filter(aDescriptor);
+
+ // Read bitmap and test color
+ // expected in order top-left, top, top-right, right, bottom-right:
+ // RGB(165|195|266), RGB(139|176|217), RGB(91|127|166), RGB(68|95|124), RGB(68|95|124)
+ // Without applied patch the colors were:
+ // RGB(193|214,236), RGB(193|214,236), RGB(80|111|145), RGB(23|32|41), RGB(193|214|236)
+ // So we test segments top, right and bottom-right.
+ SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ);
+ vcl::PngImageReader aPNGReader(aFileStream);
+ BitmapEx aBMPEx = aPNGReader.read();
+ Bitmap aBMP = aBMPEx.GetBitmap();
+ Bitmap::ScopedReadAccess pRead(aBMP);
+ Size aSize = aBMP.GetSizePixel();
+
+ // GetColor(Y,X). The chosen threshold for the ColorDistance can be adapted if necessary.
+ Color aActualColor = pRead->GetColor(aSize.Height() * 0.17, aSize.Width() * 0.5); // top
+ Color aExpectedColor(139, 176, 217);
+ sal_uInt16 nColorDistance = aExpectedColor.GetColorError(aActualColor);
+ CPPUNIT_ASSERT_LESS(sal_uInt16(6), nColorDistance);
+ aActualColor = pRead->GetColor(aSize.Height() * 0.5, aSize.Width() * 0.83); // right
+ aExpectedColor = Color(68, 95, 124); // same for right and bottom-right
+ nColorDistance = aExpectedColor.GetColorError(aActualColor);
+ CPPUNIT_ASSERT_LESS(sal_uInt16(6), nColorDistance);
+ aActualColor = pRead->GetColor(aSize.Height() * 0.75, aSize.Width() * 0.75); // bottom-right
+ nColorDistance = aExpectedColor.GetColorError(aActualColor);
+ CPPUNIT_ASSERT_LESS(sal_uInt16(6), nColorDistance);
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/qa/unit/data/tdf148501_OctagonBevel.odp b/svx/qa/unit/data/tdf148501_OctagonBevel.odp
new file mode 100644
index 000000000000..9dafaf7c2624
--- /dev/null
+++ b/svx/qa/unit/data/tdf148501_OctagonBevel.odp
Binary files differ
diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx b/svx/source/customshapes/EnhancedCustomShape2d.cxx
index 1f05a3782a7c..14f054ddce73 100644
--- a/svx/source/customshapes/EnhancedCustomShape2d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx
@@ -777,8 +777,19 @@ EnhancedCustomShape2d::EnhancedCustomShape2d(SdrObjCustomShape& rSdrObjCustomSha
case mso_sptSmileyFace : nColorData = 0x20e00000; break;
case mso_sptNil :
{
- if( sShapeType.getLength() > 4 &&
- sShapeType.match( "col-" ))
+ // Because calculation method has changed in #i102797 original color encoding for
+ // Octagon Bevel and Diamond Bevel can no longer be used. We keep the color coding
+ // only for self-created shapes, as authors may have already considered the change.
+ // We use ColorData compatible to OOXML.
+ if (sShapeType == "col-60da8460") // Octagon Bevel
+ {
+ nColorData = 0x60ecc240;
+ }
+ else if (sShapeType == "col-502ad400") // Diamond Bevel
+ {
+ nColorData = 0x502ce400;
+ }
+ else if (sShapeType.getLength() > 4 && sShapeType.match( "col-" ))
{
nColorData = sShapeType.copy( 4 ).toUInt32( 16 );
}
@@ -2755,6 +2766,9 @@ void EnhancedCustomShape2d::AdaptObjColor(
return;
const drawing::FillStyle eFillStyle = rObj.GetMergedItem(XATTR_FILLSTYLE).GetValue();
+ if (eFillStyle == drawing::FillStyle_NONE)
+ return;
+
switch( eFillStyle )
{
default: