LibreOffice Module svgio (master) 1
svgfedropshadownode.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
25#include <o3tl/string_view.hxx>
26
27namespace svgio::svgreader
28{
30 : SvgFilterNode(SVGToken::FeDropShadow, rDocument, pParent)
31 , maDx(0.0)
32 , maDy(0.0)
33 , maStdDeviation(0.0)
34 , maFloodColor(SvgPaint())
35 , maFloodOpacity(1.0)
36{
37}
38
40
41void SvgFeDropShadowNode::parseAttribute(const OUString& /*rTokenName*/, SVGToken aSVGToken,
42 const OUString& aContent)
43{
44 // parse own
45 switch (aSVGToken)
46 {
47 case SVGToken::Style:
48 {
49 readLocalCssStyle(aContent);
50 break;
51 }
52 case SVGToken::Dx:
53 {
54 SvgNumber aNum;
55
56 if (readSingleNumber(aContent, aNum))
57 {
58 maDx = aNum;
59 }
60 break;
61 }
62 case SVGToken::Dy:
63 {
64 SvgNumber aNum;
65
66 if (readSingleNumber(aContent, aNum))
67 {
68 maDy = aNum;
69 }
70 break;
71 }
73 {
74 SvgNumber aNum;
75
76 if (readSingleNumber(aContent, aNum))
77 {
78 maStdDeviation = aNum;
79 }
80 break;
81 }
83 {
84 SvgPaint aSvgPaint;
85 OUString aURL;
86 SvgNumber aOpacity;
87
88 if (readSvgPaint(aContent, aSvgPaint, aURL, aOpacity))
89 {
90 maFloodColor = aSvgPaint;
91 }
92 break;
93 }
95 {
96 SvgNumber aNum;
97
98 if (readSingleNumber(aContent, aNum))
99 {
100 maFloodOpacity = SvgNumber(std::clamp(aNum.getNumber(), 0.0, 1.0), aNum.getUnit(),
101 aNum.isSet());
102 }
103 break;
104 }
105
106 default:
107 {
108 break;
109 }
110 }
111}
112
114{
115 basegfx::B2DHomMatrix aTransform;
116 if (maDx.isSet() || maDy.isSet())
117 {
118 aTransform.translate(maDx.solve(*this, NumberType::xcoordinate),
120 }
121
123
124 // Create the shadow
129
130 const double fOpacity(maFloodOpacity.solve(*this));
131 if (basegfx::fTools::less(fOpacity, 1.0))
132 {
133 // Apply transparence to the shadow
136 1.0 - fOpacity)));
137 }
138
139 // Append the original target
140 aTempTarget.append(rTarget);
141
142 rTarget = aTempTarget;
143}
144
145} // end of namespace svgio::svgreader
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void translate(double fX, double fY)
void append(const Primitive2DReference &)
void apply(drawinglayer::primitive2d::Primitive2DContainer &rTarget) const override
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent) override
SvgFeDropShadowNode(SvgDocument &rDocument, SvgNode *pParent)
void readLocalCssStyle(std::u16string_view aContent)
scan helper to read and interpret a local CssStyle to mpLocalCssStyle
Definition: svgnode.cxx:412
SvgUnit getUnit() const
Definition: SvgNumber.hxx:90
double solve(const InfoProvider &rInfoProvider, NumberType aNumberType=NumberType::length) const
Definition: SvgNumber.cxx:69
double getNumber() const
Definition: SvgNumber.hxx:85
const basegfx::BColor & getBColor() const
Definition: svgpaint.hxx:44
URL aURL
FilterGroup & rTarget
bool less(const T &rfValA, const T &rfValB)
bool readSingleNumber(std::u16string_view rCandidate, SvgNumber &aNum)
Definition: svgtools.cxx:1076
bool readSvgPaint(const OUString &rCandidate, SvgPaint &rSvgPaint, OUString &rURL, SvgNumber &rOpacity)
Definition: svgtools.cxx:1139