/src/libreoffice/svx/source/sdr/primitive2d/sdrpathprimitive2d.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 <sdr/primitive2d/sdrpathprimitive2d.hxx> |
21 | | #include <sdr/primitive2d/sdrdecompositiontools.hxx> |
22 | | #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx> |
23 | | #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx> |
24 | | #include <drawinglayer/primitive2d/groupprimitive2d.hxx> |
25 | | #include <drawinglayer/primitive2d/maskprimitive2d.hxx> |
26 | | #include <utility> |
27 | | |
28 | | |
29 | | using namespace com::sun::star; |
30 | | |
31 | | |
32 | | namespace drawinglayer::primitive2d |
33 | | { |
34 | | Primitive2DReference SdrPathPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const |
35 | 440 | { |
36 | 440 | Primitive2DContainer aRetval; |
37 | | |
38 | | // add fill |
39 | 440 | if(!getSdrLFSTAttribute().getFill().isDefault() |
40 | 334 | && getUnitPolyPolygon().isClosed()) |
41 | 24 | { |
42 | | // #i108255# no need to use correctOrientations here; target is |
43 | | // straight visualisation |
44 | 24 | basegfx::B2DPolyPolygon aTransformed(getUnitPolyPolygon()); |
45 | 24 | aTransformed.transform(getTransform()); |
46 | | |
47 | | // OperationSmiley: Check if a UnitDefinitionPolyPolygon is set |
48 | 24 | if(getUnitDefinitionPolyPolygon().count() |
49 | 17 | && getUnitDefinitionPolyPolygon() != getUnitPolyPolygon()) |
50 | 17 | { |
51 | | // if yes, use the B2DRange of it's transformed form |
52 | 17 | basegfx::B2DPolyPolygon aTransformedDefinition(getUnitDefinitionPolyPolygon()); |
53 | 17 | aTransformedDefinition.transform(getTransform()); |
54 | | |
55 | 17 | aRetval.push_back( |
56 | 17 | createPolyPolygonFillPrimitive( |
57 | 17 | aTransformed, |
58 | 17 | aTransformedDefinition.getB2DRange(), |
59 | 17 | getSdrLFSTAttribute().getFill(), |
60 | 17 | getSdrLFSTAttribute().getFillFloatTransGradient())); |
61 | 17 | } |
62 | 7 | else |
63 | 7 | { |
64 | 7 | aRetval.push_back( |
65 | 7 | createPolyPolygonFillPrimitive( |
66 | 7 | aTransformed, |
67 | 7 | getSdrLFSTAttribute().getFill(), |
68 | 7 | getSdrLFSTAttribute().getFillFloatTransGradient())); |
69 | 7 | } |
70 | 24 | } |
71 | | |
72 | | // add line |
73 | 440 | if(getSdrLFSTAttribute().getLine().isDefault()) |
74 | 23 | { |
75 | | // if initially no line is defined, create one for HitTest and BoundRect |
76 | 23 | aRetval.push_back( |
77 | 23 | createHiddenGeometryPrimitives2D( |
78 | 23 | false, |
79 | 23 | getUnitPolyPolygon(), |
80 | 23 | getTransform())); |
81 | 23 | } |
82 | 417 | else |
83 | 417 | { |
84 | 417 | Primitive2DContainer aTemp(getUnitPolyPolygon().count()); |
85 | | |
86 | 834 | for(sal_uInt32 a(0); a < getUnitPolyPolygon().count(); a++) |
87 | 417 | { |
88 | 417 | basegfx::B2DPolygon aTransformed(getUnitPolyPolygon().getB2DPolygon(a)); |
89 | | |
90 | 417 | aTransformed.transform(getTransform()); |
91 | 417 | aTemp[a] = createPolygonLinePrimitive( |
92 | 417 | aTransformed, |
93 | 417 | getSdrLFSTAttribute().getLine(), |
94 | 417 | getSdrLFSTAttribute().getLineStartEnd()); |
95 | 417 | } |
96 | | |
97 | 417 | aRetval.append(aTemp); |
98 | 417 | } |
99 | | |
100 | | // Soft edges should be before text, since text is not affected by soft edges |
101 | 440 | if (!aRetval.empty() && getSdrLFSTAttribute().getSoftEdgeRadius()) |
102 | 0 | { |
103 | 0 | aRetval = createEmbeddedSoftEdgePrimitive(std::move(aRetval), |
104 | 0 | getSdrLFSTAttribute().getSoftEdgeRadius()); |
105 | 0 | } |
106 | | |
107 | | // tdf#132199: put glow before shadow, to have shadow of the glow, not the opposite |
108 | 440 | if (!aRetval.empty() && !getSdrLFSTAttribute().getGlow().isDefault()) |
109 | 0 | { |
110 | | // glow |
111 | 0 | aRetval = createEmbeddedGlowPrimitive(std::move(aRetval), getSdrLFSTAttribute().getGlow()); |
112 | 0 | } |
113 | | |
114 | | // add text |
115 | 440 | if(!getSdrLFSTAttribute().getText().isDefault()) |
116 | 6 | { |
117 | 6 | aRetval.push_back( |
118 | 6 | createTextPrimitive( |
119 | 6 | getUnitPolyPolygon(), |
120 | 6 | getTransform(), |
121 | 6 | getSdrLFSTAttribute().getText(), |
122 | 6 | getSdrLFSTAttribute().getLine(), |
123 | 6 | false, |
124 | 6 | false)); |
125 | 6 | } |
126 | | |
127 | | // The reflection shows the shape with its glow and text, but not its shadow. |
128 | 440 | Primitive2DContainer aReflected; |
129 | 440 | if (!getSdrLFSTAttribute().getReflection().isDefault()) |
130 | 0 | aReflected = aRetval; |
131 | | |
132 | | // add shadow |
133 | 440 | if(!getSdrLFSTAttribute().getShadow().isDefault()) |
134 | 0 | { |
135 | 0 | aRetval = createEmbeddedShadowPrimitive( |
136 | 0 | std::move(aRetval), |
137 | 0 | getSdrLFSTAttribute().getShadow()); |
138 | 0 | } |
139 | | |
140 | 440 | if (!aReflected.empty()) |
141 | 0 | { |
142 | 0 | aRetval = createEmbeddedReflectionPrimitive( |
143 | 0 | std::move(aRetval), std::move(aReflected), getSdrLFSTAttribute().getReflection()); |
144 | 0 | } |
145 | | |
146 | 440 | if (getClipPolyPolygon().count() > 0) |
147 | 0 | { |
148 | 0 | const drawinglayer::primitive2d::Primitive2DReference aMaskedGraphic( |
149 | 0 | new drawinglayer::primitive2d::MaskPrimitive2D( |
150 | 0 | getClipPolyPolygon(), |
151 | 0 | std::move(aRetval))); |
152 | 0 | aRetval = { aMaskedGraphic }; |
153 | 0 | } |
154 | | |
155 | 440 | return new GroupPrimitive2D(std::move(aRetval)); |
156 | 440 | } |
157 | | |
158 | | SdrPathPrimitive2D::SdrPathPrimitive2D( |
159 | | basegfx::B2DHomMatrix aTransform, |
160 | | const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute, |
161 | | basegfx::B2DPolyPolygon aUnitPolyPolygon, |
162 | | basegfx::B2DPolyPolygon aUnitDefinitionPolyPolygon, |
163 | | basegfx::B2DPolyPolygon aClipPolyPolygon) |
164 | 510 | : maTransform(std::move(aTransform)), |
165 | 510 | maSdrLFSTAttribute(rSdrLFSTAttribute), |
166 | 510 | maUnitPolyPolygon(std::move(aUnitPolyPolygon)), |
167 | 510 | maUnitDefinitionPolyPolygon(std::move(aUnitDefinitionPolyPolygon)), |
168 | 510 | maClipPolyPolygon(std::move(aClipPolyPolygon)) |
169 | 510 | { |
170 | 510 | } |
171 | | |
172 | | bool SdrPathPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const |
173 | 140 | { |
174 | 140 | if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) |
175 | 140 | { |
176 | 140 | const SdrPathPrimitive2D& rCompare = static_cast<const SdrPathPrimitive2D&>(rPrimitive); |
177 | | |
178 | 140 | return (getUnitPolyPolygon() == rCompare.getUnitPolyPolygon() |
179 | 140 | && getUnitDefinitionPolyPolygon() == rCompare.getUnitDefinitionPolyPolygon() |
180 | 140 | && getTransform() == rCompare.getTransform() |
181 | 140 | && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute() |
182 | 140 | && getClipPolyPolygon() == rCompare.getClipPolyPolygon()); |
183 | 140 | } |
184 | | |
185 | 0 | return false; |
186 | 140 | } |
187 | | |
188 | | // provide unique ID |
189 | | sal_uInt32 SdrPathPrimitive2D::getPrimitive2DID() const |
190 | 788 | { |
191 | 788 | return PRIMITIVE2D_ID_SDRPATHPRIMITIVE2D; |
192 | 788 | } |
193 | | |
194 | | } // end of namespace |
195 | | |
196 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |