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/sdrcaptionprimitive2d.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 
32 //////////////////////////////////////////////////////////////////////////////
33 
34 using namespace com::sun::star;
35 
36 //////////////////////////////////////////////////////////////////////////////
37 
38 namespace drawinglayer
39 {
40 	namespace primitive2d
41 	{
create2DDecomposition(const geometry::ViewInformation2D &) const42 		Primitive2DSequence SdrCaptionPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
43 		{
44 			Primitive2DSequence aRetval;
45 
46 			// create unit outline polygon
47 			const basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(
48                 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
49                 getCornerRadiusX(),
50                 getCornerRadiusY()));
51 
52 			// add fill
53 			if(getSdrLFSTAttribute().getFill().isDefault())
54 			{
55 				// create invisible fill for HitTest
56 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
57 					createHiddenGeometryPrimitives2D(
58 						true,
59 						basegfx::B2DPolyPolygon(aUnitOutline),
60 						getTransform()));
61 			}
62 			else
63 			{
64 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
65                     createPolyPolygonFillPrimitive(
66                         basegfx::B2DPolyPolygon(aUnitOutline),
67                         getTransform(),
68                         getSdrLFSTAttribute().getFill(),
69                         getSdrLFSTAttribute().getFillFloatTransGradient()));
70 			}
71 
72 			// add line
73 			if(getSdrLFSTAttribute().getLine().isDefault())
74 			{
75 				// create invisible line for HitTest/BoundRect
76 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
77 					createHiddenGeometryPrimitives2D(
78                         false,
79 						basegfx::B2DPolyPolygon(aUnitOutline),
80                         getTransform()));
81 
82 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
83 					createHiddenGeometryPrimitives2D(
84                         false,
85 						basegfx::B2DPolyPolygon(getTail()),
86                         getTransform()));
87 			}
88 			else
89 			{
90 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
91                     createPolygonLinePrimitive(
92                         aUnitOutline,
93                         getTransform(),
94                         getSdrLFSTAttribute().getLine(),
95 						attribute::SdrLineStartEndAttribute()));
96 
97                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
98                     createPolygonLinePrimitive(
99                         getTail(),
100                         getTransform(),
101                         getSdrLFSTAttribute().getLine(),
102                         getSdrLFSTAttribute().getLineStartEnd()));
103 			}
104 
105 			// add text
106 			if(!getSdrLFSTAttribute().getText().isDefault())
107 			{
108 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
109                     createTextPrimitive(
110                         basegfx::B2DPolyPolygon(aUnitOutline),
111                         getTransform(),
112                         getSdrLFSTAttribute().getText(),
113                         getSdrLFSTAttribute().getLine(),
114                         false,
115                         false,
116 						false));
117 			}
118 
119 			// add shadow
120 			if(!getSdrLFSTAttribute().getShadow().isDefault())
121 			{
122                 aRetval = createEmbeddedShadowPrimitive(aRetval, getSdrLFSTAttribute().getShadow());
123 			}
124 
125 			return aRetval;
126 		}
127 
SdrCaptionPrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute,const basegfx::B2DPolygon & rTail,double fCornerRadiusX,double fCornerRadiusY)128 		SdrCaptionPrimitive2D::SdrCaptionPrimitive2D(
129 			const basegfx::B2DHomMatrix& rTransform,
130 			const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
131 			const basegfx::B2DPolygon& rTail,
132 			double fCornerRadiusX,
133 			double fCornerRadiusY)
134 		:	BufferedDecompositionPrimitive2D(),
135 			maTransform(rTransform),
136 			maSdrLFSTAttribute(rSdrLFSTAttribute),
137 			maTail(rTail),
138 			mfCornerRadiusX(fCornerRadiusX),
139 			mfCornerRadiusY(fCornerRadiusY)
140 		{
141 			// transform maTail to unit polygon
142 			if(getTail().count())
143 			{
144 				basegfx::B2DHomMatrix aInverse(getTransform());
145 				aInverse.invert();
146 				maTail.transform(aInverse);
147 			}
148 		}
149 
operator ==(const BasePrimitive2D & rPrimitive) const150 		bool SdrCaptionPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
151 		{
152 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
153 			{
154 				const SdrCaptionPrimitive2D& rCompare = (SdrCaptionPrimitive2D&)rPrimitive;
155 
156 				return (getCornerRadiusX() == rCompare.getCornerRadiusX()
157 					&& getCornerRadiusY() == rCompare.getCornerRadiusY()
158 					&& getTail() == rCompare.getTail()
159 					&& getTransform() == rCompare.getTransform()
160 					&& getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute());
161 			}
162 
163 			return false;
164 		}
165 
166 		// provide unique ID
167 		ImplPrimitrive2DIDBlock(SdrCaptionPrimitive2D, PRIMITIVE2D_ID_SDRCAPTIONPRIMITIVE2D)
168 
169 	} // end of namespace primitive2d
170 } // end of namespace drawinglayer
171 
172 //////////////////////////////////////////////////////////////////////////////
173 // eof
174