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