summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2022-04-18 19:31:26 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-04-20 11:05:16 +0200
commitd5fb8d502e77c1dfc77b2c7bdda4bb1540f3ddaf (patch)
treee6952bccc172b5954d1845dd9199651684d5761f /svx
parent8e9a963d20edcf5751705bb64126f51a2ace6b18 (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>
Diffstat (limited to 'svx')
-rw-r--r--svx/qa/unit/customshapes.cxx41
-rw-r--r--svx/qa/unit/data/tdf148501_OctagonBevel.odpbin0 -> 15018 bytes
-rw-r--r--svx/source/customshapes/EnhancedCustomShape2d.cxx18
3 files changed, 57 insertions, 2 deletions
diff --git a/svx/qa/unit/customshapes.cxx b/svx/qa/unit/customshapes.cxx
index d4ddca038f1f..fc671384e0c8 100644
--- a/svx/qa/unit/customshapes.cxx
+++ b/svx/qa/unit/customshapes.cxx
@@ -1263,6 +1263,47 @@ 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();
+ GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "image/png", aTempFile.GetURL());
+
+ // 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 32c7a73cc4dd..1aa482769711 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: