merge the formfield patch from ooo-build
[ooovba.git] / svx / source / sdr / primitive2d / sdrellipseprimitive2d.cxx
blobc30b036bf5e756694bbe740020ca86da72bb0914
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
51 namespace primitive2d
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
60 // stroke start, too.
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);
73 // add fill
74 if(getSdrLFSTAttribute().getFill())
76 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createPolyPolygonFillPrimitive(::basegfx::B2DPolyPolygon(aUnitOutline), getTransform(), *getSdrLFSTAttribute().getFill(), getSdrLFSTAttribute().getFillFloatTransGradient()));
79 // add line
80 if(getSdrLFSTAttribute().getLine())
82 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createPolygonLinePrimitive(aUnitOutline, getTransform(), *getSdrLFSTAttribute().getLine()));
84 else
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)));
94 // add text
95 if(getSdrLFSTAttribute().getText())
97 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createTextPrimitive(::basegfx::B2DPolyPolygon(aUnitOutline), getTransform(), *getSdrLFSTAttribute().getText(), getSdrLFSTAttribute().getLine(), false, false));
100 // add shadow
101 if(getSdrLFSTAttribute().getShadow())
103 aRetval = createEmbeddedShadowPrimitive(aRetval, *getSdrLFSTAttribute().getShadow());
106 return aRetval;
109 SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
110 const ::basegfx::B2DHomMatrix& rTransform,
111 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute)
112 : BasePrimitive2D(),
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());
128 return false;
131 // provide unique ID
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;
151 if(mbCloseSegment)
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);
170 // add fill
171 if(getSdrLFSTAttribute().getFill() && aUnitOutline.isClosed())
173 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createPolyPolygonFillPrimitive(::basegfx::B2DPolyPolygon(aUnitOutline), getTransform(), *getSdrLFSTAttribute().getFill(), getSdrLFSTAttribute().getFillFloatTransGradient()));
176 // add line
177 if(getSdrLFSTAttribute().getLine())
179 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createPolygonLinePrimitive(aUnitOutline, getTransform(), *getSdrLFSTAttribute().getLine(), getSdrLFSTAttribute().getLineStartEnd()));
181 else
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)));
191 // add text
192 if(getSdrLFSTAttribute().getText())
194 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createTextPrimitive(::basegfx::B2DPolyPolygon(aUnitOutline), getTransform(), *getSdrLFSTAttribute().getText(), getSdrLFSTAttribute().getLine(), false, false));
197 // add shadow
198 if(getSdrLFSTAttribute().getShadow())
200 aRetval = createEmbeddedShadowPrimitive(aRetval, *getSdrLFSTAttribute().getShadow());
203 return aRetval;
206 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
207 const ::basegfx::B2DHomMatrix& rTransform,
208 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
209 double fStartAngle,
210 double fEndAngle,
211 bool bCloseSegment,
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)
232 return true;
236 return false;
239 // provide unique ID
240 ImplPrimitrive2DIDBlock(SdrEllipseSegmentPrimitive2D, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D)
242 } // end of namespace primitive2d
243 } // end of namespace drawinglayer
245 //////////////////////////////////////////////////////////////////////////////
246 // eof