1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
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
);
54 if(!getSdrLFSTAttribute().getFill().isDefault())
56 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
58 aTransformed
.transform(getTransform());
60 createPolyPolygonFillPrimitive(
62 getSdrLFSTAttribute().getFill(),
63 getSdrLFSTAttribute().getFillFloatTransGradient()));
67 if(getSdrLFSTAttribute().getLine().isDefault())
69 // create invisible line for HitTest/BoundRect
71 createHiddenGeometryPrimitives2D(
73 basegfx::B2DPolyPolygon(aUnitOutline
),
78 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
80 aTransformed
.transform(getTransform());
82 createPolygonLinePrimitive(
84 getSdrLFSTAttribute().getLine(),
85 attribute::SdrLineStartEndAttribute()));
89 if(!getSdrLFSTAttribute().getText().isDefault())
93 basegfx::B2DPolyPolygon(aUnitOutline
),
95 getSdrLFSTAttribute().getText(),
96 getSdrLFSTAttribute().getLine(),
102 if(!getSdrLFSTAttribute().getShadow().isDefault())
104 aRetval
= createEmbeddedShadowPrimitive(
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());
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
));
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
);
168 if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline
.isClosed())
170 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
172 aTransformed
.transform(getTransform());
174 createPolyPolygonFillPrimitive(
176 getSdrLFSTAttribute().getFill(),
177 getSdrLFSTAttribute().getFillFloatTransGradient()));
181 if(getSdrLFSTAttribute().getLine().isDefault())
183 // create invisible line for HitTest/BoundRect
185 createHiddenGeometryPrimitives2D(
187 basegfx::B2DPolyPolygon(aUnitOutline
),
192 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
194 aTransformed
.transform(getTransform());
196 createPolygonLinePrimitive(
198 getSdrLFSTAttribute().getLine(),
199 getSdrLFSTAttribute().getLineStartEnd()));
203 if(!getSdrLFSTAttribute().getText().isDefault())
207 basegfx::B2DPolyPolygon(aUnitOutline
),
209 getSdrLFSTAttribute().getText(),
210 getSdrLFSTAttribute().getLine(),
216 if(!getSdrLFSTAttribute().getShadow().isDefault())
218 aRetval
= createEmbeddedShadowPrimitive(
220 getSdrLFSTAttribute().getShadow());
223 rContainer
.append(std::move(aRetval
));
226 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
227 const basegfx::B2DHomMatrix
& rTransform
,
228 const attribute::SdrLineFillEffectsTextAttribute
& rSdrLFSTAttribute
,
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
)
260 sal_uInt32
SdrEllipseSegmentPrimitive2D::getPrimitive2DID() const
262 return PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D
;
265 } // end of namespace
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */