1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_svx.hxx"
25 #include <svx/sdr/primitive2d/sdrrectangleprimitive2d.hxx>
26 #include <basegfx/polygon/b2dpolygontools.hxx>
27 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
28 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
29 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
30 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
31 #include <basegfx/polygon/b2dpolygon.hxx>
32 
33 //////////////////////////////////////////////////////////////////////////////
34 
35 using namespace com::sun::star;
36 
37 //////////////////////////////////////////////////////////////////////////////
38 
39 namespace drawinglayer
40 {
41 	namespace primitive2d
42 	{
create2DDecomposition(const geometry::ViewInformation2D &) const43 		Primitive2DSequence SdrRectanglePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
44 		{
45 			Primitive2DSequence aRetval;
46 
47 			// create unit outline polygon
48 			const basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(
49                 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
50                 getCornerRadiusX(),
51                 getCornerRadiusY()));
52 
53 			// add fill
54 			if(!getSdrLFSTAttribute().getFill().isDefault())
55 			{
56 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
57                     createPolyPolygonFillPrimitive(
58                         basegfx::B2DPolyPolygon(aUnitOutline),
59                         getTransform(),
60                         getSdrLFSTAttribute().getFill(),
61                         getSdrLFSTAttribute().getFillFloatTransGradient()));
62 			}
63             else if(getForceFillForHitTest())
64             {
65                 // if no fill and it's a text frame, create a fill for HitTest and
66                 // BoundRect fallback
67                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
68                     createHiddenGeometryPrimitives2D(
69                         true,
70                         basegfx::B2DPolyPolygon(aUnitOutline),
71                         getTransform()));
72             }
73 
74 			// add line
75 			if(!getSdrLFSTAttribute().getLine().isDefault())
76 			{
77 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
78                     createPolygonLinePrimitive(
79                         aUnitOutline,
80                         getTransform(),
81                         getSdrLFSTAttribute().getLine(),
82 						attribute::SdrLineStartEndAttribute()));
83 			}
84             else if(!getForceFillForHitTest())
85             {
86                 // if initially no line is defined and it's not a text frame, create
87                 // a line for HitTest and BoundRect
88                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
89                     createHiddenGeometryPrimitives2D(
90                         false,
91                         basegfx::B2DPolyPolygon(aUnitOutline),
92                         getTransform()));
93             }
94 
95             // add text
96 			if(!getSdrLFSTAttribute().getText().isDefault())
97 			{
98 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
99                     createTextPrimitive(
100                         basegfx::B2DPolyPolygon(aUnitOutline),
101                         getTransform(),
102                         getSdrLFSTAttribute().getText(),
103                         getSdrLFSTAttribute().getLine(),
104                         false,
105                         false,
106                         false));
107 			}
108 
109 			// add shadow
110 			if(!getSdrLFSTAttribute().getShadow().isDefault())
111 			{
112                 aRetval = createEmbeddedShadowPrimitive(
113                     aRetval,
114                     getSdrLFSTAttribute().getShadow());
115 			}
116 
117 			return aRetval;
118 		}
119 
SdrRectanglePrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute,double fCornerRadiusX,double fCornerRadiusY,bool bForceFillForHitTest)120 		SdrRectanglePrimitive2D::SdrRectanglePrimitive2D(
121 			const basegfx::B2DHomMatrix& rTransform,
122 			const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
123 			double fCornerRadiusX,
124 			double fCornerRadiusY,
125             bool bForceFillForHitTest)
126 		:	BufferedDecompositionPrimitive2D(),
127 			maTransform(rTransform),
128 			maSdrLFSTAttribute(rSdrLFSTAttribute),
129 			mfCornerRadiusX(fCornerRadiusX),
130 			mfCornerRadiusY(fCornerRadiusY),
131             mbForceFillForHitTest(bForceFillForHitTest)
132 		{
133 		}
134 
operator ==(const BasePrimitive2D & rPrimitive) const135 		bool SdrRectanglePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
136 		{
137 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
138 			{
139 				const SdrRectanglePrimitive2D& rCompare = (SdrRectanglePrimitive2D&)rPrimitive;
140 
141 				return (getCornerRadiusX() == rCompare.getCornerRadiusX()
142 					&& getCornerRadiusY() == rCompare.getCornerRadiusY()
143 					&& getTransform() == rCompare.getTransform()
144 					&& getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
145                     && getForceFillForHitTest() == rCompare.getForceFillForHitTest());
146 			}
147 
148 			return false;
149 		}
150 
151 		// provide unique ID
152 		ImplPrimitrive2DIDBlock(SdrRectanglePrimitive2D, PRIMITIVE2D_ID_SDRRECTANGLEPRIMITIVE2D)
153 
154 	} // end of namespace primitive2d
155 } // end of namespace drawinglayer
156 
157 //////////////////////////////////////////////////////////////////////////////
158 // eof
159