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/sdrcustomshapeprimitive2d.hxx>
30 #include <basegfx/polygon/b2dpolygon.hxx>
31 #include <basegfx/polygon/b2dpolygontools.hxx>
32 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
33 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
34 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
35 #include <drawinglayer/attribute/sdrlineattribute.hxx>
36 
37 //////////////////////////////////////////////////////////////////////////////
38 
39 using namespace com::sun::star;
40 
41 //////////////////////////////////////////////////////////////////////////////
42 
43 namespace drawinglayer
44 {
45 	namespace primitive2d
46 	{
47 		Primitive2DSequence SdrCustomShapePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
48 		{
49 			Primitive2DSequence aRetval(getSubPrimitives());
50 
51 			// add text
52 			if(!getSdrSTAttribute().getText().isDefault())
53 			{
54 				const basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon());
55 
56                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
57                     createTextPrimitive(
58                         basegfx::B2DPolyPolygon(aUnitOutline),
59 					    getTextBox(),
60 					    getSdrSTAttribute().getText(),
61 						attribute::SdrLineAttribute(),
62 					    false,
63 					    getWordWrap(),
64 					    isForceTextClipToTextRange()));
65 			}
66 
67 			// add shadow
68 			if(aRetval.hasElements() && !getSdrSTAttribute().getShadow().isDefault())
69 			{
70 				// #i105323# add generic shadow only for 2D shapes. For
71 				// 3D shapes shadow will be set at the individual created
72 				// visualisation objects and be visualized by the 3d renderer
73 				// as a single shadow.
74 				//
75 				// The shadow for AutoShapes could be handled uniformely by not setting any
76 				// shadow items at the helper model objects and only adding shadow here for
77 				// 2D and 3D (and it works, too), but this would lead to two 3D scenes for
78 				// the 3D object; one for the shadow aond one for the content. The one for the
79 				// shadow will be correct (using ColorModifierStack), but expensive.
80 				if(!get3DShape())
81 				{
82 	                aRetval = createEmbeddedShadowPrimitive(aRetval, getSdrSTAttribute().getShadow());
83 				}
84 			}
85 
86 			return aRetval;
87 		}
88 
89 		SdrCustomShapePrimitive2D::SdrCustomShapePrimitive2D(
90 			const attribute::SdrShadowTextAttribute& rSdrSTAttribute,
91 			const Primitive2DSequence& rSubPrimitives,
92 			const basegfx::B2DHomMatrix& rTextBox,
93             bool bWordWrap,
94 			bool b3DShape,
95 			bool bForceTextClipToTextRange)
96 		:	BufferedDecompositionPrimitive2D(),
97 			maSdrSTAttribute(rSdrSTAttribute),
98 			maSubPrimitives(rSubPrimitives),
99 			maTextBox(rTextBox),
100             mbWordWrap(bWordWrap),
101 			mb3DShape(b3DShape),
102 			mbForceTextClipToTextRange(bForceTextClipToTextRange)
103 		{
104 		}
105 
106 		bool SdrCustomShapePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
107 		{
108 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
109 			{
110 				const SdrCustomShapePrimitive2D& rCompare = (SdrCustomShapePrimitive2D&)rPrimitive;
111 
112 				return (getSdrSTAttribute() == rCompare.getSdrSTAttribute()
113 					&& getSubPrimitives() == rCompare.getSubPrimitives()
114 					&& getTextBox() == rCompare.getTextBox()
115                     && getWordWrap() == rCompare.getWordWrap()
116 					&& get3DShape() == rCompare.get3DShape()
117 					&& isForceTextClipToTextRange() == rCompare.isForceTextClipToTextRange());
118 			}
119 
120 			return false;
121 		}
122 
123 		// provide unique ID
124 		ImplPrimitrive2DIDBlock(SdrCustomShapePrimitive2D, PRIMITIVE2D_ID_SDRCUSTOMSHAPEPRIMITIVE2D)
125 
126 	} // end of namespace primitive2d
127 } // end of namespace drawinglayer
128 
129 //////////////////////////////////////////////////////////////////////////////
130 // eof
131