filter/qa/unit/data/semi-transparent-fill.odg |binary filter/qa/unit/svg.cxx | 32 ++++++++++++++++++++++++++ filter/source/svg/svgwriter.cxx | 6 ++++ 3 files changed, 37 insertions(+), 1 deletion(-)
New commits: commit 5f1c6c71df2e463f4bc9444ce44e941c942610e8 Author: László Németh <nem...@numbertext.org> AuthorDate: Sun Nov 20 16:18:45 2022 +0100 Commit: László Németh <nem...@numbertext.org> CommitDate: Wed Nov 23 09:53:25 2022 +0100 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 <nem...@numbertext.org> (cherry picked from commit 07711c8482714f970c57688629c591f8f3aa135f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142925 Tested-by: László Németh <nem...@numbertext.org> diff --git a/filter/qa/unit/data/semi-transparent-fill.odg b/filter/qa/unit/data/semi-transparent-fill.odg new file mode 100644 index 000000000000..713f48991bcb Binary files /dev/null and b/filter/qa/unit/data/semi-transparent-fill.odg differ diff --git a/filter/qa/unit/svg.cxx b/filter/qa/unit/svg.cxx index 5506d1601cda..0fc29ecae165 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 fb0193e15418..88c240702f9b 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -3286,7 +3286,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 );