diff options
author | László Németh <nemeth@numbertext.org> | 2022-11-20 16:18:45 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2022-11-21 08:08:26 +0100 |
commit | 07711c8482714f970c57688629c591f8f3aa135f (patch) | |
tree | 5d0989774949372d75d323261a3bb3beff40acde | |
parent | deb7bc82de19ea8e20c767fdf21f9ba4feb5e9f0 (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>
-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 a650deb1fc72..824b73383af4 100644 --- a/filter/qa/unit/svg.cxx +++ b/filter/qa/unit/svg.cxx @@ -105,6 +105,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 + loadFromURL(u"semi-transparent-fill.odg"); + + // Export it to SVG. + uno::Reference<frame::XStorable> xStorable(mxComponent, 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 ec976ccb6f12..65ccab68bbb0 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -3329,7 +3329,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 ); |