Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrellipseprimitive2d.cxx
blob126b301391d89d4731b6ac0f3211d4d4edb46132
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sdr/primitive2d/sdrellipseprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <basegfx/polygon/b2dpolypolygon.hxx>
24 #include <sdr/primitive2d/sdrdecompositiontools.hxx>
25 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
26 #include <basegfx/matrix/b2dhommatrixtools.hxx>
27 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
28 #include <utility>
31 using namespace com::sun::star;
34 namespace drawinglayer::primitive2d
36 void SdrEllipsePrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
38 Primitive2DContainer aRetval;
40 // create unit outline polygon
41 // Do use createPolygonFromUnitCircle, but let create from first quadrant to mimic old geometry creation.
42 // This is needed to have the same look when stroke is used since the polygon start point defines the
43 // stroke start, too.
44 basegfx::B2DPolygon aUnitOutline(basegfx::utils::createPolygonFromUnitCircle(1));
46 // scale and move UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
47 const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
48 basegfx::utils::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
50 // apply to the geometry
51 aUnitOutline.transform(aUnitCorrectionMatrix);
53 // add fill
54 if(!getSdrLFSTAttribute().getFill().isDefault())
56 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
58 aTransformed.transform(getTransform());
59 aRetval.push_back(
60 createPolyPolygonFillPrimitive(
61 aTransformed,
62 getSdrLFSTAttribute().getFill(),
63 getSdrLFSTAttribute().getFillFloatTransGradient()));
66 // add line
67 if(getSdrLFSTAttribute().getLine().isDefault())
69 // create invisible line for HitTest/BoundRect
70 aRetval.push_back(
71 createHiddenGeometryPrimitives2D(
72 false,
73 basegfx::B2DPolyPolygon(aUnitOutline),
74 getTransform()));
76 else
78 basegfx::B2DPolygon aTransformed(aUnitOutline);
80 aTransformed.transform(getTransform());
81 aRetval.push_back(
82 createPolygonLinePrimitive(
83 aTransformed,
84 getSdrLFSTAttribute().getLine(),
85 attribute::SdrLineStartEndAttribute()));
88 // add text
89 if(!getSdrLFSTAttribute().getText().isDefault())
91 aRetval.push_back(
92 createTextPrimitive(
93 basegfx::B2DPolyPolygon(aUnitOutline),
94 getTransform(),
95 getSdrLFSTAttribute().getText(),
96 getSdrLFSTAttribute().getLine(),
97 false,
98 false));
101 // add shadow
102 if(!getSdrLFSTAttribute().getShadow().isDefault())
104 aRetval = createEmbeddedShadowPrimitive(
105 std::move(aRetval),
106 getSdrLFSTAttribute().getShadow());
109 rContainer.append(std::move(aRetval));
112 SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
113 basegfx::B2DHomMatrix aTransform,
114 const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute)
115 : maTransform(std::move(aTransform)),
116 maSdrLFSTAttribute(rSdrLFSTAttribute)
120 bool SdrEllipsePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
122 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
124 const SdrEllipsePrimitive2D& rCompare = static_cast<const SdrEllipsePrimitive2D&>(rPrimitive);
126 return (getTransform() == rCompare.getTransform()
127 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute());
130 return false;
133 // provide unique ID
134 sal_uInt32 SdrEllipsePrimitive2D::getPrimitive2DID() const
136 return PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D;
141 void SdrEllipseSegmentPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
143 Primitive2DContainer aRetval;
145 // create unit outline polygon
146 basegfx::B2DPolygon aUnitOutline(basegfx::utils::createPolygonFromUnitEllipseSegment(mfStartAngle, mfEndAngle));
148 if(mbCloseSegment)
150 if(mbCloseUsingCenter)
152 // for compatibility, insert the center point at polygon start to get the same
153 // line stroking pattern as the old painting mechanisms.
154 aUnitOutline.insert(0, basegfx::B2DPoint(0.0, 0.0));
157 aUnitOutline.setClosed(true);
160 // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
161 const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
162 basegfx::utils::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
164 // apply to the geometry
165 aUnitOutline.transform(aUnitCorrectionMatrix);
167 // add fill
168 if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
170 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
172 aTransformed.transform(getTransform());
173 aRetval.push_back(
174 createPolyPolygonFillPrimitive(
175 aTransformed,
176 getSdrLFSTAttribute().getFill(),
177 getSdrLFSTAttribute().getFillFloatTransGradient()));
180 // add line
181 if(getSdrLFSTAttribute().getLine().isDefault())
183 // create invisible line for HitTest/BoundRect
184 aRetval.push_back(
185 createHiddenGeometryPrimitives2D(
186 false,
187 basegfx::B2DPolyPolygon(aUnitOutline),
188 getTransform()));
190 else
192 basegfx::B2DPolygon aTransformed(aUnitOutline);
194 aTransformed.transform(getTransform());
195 aRetval.push_back(
196 createPolygonLinePrimitive(
197 aTransformed,
198 getSdrLFSTAttribute().getLine(),
199 getSdrLFSTAttribute().getLineStartEnd()));
202 // add text
203 if(!getSdrLFSTAttribute().getText().isDefault())
205 aRetval.push_back(
206 createTextPrimitive(
207 basegfx::B2DPolyPolygon(aUnitOutline),
208 getTransform(),
209 getSdrLFSTAttribute().getText(),
210 getSdrLFSTAttribute().getLine(),
211 false,
212 false));
215 // add shadow
216 if(!getSdrLFSTAttribute().getShadow().isDefault())
218 aRetval = createEmbeddedShadowPrimitive(
219 std::move(aRetval),
220 getSdrLFSTAttribute().getShadow());
223 rContainer.append(std::move(aRetval));
226 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
227 const basegfx::B2DHomMatrix& rTransform,
228 const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute,
229 double fStartAngle,
230 double fEndAngle,
231 bool bCloseSegment,
232 bool bCloseUsingCenter)
233 : SdrEllipsePrimitive2D(rTransform, rSdrLFSTAttribute),
234 mfStartAngle(fStartAngle),
235 mfEndAngle(fEndAngle),
236 mbCloseSegment(bCloseSegment),
237 mbCloseUsingCenter(bCloseUsingCenter)
241 bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
243 if(SdrEllipsePrimitive2D::operator==(rPrimitive))
245 const SdrEllipseSegmentPrimitive2D& rCompare = static_cast<const SdrEllipseSegmentPrimitive2D&>(rPrimitive);
247 if( mfStartAngle == rCompare.mfStartAngle
248 && mfEndAngle == rCompare.mfEndAngle
249 && mbCloseSegment == rCompare.mbCloseSegment
250 && mbCloseUsingCenter == rCompare.mbCloseUsingCenter)
252 return true;
256 return false;
259 // provide unique ID
260 sal_uInt32 SdrEllipseSegmentPrimitive2D::getPrimitive2DID() const
262 return PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D;
265 } // end of namespace
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */