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>
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
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
);
53 if(!getSdrLFSTAttribute().getFill().isDefault())
55 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
57 aTransformed
.transform(getTransform());
59 createPolyPolygonFillPrimitive(
61 getSdrLFSTAttribute().getFill(),
62 getSdrLFSTAttribute().getFillFloatTransGradient()));
66 if(getSdrLFSTAttribute().getLine().isDefault())
68 // create invisible line for HitTest/BoundRect
70 createHiddenGeometryPrimitives2D(
72 basegfx::B2DPolyPolygon(aUnitOutline
),
77 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
79 aTransformed
.transform(getTransform());
81 createPolygonLinePrimitive(
83 getSdrLFSTAttribute().getLine(),
84 attribute::SdrLineStartEndAttribute()));
88 if(!getSdrLFSTAttribute().getText().isDefault())
92 basegfx::B2DPolyPolygon(aUnitOutline
),
94 getSdrLFSTAttribute().getText(),
95 getSdrLFSTAttribute().getLine(),
101 if(!getSdrLFSTAttribute().getShadow().isDefault())
103 aRetval
= createEmbeddedShadowPrimitive(
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());
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
));
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
);
165 if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline
.isClosed())
167 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
169 aTransformed
.transform(getTransform());
171 createPolyPolygonFillPrimitive(
173 getSdrLFSTAttribute().getFill(),
174 getSdrLFSTAttribute().getFillFloatTransGradient()));
178 if(getSdrLFSTAttribute().getLine().isDefault())
180 // create invisible line for HitTest/BoundRect
182 createHiddenGeometryPrimitives2D(
184 basegfx::B2DPolyPolygon(aUnitOutline
),
189 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
191 aTransformed
.transform(getTransform());
193 createPolygonLinePrimitive(
195 getSdrLFSTAttribute().getLine(),
196 getSdrLFSTAttribute().getLineStartEnd()));
200 if(!getSdrLFSTAttribute().getText().isDefault())
204 basegfx::B2DPolyPolygon(aUnitOutline
),
206 getSdrLFSTAttribute().getText(),
207 getSdrLFSTAttribute().getLine(),
213 if(!getSdrLFSTAttribute().getShadow().isDefault())
215 aRetval
= createEmbeddedShadowPrimitive(
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
,
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
)
257 ImplPrimitive2DIDBlock(SdrEllipseSegmentPrimitive2D
, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D
)
259 } // end of namespace
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */