1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdrellipseprimitive2d.cxx,v $
11 * $Revision: 1.2.18.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/primitive2d/sdrellipseprimitive2d.hxx>
34 #include <basegfx/polygon/b2dpolygon.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
36 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
37 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
38 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
39 #include <drawinglayer/primitive2d/hittestprimitive2d.hxx>
40 #include <basegfx/color/bcolor.hxx>
41 #include <drawinglayer/attribute/sdrattribute.hxx>
43 //////////////////////////////////////////////////////////////////////////////
45 using namespace com::sun::star
;
47 //////////////////////////////////////////////////////////////////////////////
49 namespace drawinglayer
53 Primitive2DSequence
SdrEllipsePrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
55 Primitive2DSequence aRetval
;
57 // create unit outline polygon
58 // Do use createPolygonFromUnitCircle, but let create from first quadrant to mimic old geometry creation.
59 // This is needed to have the same look when stroke is used since the polygon start point defines the
61 ::basegfx::B2DPolygon
aUnitOutline(::basegfx::tools::createPolygonFromUnitCircle(1));
63 // scale and move UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
64 ::basegfx::B2DHomMatrix aUnitCorrectionMatrix
;
65 aUnitCorrectionMatrix
.set(0, 0, 0.5);
66 aUnitCorrectionMatrix
.set(1, 1, 0.5);
67 aUnitCorrectionMatrix
.set(0, 2, 0.5);
68 aUnitCorrectionMatrix
.set(1, 2, 0.5);
70 // apply to the geometry
71 aUnitOutline
.transform(aUnitCorrectionMatrix
);
74 if(getSdrLFSTAttribute().getFill())
76 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, createPolyPolygonFillPrimitive(::basegfx::B2DPolyPolygon(aUnitOutline
), getTransform(), *getSdrLFSTAttribute().getFill(), getSdrLFSTAttribute().getFillFloatTransGradient()));
80 if(getSdrLFSTAttribute().getLine())
82 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, createPolygonLinePrimitive(aUnitOutline
, getTransform(), *getSdrLFSTAttribute().getLine()));
86 // if initially no line is defined, create one for HitTest and BoundRect
87 const attribute::SdrLineAttribute
aBlackHairline(basegfx::BColor(0.0, 0.0, 0.0));
88 const Primitive2DReference
xHiddenLineReference(createPolygonLinePrimitive(aUnitOutline
, getTransform(), aBlackHairline
));
89 const Primitive2DSequence
xHiddenLineSequence(&xHiddenLineReference
, 1);
91 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, Primitive2DReference(new HitTestPrimitive2D(xHiddenLineSequence
)));
95 if(getSdrLFSTAttribute().getText())
97 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, createTextPrimitive(::basegfx::B2DPolyPolygon(aUnitOutline
), getTransform(), *getSdrLFSTAttribute().getText(), getSdrLFSTAttribute().getLine(), false, false));
101 if(getSdrLFSTAttribute().getShadow())
103 aRetval
= createEmbeddedShadowPrimitive(aRetval
, *getSdrLFSTAttribute().getShadow());
109 SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
110 const ::basegfx::B2DHomMatrix
& rTransform
,
111 const attribute::SdrLineFillShadowTextAttribute
& rSdrLFSTAttribute
)
113 maTransform(rTransform
),
114 maSdrLFSTAttribute(rSdrLFSTAttribute
)
118 bool SdrEllipsePrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
120 if(BasePrimitive2D::operator==(rPrimitive
))
122 const SdrEllipsePrimitive2D
& rCompare
= (SdrEllipsePrimitive2D
&)rPrimitive
;
124 return (getTransform() == rCompare
.getTransform()
125 && getSdrLFSTAttribute() == rCompare
.getSdrLFSTAttribute());
132 ImplPrimitrive2DIDBlock(SdrEllipsePrimitive2D
, PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D
)
134 } // end of namespace primitive2d
135 } // end of namespace drawinglayer
137 //////////////////////////////////////////////////////////////////////////////
139 namespace drawinglayer
141 namespace primitive2d
143 Primitive2DSequence
SdrEllipseSegmentPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
145 Primitive2DSequence aRetval
;
147 // create unit outline polygon
148 ::basegfx::B2DPolygon
aUnitOutline(::basegfx::tools::createPolygonFromUnitEllipseSegment(mfStartAngle
, mfEndAngle
));
149 ::basegfx::B2DHomMatrix aUnitCorrectionMatrix
;
153 if(mbCloseUsingCenter
)
155 // for compatibility, insert the center point at polygon start to get the same
156 // line stroking pattern as the old painting mechanisms.
157 aUnitOutline
.insert(0L, ::basegfx::B2DPoint(0.0, 0.0));
160 aUnitOutline
.setClosed(true);
163 // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
164 aUnitCorrectionMatrix
.translate(1.0, 1.0);
165 aUnitCorrectionMatrix
.scale(0.5, 0.5);
167 // apply to the geometry
168 aUnitOutline
.transform(aUnitCorrectionMatrix
);
171 if(getSdrLFSTAttribute().getFill() && aUnitOutline
.isClosed())
173 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, createPolyPolygonFillPrimitive(::basegfx::B2DPolyPolygon(aUnitOutline
), getTransform(), *getSdrLFSTAttribute().getFill(), getSdrLFSTAttribute().getFillFloatTransGradient()));
177 if(getSdrLFSTAttribute().getLine())
179 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, createPolygonLinePrimitive(aUnitOutline
, getTransform(), *getSdrLFSTAttribute().getLine(), getSdrLFSTAttribute().getLineStartEnd()));
183 // if initially no line is defined, create one for HitTest and BoundRect
184 const attribute::SdrLineAttribute
aBlackHairline(basegfx::BColor(0.0, 0.0, 0.0));
185 const Primitive2DReference
xHiddenLineReference(createPolygonLinePrimitive(aUnitOutline
, getTransform(), aBlackHairline
));
186 const Primitive2DSequence
xHiddenLineSequence(&xHiddenLineReference
, 1);
188 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, Primitive2DReference(new HitTestPrimitive2D(xHiddenLineSequence
)));
192 if(getSdrLFSTAttribute().getText())
194 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, createTextPrimitive(::basegfx::B2DPolyPolygon(aUnitOutline
), getTransform(), *getSdrLFSTAttribute().getText(), getSdrLFSTAttribute().getLine(), false, false));
198 if(getSdrLFSTAttribute().getShadow())
200 aRetval
= createEmbeddedShadowPrimitive(aRetval
, *getSdrLFSTAttribute().getShadow());
206 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
207 const ::basegfx::B2DHomMatrix
& rTransform
,
208 const attribute::SdrLineFillShadowTextAttribute
& rSdrLFSTAttribute
,
212 bool bCloseUsingCenter
)
213 : SdrEllipsePrimitive2D(rTransform
, rSdrLFSTAttribute
),
214 mfStartAngle(fStartAngle
),
215 mfEndAngle(fEndAngle
),
216 mbCloseSegment(bCloseSegment
),
217 mbCloseUsingCenter(bCloseUsingCenter
)
221 bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
223 if(SdrEllipsePrimitive2D::operator==(rPrimitive
))
225 const SdrEllipseSegmentPrimitive2D
& rCompare
= (SdrEllipseSegmentPrimitive2D
&)rPrimitive
;
227 if( mfStartAngle
== rCompare
.mfStartAngle
228 && mfEndAngle
== rCompare
.mfEndAngle
229 && mbCloseSegment
== rCompare
.mbCloseSegment
230 && mbCloseUsingCenter
== rCompare
.mbCloseUsingCenter
)
240 ImplPrimitrive2DIDBlock(SdrEllipseSegmentPrimitive2D
, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D
)
242 } // end of namespace primitive2d
243 } // end of namespace drawinglayer
245 //////////////////////////////////////////////////////////////////////////////