/src/libreoffice/svgio/source/svgreader/svgfefloodnode.cxx
Line | Count | Source |
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 | | |
20 | | #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx> |
21 | | #include <drawinglayer/primitive2d/transformprimitive2d.hxx> |
22 | | #include <drawinglayer/primitive2d/PolyPolygonRGBAPrimitive2D.hxx> |
23 | | #include <basegfx/polygon/b2dpolygontools.hxx> |
24 | | #include <svgfefloodnode.hxx> |
25 | | #include <o3tl/string_view.hxx> |
26 | | |
27 | | namespace svgio::svgreader |
28 | | { |
29 | | SvgFeFloodNode::SvgFeFloodNode(SvgDocument& rDocument, SvgNode* pParent) |
30 | 0 | : SvgFilterNode(SVGToken::FeFlood, rDocument, pParent) |
31 | 0 | , maX(0.0) |
32 | 0 | , maY(0.0) |
33 | 0 | , maWidth(0.0) |
34 | 0 | , maHeight(0.0) |
35 | 0 | , maFloodColor(SvgPaint()) |
36 | 0 | , maFloodOpacity(1.0) |
37 | 0 | { |
38 | 0 | } |
39 | | |
40 | 0 | SvgFeFloodNode::~SvgFeFloodNode() {} |
41 | | |
42 | | void SvgFeFloodNode::parseAttribute(SVGToken aSVGToken, const OUString& aContent) |
43 | 0 | { |
44 | | // parse own |
45 | 0 | switch (aSVGToken) |
46 | 0 | { |
47 | 0 | case SVGToken::Style: |
48 | 0 | { |
49 | 0 | readLocalCssStyle(aContent); |
50 | 0 | break; |
51 | 0 | } |
52 | 0 | case SVGToken::Result: |
53 | 0 | { |
54 | 0 | maResult = aContent.trim(); |
55 | 0 | break; |
56 | 0 | } |
57 | 0 | case SVGToken::X: |
58 | 0 | { |
59 | 0 | SvgNumber aNum; |
60 | |
|
61 | 0 | if (readSingleNumber(aContent, aNum)) |
62 | 0 | { |
63 | 0 | maX = aNum; |
64 | 0 | } |
65 | 0 | break; |
66 | 0 | } |
67 | 0 | case SVGToken::Y: |
68 | 0 | { |
69 | 0 | SvgNumber aNum; |
70 | |
|
71 | 0 | if (readSingleNumber(aContent, aNum)) |
72 | 0 | { |
73 | 0 | maY = aNum; |
74 | 0 | } |
75 | 0 | break; |
76 | 0 | } |
77 | 0 | case SVGToken::Width: |
78 | 0 | { |
79 | 0 | SvgNumber aNum; |
80 | |
|
81 | 0 | if (readSingleNumber(aContent, aNum)) |
82 | 0 | { |
83 | 0 | if (aNum.isPositive()) |
84 | 0 | { |
85 | 0 | maWidth = aNum; |
86 | 0 | } |
87 | 0 | } |
88 | 0 | break; |
89 | 0 | } |
90 | 0 | case SVGToken::Height: |
91 | 0 | { |
92 | 0 | SvgNumber aNum; |
93 | |
|
94 | 0 | if (readSingleNumber(aContent, aNum)) |
95 | 0 | { |
96 | 0 | if (aNum.isPositive()) |
97 | 0 | { |
98 | 0 | maHeight = aNum; |
99 | 0 | } |
100 | 0 | } |
101 | 0 | break; |
102 | 0 | } |
103 | 0 | case SVGToken::FloodColor: |
104 | 0 | { |
105 | 0 | SvgPaint aSvgPaint; |
106 | 0 | OUString aURL; |
107 | 0 | SvgNumber aOpacity; |
108 | |
|
109 | 0 | if (readSvgPaint(aContent, aSvgPaint, aURL, aOpacity)) |
110 | 0 | { |
111 | 0 | maFloodColor = aSvgPaint; |
112 | 0 | } |
113 | 0 | break; |
114 | 0 | } |
115 | 0 | case SVGToken::FloodOpacity: |
116 | 0 | { |
117 | 0 | SvgNumber aNum; |
118 | |
|
119 | 0 | if (readSingleNumber(aContent, aNum)) |
120 | 0 | { |
121 | 0 | maFloodOpacity = SvgNumber(std::clamp(aNum.getNumber(), 0.0, 1.0), aNum.getUnit(), |
122 | 0 | aNum.isSet()); |
123 | 0 | } |
124 | 0 | break; |
125 | 0 | } |
126 | | |
127 | 0 | default: |
128 | 0 | { |
129 | 0 | break; |
130 | 0 | } |
131 | 0 | } |
132 | 0 | } |
133 | | |
134 | | void SvgFeFloodNode::apply(drawinglayer::primitive2d::Primitive2DContainer& rTarget, |
135 | | const SvgFilterNode* pParent) const |
136 | 0 | { |
137 | 0 | const double fWidth(maWidth.solve(*this, NumberType::xcoordinate)); |
138 | 0 | const double fHeight(maHeight.solve(*this, NumberType::ycoordinate)); |
139 | |
|
140 | 0 | if (fWidth <= 0.0 || fHeight <= 0.0) |
141 | 0 | return; |
142 | | |
143 | 0 | const double fX(maX.solve(*this, NumberType::xcoordinate)); |
144 | 0 | const double fY(maY.solve(*this, NumberType::ycoordinate)); |
145 | 0 | const basegfx::B2DRange aRange(fX, fY, fX + fWidth, fY + fHeight); |
146 | 0 | const double fOpacity(maFloodOpacity.solve(*this)); |
147 | |
|
148 | 0 | if (basegfx::fTools::moreOrEqual(fOpacity, 1.0)) |
149 | 0 | { |
150 | | // no transparence |
151 | 0 | rTarget = drawinglayer::primitive2d::Primitive2DContainer{ |
152 | 0 | new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D( |
153 | 0 | basegfx::B2DPolyPolygon(basegfx::utils::createPolygonFromRect(aRange)), |
154 | 0 | maFloodColor.getBColor()) |
155 | 0 | }; |
156 | 0 | } |
157 | 0 | else |
158 | 0 | { |
159 | | // transparence |
160 | 0 | rTarget = drawinglayer::primitive2d::Primitive2DContainer{ |
161 | 0 | new drawinglayer::primitive2d::PolyPolygonRGBAPrimitive2D( |
162 | 0 | basegfx::B2DPolyPolygon(basegfx::utils::createPolygonFromRect(aRange)), |
163 | 0 | maFloodColor.getBColor(), 1.0 - fOpacity) |
164 | 0 | }; |
165 | 0 | } |
166 | |
|
167 | 0 | pParent->addGraphicSourceToMapper(maResult, rTarget); |
168 | 0 | } |
169 | | |
170 | | } // end of namespace svgio::svgreader |
171 | | |
172 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |