summaryrefslogtreecommitdiff
path: root/svgio/source
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-06-28 23:46:37 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-06-29 10:40:06 +0200
commit14c40c460526f2e4ed2c24a3f50baae25a43a8f2 (patch)
treeabe0964a546eddf5ade34bb71a6faa8fc6913f17 /svgio/source
parentdb591df99424dd7e1837946b36ca0658a02d520c (diff)
tdf#156066: Add support for feDropShadow filter
Change-Id: I0b2772a7211efb91821853e3369cfc3a5ef6a932 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153727 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio/source')
-rw-r--r--svgio/source/svgreader/svgdocumenthandler.cxx9
-rw-r--r--svgio/source/svgreader/svgfedropshadownode.cxx147
-rw-r--r--svgio/source/svgreader/svgfilternode.cxx7
-rw-r--r--svgio/source/svgreader/svgtoken.cxx3
4 files changed, 165 insertions, 1 deletions
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx
index 7883383c5287..a070540e68eb 100644
--- a/svgio/source/svgreader/svgdocumenthandler.cxx
+++ b/svgio/source/svgreader/svgdocumenthandler.cxx
@@ -42,6 +42,7 @@
#include <svgimagenode.hxx>
#include <svgclippathnode.hxx>
#include <svgfecolormatrixnode.hxx>
+#include <svgfedropshadownode.hxx>
#include <svgfefloodnode.hxx>
#include <svgfegaussianblurnode.hxx>
#include <svgfeoffsetnode.hxx>
@@ -341,6 +342,13 @@ namespace
mpTarget->parseAttributes(xAttribs);
break;
}
+ case SVGToken::FeDropShadow:
+ {
+ /// new node for feDropShadow
+ mpTarget = new SvgFeDropShadowNode(maDocument, mpTarget);
+ mpTarget->parseAttributes(xAttribs);
+ break;
+ }
case SVGToken::FeFlood:
{
/// new node for feFlood
@@ -469,6 +477,7 @@ namespace
/// structural elements for filters
case SVGToken::FeColorMatrix:
+ case SVGToken::FeDropShadow:
case SVGToken::FeFlood:
case SVGToken::FeGaussianBlur:
case SVGToken::FeOffset:
diff --git a/svgio/source/svgreader/svgfedropshadownode.cxx b/svgio/source/svgreader/svgfedropshadownode.cxx
new file mode 100644
index 000000000000..56dd5dcf9587
--- /dev/null
+++ b/svgio/source/svgreader/svgfedropshadownode.cxx
@@ -0,0 +1,147 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
+#include <drawinglayer/primitive2d/shadowprimitive2d.hxx>
+#include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+#include <svgfedropshadownode.hxx>
+#include <o3tl/string_view.hxx>
+
+namespace svgio::svgreader
+{
+SvgFeDropShadowNode::SvgFeDropShadowNode(SvgDocument& rDocument, SvgNode* pParent)
+ : SvgNode(SVGToken::FeDropShadow, rDocument, pParent)
+ , maDx(0.0)
+ , maDy(0.0)
+ , maStdDeviation(0.0)
+ , maFloodColor(SvgPaint())
+ , maFloodOpacity(1.0)
+{
+}
+
+SvgFeDropShadowNode::~SvgFeDropShadowNode() {}
+
+void SvgFeDropShadowNode::parseAttribute(const OUString& /*rTokenName*/, SVGToken aSVGToken,
+ const OUString& aContent)
+{
+ // parse own
+ switch (aSVGToken)
+ {
+ case SVGToken::Style:
+ {
+ readLocalCssStyle(aContent);
+ break;
+ }
+ case SVGToken::Dx:
+ {
+ SvgNumber aNum;
+
+ if (readSingleNumber(aContent, aNum))
+ {
+ maDx = aNum;
+ }
+ break;
+ }
+ case SVGToken::Dy:
+ {
+ SvgNumber aNum;
+
+ if (readSingleNumber(aContent, aNum))
+ {
+ maDy = aNum;
+ }
+ break;
+ }
+ case SVGToken::StdDeviation:
+ {
+ SvgNumber aNum;
+
+ if (readSingleNumber(aContent, aNum))
+ {
+ maStdDeviation = aNum;
+ }
+ break;
+ }
+ case SVGToken::FloodColor:
+ {
+ SvgPaint aSvgPaint;
+ OUString aURL;
+ SvgNumber aOpacity;
+
+ if (readSvgPaint(aContent, aSvgPaint, aURL, aOpacity))
+ {
+ maFloodColor = aSvgPaint;
+ }
+ break;
+ }
+ case SVGToken::FloodOpacity:
+ {
+ SvgNumber aNum;
+
+ if (readSingleNumber(aContent, aNum))
+ {
+ maFloodOpacity = SvgNumber(std::clamp(aNum.getNumber(), 0.0, 1.0), aNum.getUnit(),
+ aNum.isSet());
+ }
+ break;
+ }
+
+ default:
+ {
+ break;
+ }
+ }
+}
+
+void SvgFeDropShadowNode::apply(drawinglayer::primitive2d::Primitive2DContainer& rTarget) const
+{
+ basegfx::B2DHomMatrix aTransform;
+ if (maDx.isSet() || maDy.isSet())
+ {
+ aTransform.translate(maDx.solve(*this, NumberType::xcoordinate),
+ maDy.solve(*this, NumberType::ycoordinate));
+ }
+
+ drawinglayer::primitive2d::Primitive2DContainer aTempTarget;
+
+ // Create the shadow
+ aTempTarget.append(drawinglayer::primitive2d::Primitive2DReference(
+ new drawinglayer::primitive2d::ShadowPrimitive2D(
+ aTransform, maFloodColor.getBColor(), maStdDeviation.getNumber(),
+ drawinglayer::primitive2d::Primitive2DContainer(rTarget))));
+
+ const double fOpacity(maFloodOpacity.solve(*this));
+ if (basegfx::fTools::less(fOpacity, 1.0))
+ {
+ // Apply transparence to the shadow
+ aTempTarget.append(drawinglayer::primitive2d::Primitive2DReference(
+ new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(std::move(aTempTarget),
+ 1.0 - fOpacity)));
+ }
+
+ // Append the original target
+ aTempTarget.append(rTarget);
+
+ rTarget = aTempTarget;
+}
+
+} // end of namespace svgio::svgreader
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svgio/source/svgreader/svgfilternode.cxx b/svgio/source/svgreader/svgfilternode.cxx
index 6ff71f002e73..3afdc6b0b524 100644
--- a/svgio/source/svgreader/svgfilternode.cxx
+++ b/svgio/source/svgreader/svgfilternode.cxx
@@ -19,6 +19,7 @@
#include <svgfilternode.hxx>
#include <svgfecolormatrixnode.hxx>
+#include <svgfedropshadownode.hxx>
#include <svgfefloodnode.hxx>
#include <svgfegaussianblurnode.hxx>
#include <svgfeoffsetnode.hxx>
@@ -67,6 +68,12 @@ void SvgFilterNode::apply(drawinglayer::primitive2d::Primitive2DContainer& rTarg
const SvgFeFloodNode& rFeFloodNode = dynamic_cast<const SvgFeFloodNode&>(*pCandidate);
rFeFloodNode.apply(rTarget);
}
+ else if (pCandidate->getType() == SVGToken::FeDropShadow)
+ {
+ const SvgFeDropShadowNode& rFeDropShadowNode
+ = dynamic_cast<const SvgFeDropShadowNode&>(*pCandidate);
+ rFeDropShadowNode.apply(rTarget);
+ }
}
}
diff --git a/svgio/source/svgreader/svgtoken.cxx b/svgio/source/svgreader/svgtoken.cxx
index 7a49896b0ed1..2383a6d79abd 100644
--- a/svgio/source/svgreader/svgtoken.cxx
+++ b/svgio/source/svgreader/svgtoken.cxx
@@ -28,7 +28,7 @@ namespace svgio::svgreader
constexpr const std::u16string_view constToken_Title = u"title";
constexpr const std::u16string_view constToken_Desc = u"desc";
-constexpr frozen::unordered_map<std::u16string_view, SVGToken, 143> aSVGTokenMapperList
+constexpr frozen::unordered_map<std::u16string_view, SVGToken, 144> aSVGTokenMapperList
{
{ u"width", SVGToken::Width },
{ u"height", SVGToken::Height },
@@ -81,6 +81,7 @@ constexpr frozen::unordered_map<std::u16string_view, SVGToken, 143> aSVGTokenMap
{ u"clipPath", SVGToken::ClipPathNode },
{ u"clip-path", SVGToken::ClipPathProperty },
{ u"feColorMatrix", SVGToken::FeColorMatrix },
+ { u"feDropShadow", SVGToken::FeDropShadow },
{ u"feFlood", SVGToken::FeFlood },
{ u"feGaussianBlur", SVGToken::FeGaussianBlur },
{ u"feOffset", SVGToken::FeOffset },