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