LibreOffice Module svgio (master) 1
svgfefloodnode.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
24#include <svgfefloodnode.hxx>
25#include <o3tl/string_view.hxx>
26
27namespace svgio::svgreader
28{
30 : SvgFilterNode(SVGToken::FeFlood, rDocument, pParent)
31 , maX(0.0)
32 , maY(0.0)
33 , maWidth(0.0)
34 , maHeight(0.0)
35 , maFloodColor(SvgPaint())
36 , maFloodOpacity(1.0)
37{
38}
39
41
42void SvgFeFloodNode::parseAttribute(const OUString& /*rTokenName*/, SVGToken aSVGToken,
43 const OUString& aContent)
44{
45 // parse own
46 switch (aSVGToken)
47 {
48 case SVGToken::Style:
49 {
50 readLocalCssStyle(aContent);
51 break;
52 }
53 case SVGToken::X:
54 {
55 SvgNumber aNum;
56
57 if (readSingleNumber(aContent, aNum))
58 {
59 maX = aNum;
60 }
61 break;
62 }
63 case SVGToken::Y:
64 {
65 SvgNumber aNum;
66
67 if (readSingleNumber(aContent, aNum))
68 {
69 maY = aNum;
70 }
71 break;
72 }
73 case SVGToken::Width:
74 {
75 SvgNumber aNum;
76
77 if (readSingleNumber(aContent, aNum))
78 {
79 if (aNum.isPositive())
80 {
81 maWidth = aNum;
82 }
83 }
84 break;
85 }
87 {
88 SvgNumber aNum;
89
90 if (readSingleNumber(aContent, aNum))
91 {
92 if (aNum.isPositive())
93 {
94 maHeight = aNum;
95 }
96 }
97 break;
98 }
100 {
101 SvgPaint aSvgPaint;
102 OUString aURL;
103 SvgNumber aOpacity;
104
105 if (readSvgPaint(aContent, aSvgPaint, aURL, aOpacity))
106 {
107 maFloodColor = aSvgPaint;
108 }
109 break;
110 }
112 {
113 SvgNumber aNum;
114
115 if (readSingleNumber(aContent, aNum))
116 {
117 maFloodOpacity = SvgNumber(std::clamp(aNum.getNumber(), 0.0, 1.0), aNum.getUnit(),
118 aNum.isSet());
119 }
120 break;
121 }
122
123 default:
124 {
125 break;
126 }
127 }
128}
129
131{
132 const double fWidth(maWidth.solve(*this, NumberType::xcoordinate));
133 const double fHeight(maHeight.solve(*this, NumberType::ycoordinate));
134
135 if (fWidth <= 0.0 || fHeight <= 0.0)
136 return;
137
138 const double fX(maX.solve(*this, NumberType::xcoordinate));
139 const double fY(maY.solve(*this, NumberType::ycoordinate));
140 const basegfx::B2DRange aRange(fX, fY, fX + fWidth, fY + fHeight);
141
146
148
149 const double fOpacity(maFloodOpacity.solve(*this));
150
151 if (basegfx::fTools::less(fOpacity, 1.0))
152 {
154 1.0 - fOpacity);
155
157 }
158}
159
160} // end of namespace svgio::svgreader
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void apply(drawinglayer::primitive2d::Primitive2DContainer &rTarget) const override
SvgFeFloodNode(SvgDocument &rDocument, SvgNode *pParent)
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent) override
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)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
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