/src/libreoffice/svgio/source/svgreader/svgfedropshadownode.cxx
Line | Count | Source (jump to first uncovered line) |
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/Primitive2DContainer.hxx> |
21 | | #include <drawinglayer/primitive2d/shadowprimitive2d.hxx> |
22 | | #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx> |
23 | | #include <basegfx/polygon/b2dpolygontools.hxx> |
24 | | #include <svgfedropshadownode.hxx> |
25 | | #include <o3tl/string_view.hxx> |
26 | | |
27 | | namespace svgio::svgreader |
28 | | { |
29 | | SvgFeDropShadowNode::SvgFeDropShadowNode(SvgDocument& rDocument, SvgNode* pParent) |
30 | 0 | : SvgFilterNode(SVGToken::FeDropShadow, rDocument, pParent) |
31 | 0 | , maDx(0.0) |
32 | 0 | , maDy(0.0) |
33 | 0 | , maStdDeviation(0.0) |
34 | 0 | , maFloodColor(SvgPaint()) |
35 | 0 | , maFloodOpacity(1.0) |
36 | 0 | { |
37 | 0 | } |
38 | | |
39 | 0 | SvgFeDropShadowNode::~SvgFeDropShadowNode() {} |
40 | | |
41 | | void SvgFeDropShadowNode::parseAttribute(SVGToken aSVGToken, const OUString& aContent) |
42 | 0 | { |
43 | | // parse own |
44 | 0 | switch (aSVGToken) |
45 | 0 | { |
46 | 0 | case SVGToken::Style: |
47 | 0 | { |
48 | 0 | readLocalCssStyle(aContent); |
49 | 0 | break; |
50 | 0 | } |
51 | 0 | case SVGToken::In: |
52 | 0 | { |
53 | 0 | maIn = aContent.trim(); |
54 | 0 | break; |
55 | 0 | } |
56 | 0 | case SVGToken::Result: |
57 | 0 | { |
58 | 0 | maResult = aContent.trim(); |
59 | 0 | break; |
60 | 0 | } |
61 | 0 | case SVGToken::Dx: |
62 | 0 | { |
63 | 0 | SvgNumber aNum; |
64 | |
|
65 | 0 | if (readSingleNumber(aContent, aNum)) |
66 | 0 | { |
67 | 0 | maDx = aNum; |
68 | 0 | } |
69 | 0 | break; |
70 | 0 | } |
71 | 0 | case SVGToken::Dy: |
72 | 0 | { |
73 | 0 | SvgNumber aNum; |
74 | |
|
75 | 0 | if (readSingleNumber(aContent, aNum)) |
76 | 0 | { |
77 | 0 | maDy = aNum; |
78 | 0 | } |
79 | 0 | break; |
80 | 0 | } |
81 | 0 | case SVGToken::StdDeviation: |
82 | 0 | { |
83 | 0 | SvgNumber aNum; |
84 | |
|
85 | 0 | if (readSingleNumber(aContent, aNum)) |
86 | 0 | { |
87 | 0 | maStdDeviation = aNum; |
88 | 0 | } |
89 | 0 | break; |
90 | 0 | } |
91 | 0 | case SVGToken::FloodColor: |
92 | 0 | { |
93 | 0 | SvgPaint aSvgPaint; |
94 | 0 | OUString aURL; |
95 | 0 | SvgNumber aOpacity; |
96 | |
|
97 | 0 | if (readSvgPaint(aContent, aSvgPaint, aURL, aOpacity)) |
98 | 0 | { |
99 | 0 | maFloodColor = aSvgPaint; |
100 | 0 | } |
101 | 0 | break; |
102 | 0 | } |
103 | 0 | case SVGToken::FloodOpacity: |
104 | 0 | { |
105 | 0 | SvgNumber aNum; |
106 | |
|
107 | 0 | if (readSingleNumber(aContent, aNum)) |
108 | 0 | { |
109 | 0 | maFloodOpacity = SvgNumber(std::clamp(aNum.getNumber(), 0.0, 1.0), aNum.getUnit(), |
110 | 0 | aNum.isSet()); |
111 | 0 | } |
112 | 0 | break; |
113 | 0 | } |
114 | | |
115 | 0 | default: |
116 | 0 | { |
117 | 0 | break; |
118 | 0 | } |
119 | 0 | } |
120 | 0 | } |
121 | | |
122 | | void SvgFeDropShadowNode::apply(drawinglayer::primitive2d::Primitive2DContainer& rTarget, |
123 | | const SvgFilterNode* pParent) const |
124 | 0 | { |
125 | 0 | if (const drawinglayer::primitive2d::Primitive2DContainer* rSource |
126 | 0 | = pParent->findGraphicSource(maIn)) |
127 | 0 | { |
128 | 0 | rTarget = *rSource; |
129 | 0 | } |
130 | |
|
131 | 0 | basegfx::B2DHomMatrix aTransform; |
132 | 0 | if (maDx.isSet() || maDy.isSet()) |
133 | 0 | { |
134 | 0 | aTransform.translate(maDx.solve(*this, NumberType::xcoordinate), |
135 | 0 | maDy.solve(*this, NumberType::ycoordinate)); |
136 | 0 | } |
137 | |
|
138 | 0 | drawinglayer::primitive2d::Primitive2DContainer aTempTarget; |
139 | | |
140 | | // Create the shadow |
141 | 0 | aTempTarget.append(new drawinglayer::primitive2d::ShadowPrimitive2D( |
142 | 0 | aTransform, maFloodColor.getBColor(), maStdDeviation.getNumber(), |
143 | 0 | drawinglayer::primitive2d::Primitive2DContainer(rTarget))); |
144 | |
|
145 | 0 | const double fOpacity(maFloodOpacity.solve(*this)); |
146 | 0 | if (basegfx::fTools::less(fOpacity, 1.0)) |
147 | 0 | { |
148 | | // Apply transparence to the shadow |
149 | 0 | aTempTarget.append(new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D( |
150 | 0 | std::move(aTempTarget), 1.0 - fOpacity)); |
151 | 0 | } |
152 | | |
153 | | // Append the original target |
154 | 0 | aTempTarget.append(rTarget); |
155 | |
|
156 | 0 | rTarget = std::move(aTempTarget); |
157 | |
|
158 | 0 | pParent->addGraphicSourceToMapper(maResult, rTarget); |
159 | 0 | } |
160 | | |
161 | | } // end of namespace svgio::svgreader |
162 | | |
163 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |