summaryrefslogtreecommitdiff
path: root/svgio/source/svgreader
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-11-29 09:14:08 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-11-29 11:32:14 +0100
commitd34036e60c4e7d13feccd089f7749d35d956b358 (patch)
tree1d58eab69e4cf374d9415996a77d887e2f301717 /svgio/source/svgreader
parent236a96c7cff4cbf8a4ee2499739e7a938b6bae64 (diff)
SVG import: add support for semi-transparent text
<tspan fill-opacity="..."> from SVG was ignored so far, only taking RGB colors from the 'fill' attribute, but ignoring transparency. The problem is that an SVG file is imported by mapping it to drawinglayer primitives, but TextSimplePortionPrimitive2D takes a basegfx::BColor as the font color, which doesn't handle transparency. Fix the problem by rendering SVG similar to how commit 81b0d5393ca4cf2ff0954e53b05928cde047c2e0 (svx: add rendering for semi-transparent shape text, 2019-11-20) did it for shape text: wrap the text primitive in a UnifiedTransparencePrimitive2D when opacity is not 1. Note that the drawinglayer primitive works with transparency and SVG works with opacity, which is the opposite of each other, but both are 0..1 ranges. Change-Id: If5c48613b70eac662b54b8c9da835cd0a966ba89 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143429 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'svgio/source/svgreader')
-rw-r--r--svgio/source/svgreader/svgcharacternode.cxx19
1 files changed, 17 insertions, 2 deletions
diff --git a/svgio/source/svgreader/svgcharacternode.cxx b/svgio/source/svgreader/svgcharacternode.cxx
index d2949d5a0630..4ca8a3468c02 100644
--- a/svgio/source/svgreader/svgcharacternode.cxx
+++ b/svgio/source/svgreader/svgcharacternode.cxx
@@ -24,6 +24,7 @@
#include <drawinglayer/primitive2d/textlayoutdevice.hxx>
#include <drawinglayer/primitive2d/textbreakuphelper.hxx>
#include <drawinglayer/primitive2d/textdecoratedprimitive2d.hxx>
+#include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
#include <utility>
#include <o3tl/string_view.hxx>
#include <osl/diagnose.h>
@@ -208,12 +209,12 @@ namespace svgio::svgreader
}
}
- rtl::Reference<TextSimplePortionPrimitive2D> SvgCharacterNode::createSimpleTextPrimitive(
+ rtl::Reference<BasePrimitive2D> SvgCharacterNode::createSimpleTextPrimitive(
SvgTextPosition& rSvgTextPosition,
const SvgStyleAttributes& rSvgStyleAttributes) const
{
// prepare retval, index and length
- rtl::Reference<TextSimplePortionPrimitive2D> pRetval;
+ rtl::Reference<BasePrimitive2D> pRetval;
sal_uInt32 nLength(getText().getLength());
if(nLength)
@@ -412,6 +413,13 @@ namespace svgio::svgreader
if(rSvgStyleAttributes.getFill())
aFill = *rSvgStyleAttributes.getFill();
+ // get fill opacity
+ double fFillOpacity = 1.0;
+ if (rSvgStyleAttributes.getFillOpacity().isSet())
+ {
+ fFillOpacity = rSvgStyleAttributes.getFillOpacity().getNumber();
+ }
+
// prepare TextTransformation
basegfx::B2DHomMatrix aTextTransform;
@@ -487,6 +495,13 @@ namespace svgio::svgreader
aFill);
}
+ if (fFillOpacity != 1.0)
+ {
+ pRetval = new UnifiedTransparencePrimitive2D(
+ drawinglayer::primitive2d::Primitive2DContainer{ pRetval },
+ 1.0 - fFillOpacity);
+ }
+
// advance current TextPosition
rSvgTextPosition.setPosition(rSvgTextPosition.getPosition() + basegfx::B2DVector(fTextWidth, 0.0));
}