1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "precompiled_svx.hxx"
29*cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrrectangleprimitive2d.hxx>
30*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
31*cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
32*cdf0e10cSrcweir #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
33*cdf0e10cSrcweir #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
34*cdf0e10cSrcweir #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
35*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir using namespace com::sun::star;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir namespace drawinglayer
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir 	namespace primitive2d
46*cdf0e10cSrcweir 	{
47*cdf0e10cSrcweir 		Primitive2DSequence SdrRectanglePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
48*cdf0e10cSrcweir 		{
49*cdf0e10cSrcweir 			Primitive2DSequence aRetval;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 			// create unit outline polygon
52*cdf0e10cSrcweir 			const basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(
53*cdf0e10cSrcweir                 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
54*cdf0e10cSrcweir                 getCornerRadiusX(),
55*cdf0e10cSrcweir                 getCornerRadiusY()));
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 			// add fill
58*cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getFill().isDefault())
59*cdf0e10cSrcweir 			{
60*cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
61*cdf0e10cSrcweir                     createPolyPolygonFillPrimitive(
62*cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
63*cdf0e10cSrcweir                         getTransform(),
64*cdf0e10cSrcweir                         getSdrLFSTAttribute().getFill(),
65*cdf0e10cSrcweir                         getSdrLFSTAttribute().getFillFloatTransGradient()));
66*cdf0e10cSrcweir 			}
67*cdf0e10cSrcweir             else if(getForceFillForHitTest())
68*cdf0e10cSrcweir             {
69*cdf0e10cSrcweir                 // if no fill and it's a text frame, create a fill for HitTest and
70*cdf0e10cSrcweir                 // BoundRect fallback
71*cdf0e10cSrcweir                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
72*cdf0e10cSrcweir                     createHiddenGeometryPrimitives2D(
73*cdf0e10cSrcweir                         true,
74*cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
75*cdf0e10cSrcweir                         getTransform()));
76*cdf0e10cSrcweir             }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 			// add line
79*cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getLine().isDefault())
80*cdf0e10cSrcweir 			{
81*cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
82*cdf0e10cSrcweir                     createPolygonLinePrimitive(
83*cdf0e10cSrcweir                         aUnitOutline,
84*cdf0e10cSrcweir                         getTransform(),
85*cdf0e10cSrcweir                         getSdrLFSTAttribute().getLine(),
86*cdf0e10cSrcweir 						attribute::SdrLineStartEndAttribute()));
87*cdf0e10cSrcweir 			}
88*cdf0e10cSrcweir             else if(!getForceFillForHitTest())
89*cdf0e10cSrcweir             {
90*cdf0e10cSrcweir                 // if initially no line is defined and it's not a text frame, create
91*cdf0e10cSrcweir                 // a line for HitTest and BoundRect
92*cdf0e10cSrcweir                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
93*cdf0e10cSrcweir                     createHiddenGeometryPrimitives2D(
94*cdf0e10cSrcweir                         false,
95*cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
96*cdf0e10cSrcweir                         getTransform()));
97*cdf0e10cSrcweir             }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir             // add text
100*cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getText().isDefault())
101*cdf0e10cSrcweir 			{
102*cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
103*cdf0e10cSrcweir                     createTextPrimitive(
104*cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
105*cdf0e10cSrcweir                         getTransform(),
106*cdf0e10cSrcweir                         getSdrLFSTAttribute().getText(),
107*cdf0e10cSrcweir                         getSdrLFSTAttribute().getLine(),
108*cdf0e10cSrcweir                         false,
109*cdf0e10cSrcweir                         false,
110*cdf0e10cSrcweir                         false));
111*cdf0e10cSrcweir 			}
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 			// add shadow
114*cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getShadow().isDefault())
115*cdf0e10cSrcweir 			{
116*cdf0e10cSrcweir                 aRetval = createEmbeddedShadowPrimitive(
117*cdf0e10cSrcweir                     aRetval,
118*cdf0e10cSrcweir                     getSdrLFSTAttribute().getShadow());
119*cdf0e10cSrcweir 			}
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 			return aRetval;
122*cdf0e10cSrcweir 		}
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 		SdrRectanglePrimitive2D::SdrRectanglePrimitive2D(
125*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rTransform,
126*cdf0e10cSrcweir 			const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
127*cdf0e10cSrcweir 			double fCornerRadiusX,
128*cdf0e10cSrcweir 			double fCornerRadiusY,
129*cdf0e10cSrcweir             bool bForceFillForHitTest)
130*cdf0e10cSrcweir 		:	BufferedDecompositionPrimitive2D(),
131*cdf0e10cSrcweir 			maTransform(rTransform),
132*cdf0e10cSrcweir 			maSdrLFSTAttribute(rSdrLFSTAttribute),
133*cdf0e10cSrcweir 			mfCornerRadiusX(fCornerRadiusX),
134*cdf0e10cSrcweir 			mfCornerRadiusY(fCornerRadiusY),
135*cdf0e10cSrcweir             mbForceFillForHitTest(bForceFillForHitTest)
136*cdf0e10cSrcweir 		{
137*cdf0e10cSrcweir 		}
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 		bool SdrRectanglePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
140*cdf0e10cSrcweir 		{
141*cdf0e10cSrcweir 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
142*cdf0e10cSrcweir 			{
143*cdf0e10cSrcweir 				const SdrRectanglePrimitive2D& rCompare = (SdrRectanglePrimitive2D&)rPrimitive;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 				return (getCornerRadiusX() == rCompare.getCornerRadiusX()
146*cdf0e10cSrcweir 					&& getCornerRadiusY() == rCompare.getCornerRadiusY()
147*cdf0e10cSrcweir 					&& getTransform() == rCompare.getTransform()
148*cdf0e10cSrcweir 					&& getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
149*cdf0e10cSrcweir                     && getForceFillForHitTest() == rCompare.getForceFillForHitTest());
150*cdf0e10cSrcweir 			}
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 			return false;
153*cdf0e10cSrcweir 		}
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 		// provide unique ID
156*cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(SdrRectanglePrimitive2D, PRIMITIVE2D_ID_SDRRECTANGLEPRIMITIVE2D)
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	} // end of namespace primitive2d
159*cdf0e10cSrcweir } // end of namespace drawinglayer
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
162*cdf0e10cSrcweir // eof
163