Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrellipseprimitive2d.cxx
blob1a341b8ff3fc6211be84ea58bcd62d3aa3be5e25
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>
30 using namespace com::sun::star;
33 namespace drawinglayer::primitive2d
35 void SdrEllipsePrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
37 Primitive2DContainer aRetval;
39 // create unit outline polygon
40 // Do use createPolygonFromUnitCircle, but let create from first quadrant to mimic old geometry creation.
41 // This is needed to have the same look when stroke is used since the polygon start point defines the
42 // stroke start, too.
43 basegfx::B2DPolygon aUnitOutline(basegfx::utils::createPolygonFromUnitCircle(1));
45 // scale and move UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
46 const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
47 basegfx::utils::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
49 // apply to the geometry
50 aUnitOutline.transform(aUnitCorrectionMatrix);
52 // add fill
53 if(!getSdrLFSTAttribute().getFill().isDefault())
55 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
57 aTransformed.transform(getTransform());
58 aRetval.push_back(
59 createPolyPolygonFillPrimitive(
60 aTransformed,
61 getSdrLFSTAttribute().getFill(),
62 getSdrLFSTAttribute().getFillFloatTransGradient()));
65 // add line
66 if(getSdrLFSTAttribute().getLine().isDefault())
68 // create invisible line for HitTest/BoundRect
69 aRetval.push_back(
70 createHiddenGeometryPrimitives2D(
71 false,
72 basegfx::B2DPolyPolygon(aUnitOutline),
73 getTransform()));
75 else
77 basegfx::B2DPolygon aTransformed(aUnitOutline);
79 aTransformed.transform(getTransform());
80 aRetval.push_back(
81 createPolygonLinePrimitive(
82 aTransformed,
83 getSdrLFSTAttribute().getLine(),
84 attribute::SdrLineStartEndAttribute()));
87 // add text
88 if(!getSdrLFSTAttribute().getText().isDefault())
90 aRetval.push_back(
91 createTextPrimitive(
92 basegfx::B2DPolyPolygon(aUnitOutline),
93 getTransform(),
94 getSdrLFSTAttribute().getText(),
95 getSdrLFSTAttribute().getLine(),
96 false,
97 false));
100 // add shadow
101 if(!getSdrLFSTAttribute().getShadow().isDefault())
103 aRetval = createEmbeddedShadowPrimitive(
104 aRetval,
105 getSdrLFSTAttribute().getShadow());
108 rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end());
111 SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
112 const basegfx::B2DHomMatrix& rTransform,
113 const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute)
114 : BufferedDecompositionPrimitive2D(),
115 maTransform(rTransform),
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 ImplPrimitive2DIDBlock(SdrEllipsePrimitive2D, PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D)
138 void SdrEllipseSegmentPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
140 Primitive2DContainer aRetval;
142 // create unit outline polygon
143 basegfx::B2DPolygon aUnitOutline(basegfx::utils::createPolygonFromUnitEllipseSegment(mfStartAngle, mfEndAngle));
145 if(mbCloseSegment)
147 if(mbCloseUsingCenter)
149 // for compatibility, insert the center point at polygon start to get the same
150 // line stroking pattern as the old painting mechanisms.
151 aUnitOutline.insert(0, basegfx::B2DPoint(0.0, 0.0));
154 aUnitOutline.setClosed(true);
157 // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
158 const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
159 basegfx::utils::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
161 // apply to the geometry
162 aUnitOutline.transform(aUnitCorrectionMatrix);
164 // add fill
165 if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
167 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
169 aTransformed.transform(getTransform());
170 aRetval.push_back(
171 createPolyPolygonFillPrimitive(
172 aTransformed,
173 getSdrLFSTAttribute().getFill(),
174 getSdrLFSTAttribute().getFillFloatTransGradient()));
177 // add line
178 if(getSdrLFSTAttribute().getLine().isDefault())
180 // create invisible line for HitTest/BoundRect
181 aRetval.push_back(
182 createHiddenGeometryPrimitives2D(
183 false,
184 basegfx::B2DPolyPolygon(aUnitOutline),
185 getTransform()));
187 else
189 basegfx::B2DPolygon aTransformed(aUnitOutline);
191 aTransformed.transform(getTransform());
192 aRetval.push_back(
193 createPolygonLinePrimitive(
194 aTransformed,
195 getSdrLFSTAttribute().getLine(),
196 getSdrLFSTAttribute().getLineStartEnd()));
199 // add text
200 if(!getSdrLFSTAttribute().getText().isDefault())
202 aRetval.push_back(
203 createTextPrimitive(
204 basegfx::B2DPolyPolygon(aUnitOutline),
205 getTransform(),
206 getSdrLFSTAttribute().getText(),
207 getSdrLFSTAttribute().getLine(),
208 false,
209 false));
212 // add shadow
213 if(!getSdrLFSTAttribute().getShadow().isDefault())
215 aRetval = createEmbeddedShadowPrimitive(
216 aRetval,
217 getSdrLFSTAttribute().getShadow());
220 rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end());
223 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
224 const basegfx::B2DHomMatrix& rTransform,
225 const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute,
226 double fStartAngle,
227 double fEndAngle,
228 bool bCloseSegment,
229 bool bCloseUsingCenter)
230 : SdrEllipsePrimitive2D(rTransform, rSdrLFSTAttribute),
231 mfStartAngle(fStartAngle),
232 mfEndAngle(fEndAngle),
233 mbCloseSegment(bCloseSegment),
234 mbCloseUsingCenter(bCloseUsingCenter)
238 bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
240 if(SdrEllipsePrimitive2D::operator==(rPrimitive))
242 const SdrEllipseSegmentPrimitive2D& rCompare = static_cast<const SdrEllipseSegmentPrimitive2D&>(rPrimitive);
244 if( mfStartAngle == rCompare.mfStartAngle
245 && mfEndAngle == rCompare.mfEndAngle
246 && mbCloseSegment == rCompare.mbCloseSegment
247 && mbCloseUsingCenter == rCompare.mbCloseUsingCenter)
249 return true;
253 return false;
256 // provide unique ID
257 ImplPrimitive2DIDBlock(SdrEllipseSegmentPrimitive2D, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D)
259 } // end of namespace
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */