1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22cdf0e10cSrcweir #include "precompiled_svx.hxx"
23cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrgrafprimitive2d.hxx>
24cdf0e10cSrcweir #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
25cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
26cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
27cdf0e10cSrcweir #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
28cdf0e10cSrcweir #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
30cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
31ddde725dSArmin Le Grand #include <basegfx/matrix/b2dhommatrixtools.hxx>
32ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace drawinglayer
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	namespace primitive2d
39cdf0e10cSrcweir 	{
create2DDecomposition(const geometry::ViewInformation2D &) const40cdf0e10cSrcweir 		Primitive2DSequence SdrGrafPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
41cdf0e10cSrcweir 		{
42cdf0e10cSrcweir 			Primitive2DSequence  aRetval;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 			// create unit outline polygon
45cdf0e10cSrcweir 			basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon());
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 			// add fill, but only when graphic ist transparent
48cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
49cdf0e10cSrcweir 			{
50cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
51cdf0e10cSrcweir 					createPolyPolygonFillPrimitive(
52cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
53cdf0e10cSrcweir                         getTransform(),
54cdf0e10cSrcweir                         getSdrLFSTAttribute().getFill(),
55cdf0e10cSrcweir                         getSdrLFSTAttribute().getFillFloatTransGradient()));
56cdf0e10cSrcweir 			}
57cdf0e10cSrcweir 
58*025b0597SArmin Le Grand 			// add graphic content
59*025b0597SArmin Le Grand 			if(255L != getGraphicAttr().GetTransparency())
60*025b0597SArmin Le Grand 			{
61*025b0597SArmin Le Grand                 // standard graphic fill
62*025b0597SArmin Le Grand                 const Primitive2DReference xGraphicContentPrimitive(
63*025b0597SArmin Le Grand                     new GraphicPrimitive2D(
64*025b0597SArmin Le Grand                         getTransform(),
65*025b0597SArmin Le Grand                         getGraphicObject(),
66*025b0597SArmin Le Grand                         getGraphicAttr()));
67*025b0597SArmin Le Grand 
68*025b0597SArmin Le Grand                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive);
69*025b0597SArmin Le Grand 			}
70*025b0597SArmin Le Grand 
71cdf0e10cSrcweir 			// add line
72cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getLine().isDefault())
73cdf0e10cSrcweir 			{
74cdf0e10cSrcweir 				// if line width is given, polygon needs to be grown by half of it to make the
75cdf0e10cSrcweir 				// outline to be outside of the bitmap
76cdf0e10cSrcweir 				if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
77cdf0e10cSrcweir 				{
78cdf0e10cSrcweir 					// decompose to get scale
79cdf0e10cSrcweir 					basegfx::B2DVector aScale, aTranslate;
80cdf0e10cSrcweir 					double fRotate, fShearX;
81cdf0e10cSrcweir 					getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 					// create expanded range (add relative half line width to unit rectangle)
84cdf0e10cSrcweir 					double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
85cdf0e10cSrcweir 					double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
86cdf0e10cSrcweir 					double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
87cdf0e10cSrcweir 					const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
88cdf0e10cSrcweir 					basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange));
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 					appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
91cdf0e10cSrcweir                         createPolygonLinePrimitive(
92cdf0e10cSrcweir                             aExpandedUnitOutline,
93cdf0e10cSrcweir                             getTransform(),
94cdf0e10cSrcweir                             getSdrLFSTAttribute().getLine(),
95cdf0e10cSrcweir 							attribute::SdrLineStartEndAttribute()));
96cdf0e10cSrcweir 				}
97cdf0e10cSrcweir 				else
98cdf0e10cSrcweir 				{
99cdf0e10cSrcweir 					appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
100cdf0e10cSrcweir                         createPolygonLinePrimitive(
101cdf0e10cSrcweir                             aUnitOutline, getTransform(),
102cdf0e10cSrcweir                             getSdrLFSTAttribute().getLine(),
103cdf0e10cSrcweir 							attribute::SdrLineStartEndAttribute()));
104cdf0e10cSrcweir 				}
105cdf0e10cSrcweir 			}
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 			// add text
108cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getText().isDefault())
109cdf0e10cSrcweir 			{
110cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
111cdf0e10cSrcweir                     createTextPrimitive(
112cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
113cdf0e10cSrcweir                         getTransform(),
114cdf0e10cSrcweir 						getSdrLFSTAttribute().getText(),
115cdf0e10cSrcweir                         getSdrLFSTAttribute().getLine(),
116cdf0e10cSrcweir                         false,
117cdf0e10cSrcweir                         false,
118cdf0e10cSrcweir                         false));
119cdf0e10cSrcweir 			}
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 			// add shadow
122cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getShadow().isDefault())
123cdf0e10cSrcweir 			{
124cdf0e10cSrcweir                 aRetval = createEmbeddedShadowPrimitive(
125cdf0e10cSrcweir                     aRetval,
126cdf0e10cSrcweir                     getSdrLFSTAttribute().getShadow());
127cdf0e10cSrcweir 			}
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 			return aRetval;
130cdf0e10cSrcweir 		}
131cdf0e10cSrcweir 
SdrGrafPrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute,const GraphicObject & rGraphicObject,const GraphicAttr & rGraphicAttr)132cdf0e10cSrcweir 		SdrGrafPrimitive2D::SdrGrafPrimitive2D(
133cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rTransform,
134cdf0e10cSrcweir 			const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
135cdf0e10cSrcweir 			const GraphicObject& rGraphicObject,
136cdf0e10cSrcweir 			const GraphicAttr& rGraphicAttr)
137cdf0e10cSrcweir 		:	BufferedDecompositionPrimitive2D(),
138cdf0e10cSrcweir 			maTransform(rTransform),
139cdf0e10cSrcweir 			maSdrLFSTAttribute(rSdrLFSTAttribute),
140cdf0e10cSrcweir 			maGraphicObject(rGraphicObject),
141cdf0e10cSrcweir 			maGraphicAttr(rGraphicAttr)
142cdf0e10cSrcweir 		{
143cdf0e10cSrcweir 			// reset some values from GraphicAttr which are part of transformation already
144cdf0e10cSrcweir 			maGraphicAttr.SetRotation(0L);
145cdf0e10cSrcweir 		}
146cdf0e10cSrcweir 
operator ==(const BasePrimitive2D & rPrimitive) const147cdf0e10cSrcweir 		bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
148cdf0e10cSrcweir 		{
149cdf0e10cSrcweir 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
150cdf0e10cSrcweir 			{
151cdf0e10cSrcweir 				const SdrGrafPrimitive2D& rCompare = (SdrGrafPrimitive2D&)rPrimitive;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 				return (getTransform() == rCompare.getTransform()
154cdf0e10cSrcweir 					&& getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
155cdf0e10cSrcweir 					&& getGraphicObject() == rCompare.getGraphicObject()
156cdf0e10cSrcweir 					&& getGraphicAttr() == rCompare.getGraphicAttr());
157cdf0e10cSrcweir 			}
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 			return false;
160cdf0e10cSrcweir 		}
161cdf0e10cSrcweir 
isTransparent() const162cdf0e10cSrcweir 		bool SdrGrafPrimitive2D::isTransparent() const
163cdf0e10cSrcweir 		{
164ddde725dSArmin Le Grand 			return ((0L != getGraphicAttr().GetTransparency())
165ddde725dSArmin Le Grand                 || (getGraphicObject().IsTransparent()));
166cdf0e10cSrcweir 		}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 		// provide unique ID
169cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D)
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 	} // end of namespace primitive2d
172cdf0e10cSrcweir } // end of namespace drawinglayer
173cdf0e10cSrcweir 
174cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
175cdf0e10cSrcweir // eof
176