summaryrefslogtreecommitdiff
path: root/svgio/source
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-06-06 19:04:50 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-06-07 14:49:42 +0200
commit77354ba8695f66331bfc6cc3f5e3f2e9d15f1740 (patch)
tree58794916319f20cf045293fc4a8b7b50e56565cc /svgio/source
parent225f79a068a1b5a51b82f9d1a6b1fc756b572873 (diff)
tdf#132246: add basic support for feGaussianBlur
for now only apply it if in="SourceGraphic" is explicitly used Change-Id: I3daea354f61ba5f6b3d13da1e7a71e99d51f6729 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152684 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio/source')
-rw-r--r--svgio/source/svgreader/svgdocumenthandler.cxx11
-rw-r--r--svgio/source/svgreader/svgfegaussianblurnode.cxx86
-rw-r--r--svgio/source/svgreader/svgfilternode.cxx22
-rw-r--r--svgio/source/svgreader/svgstyleattributes.cxx6
-rw-r--r--svgio/source/svgreader/svgtoken.cxx6
5 files changed, 130 insertions, 1 deletions
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx
index ac866b37f0d2..5e61693e64c7 100644
--- a/svgio/source/svgreader/svgdocumenthandler.cxx
+++ b/svgio/source/svgreader/svgdocumenthandler.cxx
@@ -41,6 +41,7 @@
#include <svgstylenode.hxx>
#include <svgimagenode.hxx>
#include <svgclippathnode.hxx>
+#include <svgfegaussianblurnode.hxx>
#include <svgfilternode.hxx>
#include <svgmasknode.hxx>
#include <svgmarkernode.hxx>
@@ -341,6 +342,13 @@ namespace
mpTarget->parseAttributes(xAttribs);
break;
}
+ case SVGToken::FeGaussianBlur:
+ {
+ /// new node for feGaussianBlur
+ mpTarget = new SvgFeGaussianBlurNode(maDocument, mpTarget);
+ mpTarget->parseAttributes(xAttribs);
+ break;
+ }
case SVGToken::Filter:
{
/// new node for Filter
@@ -442,8 +450,9 @@ namespace
/// styles (as stylesheets)
case SVGToken::Style:
- /// structural elements clip-path, filter and mask
+ /// structural elements clip-path, feGaussianBlur, filter and mask
case SVGToken::ClipPathNode:
+ case SVGToken::FeGaussianBlur:
case SVGToken::Filter:
case SVGToken::Mask:
diff --git a/svgio/source/svgreader/svgfegaussianblurnode.cxx b/svgio/source/svgreader/svgfegaussianblurnode.cxx
new file mode 100644
index 000000000000..fff21345c4d8
--- /dev/null
+++ b/svgio/source/svgreader/svgfegaussianblurnode.cxx
@@ -0,0 +1,86 @@
+/* -*- 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 <svgfegaussianblurnode.hxx>
+#include <drawinglayer/primitive2d/softedgeprimitive2d.hxx>
+#include <o3tl/string_view.hxx>
+
+namespace svgio::svgreader
+{
+SvgFeGaussianBlurNode::SvgFeGaussianBlurNode(SvgDocument& rDocument, SvgNode* pParent)
+ : SvgNode(SVGToken::FeGaussianBlur, rDocument, pParent)
+ , maStdDeviation(SvgNumber(0.0))
+ , maIn(In::None)
+{
+}
+
+SvgFeGaussianBlurNode::~SvgFeGaussianBlurNode() {}
+
+void SvgFeGaussianBlurNode::parseAttribute(const OUString& /*rTokenName*/, SVGToken aSVGToken,
+ const OUString& aContent)
+{
+ // parse own
+ switch (aSVGToken)
+ {
+ case SVGToken::StdDeviation:
+ {
+ SvgNumber aNum;
+
+ if (readSingleNumber(aContent, aNum))
+ {
+ if (aNum.isPositive())
+ {
+ maStdDeviation = aNum;
+ }
+ }
+ break;
+ }
+ case SVGToken::In:
+ {
+ if (!aContent.isEmpty())
+ {
+ if (o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"SourceGraphic"))
+ {
+ maIn = In::SourceGraphic;
+ }
+ }
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+}
+
+void SvgFeGaussianBlurNode::apply(drawinglayer::primitive2d::Primitive2DContainer& rTarget) const
+{
+ if (maIn == In::SourceGraphic)
+ {
+ const drawinglayer::primitive2d::Primitive2DReference xRef(
+ new drawinglayer::primitive2d::SoftEdgePrimitive2D(maStdDeviation.getNumber(),
+ std::move(rTarget)));
+
+ rTarget = drawinglayer::primitive2d::Primitive2DContainer{ xRef };
+ }
+}
+
+} // 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 374feb06247b..8eb0beb65e6b 100644
--- a/svgio/source/svgreader/svgfilternode.cxx
+++ b/svgio/source/svgreader/svgfilternode.cxx
@@ -18,6 +18,7 @@
*/
#include <svgfilternode.hxx>
+#include <svgfegaussianblurnode.hxx>
namespace svgio::svgreader
{
@@ -28,6 +29,27 @@ SvgFilterNode::SvgFilterNode(SvgDocument& rDocument, SvgNode* pParent)
SvgFilterNode::~SvgFilterNode() {}
+void SvgFilterNode::apply(drawinglayer::primitive2d::Primitive2DContainer& rTarget) const
+{
+ if (rTarget.empty())
+ return;
+
+ const auto& rChildren = getChildren();
+ const sal_uInt32 nCount(rChildren.size());
+
+ // apply children's filters
+ for (sal_uInt32 a(0); a < nCount; a++)
+ {
+ SvgNode* pCandidate = rChildren[a].get();
+ if (pCandidate->getType() == SVGToken::FeGaussianBlur)
+ {
+ const SvgFeGaussianBlurNode* pFeGaussianBlurNode
+ = dynamic_cast<const SvgFeGaussianBlurNode*>(pCandidate);
+ pFeGaussianBlurNode->apply(rTarget);
+ }
+ }
+}
+
} // end of namespace svgio::svgreader
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index 5a3c9396ae91..eda757af80d3 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -1208,6 +1208,12 @@ namespace svgio::svgreader
if(!aSource.empty()) // test again, applied clipPath may have lead to empty geometry
{
+ const SvgFilterNode* pFilter = accessFilterXLink();
+ if(pFilter)
+ {
+ pFilter->apply(aSource);
+ }
+
const SvgMaskNode* pMask = accessMaskXLink();
if(pMask)
{
diff --git a/svgio/source/svgreader/svgtoken.cxx b/svgio/source/svgreader/svgtoken.cxx
index a472466b3995..48a0c8eb47df 100644
--- a/svgio/source/svgreader/svgtoken.cxx
+++ b/svgio/source/svgreader/svgtoken.cxx
@@ -34,6 +34,7 @@ namespace svgio::svgreader
const char aSVGStrXmlns[] = "xmlns";
const char aSVGStrVersion[] = "version";
const char aSVGStrId[] = "id";
+ const char aSVGStrIn[] = "in";
const char aSVGStrRx[] = "rx";
const char aSVGStrRy[] = "ry";
const char aSVGStrPoints[] = "points";
@@ -61,6 +62,7 @@ namespace svgio::svgreader
const char aSVGStrStartOffset[] = "startOffset";
const char aSVGStrMethod[] = "method";
const char aSVGStrSpacing[] = "spacing";
+ const char aSVGStrStdDeviation[] = "stdDeviation";
const char aSVGStrTextAlign[] = "text-align";
const char aSVGStrPathLength[] = "pathLength";
const char aSVGStrType[] = "type";
@@ -70,6 +72,7 @@ namespace svgio::svgreader
const char aSVGStrColor[] = "color";
const char aSVGStrClipPathNode[] = "clipPath";
const char aSVGStrClipPathProperty[] = "clip-path";
+ const char aSVGStrFeGaussianBlur[] = "feGaussianBlur";
const char aSVGStrFilter[] = "filter";
const char aSVGStrMask[] = "mask";
const char aSVGStrClipPathUnits[] = "clipPathUnits";
@@ -182,6 +185,7 @@ namespace svgio::svgreader
{ aSVGStrXmlns, SVGToken::Xmlns },
{ aSVGStrVersion, SVGToken::Version },
{ aSVGStrId, SVGToken::Id },
+ { aSVGStrIn, SVGToken::In },
{ aSVGStrRx, SVGToken::Rx },
{ aSVGStrRy, SVGToken::Ry },
{ aSVGStrPoints, SVGToken::Points },
@@ -209,6 +213,7 @@ namespace svgio::svgreader
{ aSVGStrStartOffset, SVGToken::StartOffset },
{ aSVGStrMethod, SVGToken::Method },
{ aSVGStrSpacing, SVGToken::Spacing },
+ { aSVGStrStdDeviation, SVGToken::StdDeviation },
{ aSVGStrTextAlign, SVGToken::TextAlign },
{ aSVGStrPathLength, SVGToken::PathLength },
{ aSVGStrType, SVGToken::Type },
@@ -218,6 +223,7 @@ namespace svgio::svgreader
{ aSVGStrColor, SVGToken::Color },
{ aSVGStrClipPathNode, SVGToken::ClipPathNode },
{ aSVGStrClipPathProperty, SVGToken::ClipPathProperty },
+ { aSVGStrFeGaussianBlur, SVGToken::FeGaussianBlur },
{ aSVGStrFilter, SVGToken::Filter },
{ aSVGStrMask, SVGToken::Mask },
{ aSVGStrClipPathUnits, SVGToken::ClipPathUnits },