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/sdrgrafprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
27 #include <basegfx/polygon/b2dpolygontools.hxx>
28 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
29 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
30 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
31 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
32 #include <basegfx/polygon/b2dpolygon.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 namespace drawinglayer
37 {
38 	namespace primitive2d
39 	{
40 		Primitive2DSequence SdrGrafPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
41 		{
42 			Primitive2DSequence  aRetval;
43 
44 			// create unit outline polygon
45 			basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon());
46 
47 			// add fill, but only when graphic ist transparent
48 			if(!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
49 			{
50 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
51 					createPolyPolygonFillPrimitive(
52                         basegfx::B2DPolyPolygon(aUnitOutline),
53                         getTransform(),
54                         getSdrLFSTAttribute().getFill(),
55                         getSdrLFSTAttribute().getFillFloatTransGradient()));
56 			}
57 
58 			// add line
59 			if(!getSdrLFSTAttribute().getLine().isDefault())
60 			{
61 				// if line width is given, polygon needs to be grown by half of it to make the
62 				// outline to be outside of the bitmap
63 				if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
64 				{
65 					// decompose to get scale
66 					basegfx::B2DVector aScale, aTranslate;
67 					double fRotate, fShearX;
68 					getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
69 
70 					// create expanded range (add relative half line width to unit rectangle)
71 					double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
72 					double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
73 					double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
74 					const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
75 					basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange));
76 
77 					appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
78                         createPolygonLinePrimitive(
79                             aExpandedUnitOutline,
80                             getTransform(),
81                             getSdrLFSTAttribute().getLine(),
82 							attribute::SdrLineStartEndAttribute()));
83 				}
84 				else
85 				{
86 					appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
87                         createPolygonLinePrimitive(
88                             aUnitOutline, getTransform(),
89                             getSdrLFSTAttribute().getLine(),
90 							attribute::SdrLineStartEndAttribute()));
91 				}
92 			}
93 
94 			// add graphic content
95 			if(255L != getGraphicAttr().GetTransparency())
96 			{
97 				const Primitive2DReference xGraphicContentPrimitive(
98                     new GraphicPrimitive2D(
99                         getTransform(),
100                         getGraphicObject(),
101                         getGraphicAttr()));
102 
103                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive);
104 			}
105 
106 			// add text
107 			if(!getSdrLFSTAttribute().getText().isDefault())
108 			{
109 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
110                     createTextPrimitive(
111                         basegfx::B2DPolyPolygon(aUnitOutline),
112                         getTransform(),
113 						getSdrLFSTAttribute().getText(),
114                         getSdrLFSTAttribute().getLine(),
115                         false,
116                         false,
117                         false));
118 			}
119 
120 			// add shadow
121 			if(!getSdrLFSTAttribute().getShadow().isDefault())
122 			{
123                 aRetval = createEmbeddedShadowPrimitive(
124                     aRetval,
125                     getSdrLFSTAttribute().getShadow());
126 			}
127 
128 			return aRetval;
129 		}
130 
131 		SdrGrafPrimitive2D::SdrGrafPrimitive2D(
132 			const basegfx::B2DHomMatrix& rTransform,
133 			const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
134 			const GraphicObject& rGraphicObject,
135 			const GraphicAttr& rGraphicAttr)
136 		:	BufferedDecompositionPrimitive2D(),
137 			maTransform(rTransform),
138 			maSdrLFSTAttribute(rSdrLFSTAttribute),
139 			maGraphicObject(rGraphicObject),
140 			maGraphicAttr(rGraphicAttr)
141 		{
142 			// reset some values from GraphicAttr which are part of transformation already
143 			maGraphicAttr.SetRotation(0L);
144 		}
145 
146 		bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
147 		{
148 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
149 			{
150 				const SdrGrafPrimitive2D& rCompare = (SdrGrafPrimitive2D&)rPrimitive;
151 
152 				return (getTransform() == rCompare.getTransform()
153 					&& getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
154 					&& getGraphicObject() == rCompare.getGraphicObject()
155 					&& getGraphicAttr() == rCompare.getGraphicAttr());
156 			}
157 
158 			return false;
159 		}
160 
161 		bool SdrGrafPrimitive2D::isTransparent() const
162 		{
163 			return ((0L != getGraphicAttr().GetTransparency()) || (getGraphicObject().IsTransparent()));
164 		}
165 
166 		// provide unique ID
167 		ImplPrimitrive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D)
168 
169 	} // end of namespace primitive2d
170 } // end of namespace drawinglayer
171 
172 //////////////////////////////////////////////////////////////////////////////
173 // eof
174