diff options
author | László Németh <nemeth@numbertext.org> | 2022-11-20 16:18:45 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2022-11-23 21:12:01 +0100 |
commit | aa5f995baecd95594e0906fa357cad31d2991797 (patch) | |
tree | cdb6c14f8f9eae6c08e7c90b70aa5038bd341ab8 | |
parent | 8221008b602cadb139bf927d7e5c76777632a7b0 (diff) |
tdf#149800 SVG export: remove extra white line of semi-transparent shape
A shape is exported using two svg:paths, first one is for the
fill, and the second one is for the line. Semi-transparency of
shapes enabled the disabled stroke of the first path, resulting
an ~1 pt width extra white line behind the normal line of the
shape. It was visible only, if the normal shape line was thinner
than 1 pt, or if the normal line was semi-transparent or disabled.
The extra line got the same transparency value, as the fill,
so its visibility depended on that, too.
Change-Id: Idc40971cc73ec9e4f241974ae29c876d06cc0658
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143003
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit 07711c8482714f970c57688629c591f8f3aa135f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142925
Tested-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | filter/qa/unit/data/semi-transparent-fill.odg | bin | 0 -> 10597 bytes | |||
-rw-r--r-- | filter/qa/unit/svg.cxx | 32 | ||||
-rw-r--r-- | filter/source/svg/svgwriter.cxx | 6 |
3 files changed, 37 insertions, 1 deletions
diff --git a/filter/qa/unit/data/semi-transparent-fill.odg b/filter/qa/unit/data/semi-transparent-fill.odg Binary files differnew file mode 100644 index 000000000000..713f48991bcb --- /dev/null +++ b/filter/qa/unit/data/semi-transparent-fill.odg diff --git a/filter/qa/unit/svg.cxx b/filter/qa/unit/svg.cxx index 8bf13756f35c..55d9da1814d2 100644 --- a/filter/qa/unit/svg.cxx +++ b/filter/qa/unit/svg.cxx @@ -129,6 +129,38 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testSemiTransparentLine) CPPUNIT_ASSERT_EQUAL(30, nPercent); } +CPPUNIT_TEST_FIXTURE(SvgFilterTest, testSemiTransparentFillWithTransparentLine) +{ + // Load a document with a shape with semi-transparent fill and line + load(u"semi-transparent-fill.odg"); + + // Export it to SVG. + uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY_THROW); + SvMemoryStream aStream; + uno::Reference<io::XOutputStream> xOut = new utl::OOutputStreamWrapper(aStream); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("draw_svg_Export"); + aMediaDescriptor["OutputStream"] <<= xOut; + xStorable->storeToURL("private:stream", aMediaDescriptor.getAsConstPropertyValueList()); + aStream.Seek(STREAM_SEEK_TO_BEGIN); + + // Get the style of the group around the actual <path> element. + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + OUString aStyle = getXPath( + pXmlDoc, "//svg:g[@class='com.sun.star.drawing.EllipseShape']/svg:g/svg:g", "style"); + CPPUNIT_ASSERT(aStyle.startsWith("opacity: ", &aStyle)); + int nPercent = std::round(aStyle.toDouble() * 100); + // Make sure that the line is still 50% opaque + CPPUNIT_ASSERT_EQUAL(50, nPercent); + + // Get the stroke of the fill of the EllipseShape (it must be "none") + OUString aStroke = getXPath( + pXmlDoc, "//svg:g[@class='com.sun.star.drawing.EllipseShape']/svg:g/svg:path", "stroke"); + // Without the accompanying fix in place, this test would have failed, as the stroke was + // "rgb(255,255,255)", not "none". + CPPUNIT_ASSERT_EQUAL(OUString("none"), aStroke); +} + CPPUNIT_TEST_FIXTURE(SvgFilterTest, testSemiTransparentText) { // Two shapes, one with transparent text and the other one with diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx index f8578e585b43..606e477afddc 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -3316,7 +3316,11 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, { Color aNewLineColor( mpVDev->GetLineColor() ), aNewFillColor( mpVDev->GetFillColor() ); - aNewLineColor.SetAlpha( 255 - sal::static_int_cast<sal_uInt8>( FRound( pA->GetTransparence() * 2.55 ) ) ); + // tdf#149800 do not change transparency of fully transparent + // i.e. invisible line, because it makes it visible, + // resulting an extra line behind the normal shape line + if ( aNewLineColor.GetAlpha() > 0 ) + aNewLineColor.SetAlpha( 255 - sal::static_int_cast<sal_uInt8>( FRound( pA->GetTransparence() * 2.55 ) ) ); aNewFillColor.SetAlpha( 255 - sal::static_int_cast<sal_uInt8>( FRound( pA->GetTransparence() * 2.55 ) ) ); maAttributeWriter.AddPaintAttr( aNewLineColor, aNewFillColor ); |