xref: /trunk/main/svx/source/sdr/primitive2d/sdrole2primitive2d.cxx (revision 61dff127b6698e0bae836c8aedd6ec62111483d1)
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/sdrole2primitive2d.hxx>
30 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
31 #include <basegfx/polygon/b2dpolygontools.hxx>
32 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
33 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
34 #include <basegfx/polygon/b2dpolygon.hxx>
35 
36 //////////////////////////////////////////////////////////////////////////////
37 
38 using namespace com::sun::star;
39 
40 //////////////////////////////////////////////////////////////////////////////
41 
42 namespace drawinglayer
43 {
44     namespace primitive2d
45     {
46         SdrOle2Primitive2D::SdrOle2Primitive2D(
47             const Primitive2DSequence& rOLEContent,
48             const basegfx::B2DHomMatrix& rTransform,
49             const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute)
50         :   BasePrimitive2D(),
51             maOLEContent(rOLEContent),
52             maTransform(rTransform),
53             maSdrLFSTAttribute(rSdrLFSTAttribute)
54         {
55         }
56 
57         bool SdrOle2Primitive2D::operator==(const BasePrimitive2D& rPrimitive) const
58         {
59             if(BasePrimitive2D::operator==(rPrimitive))
60             {
61                 const SdrOle2Primitive2D& rCompare = (SdrOle2Primitive2D&)rPrimitive;
62 
63                 // #i108636# The standard operator== on two UNO sequences did not work as i
64                 // would have expected; it just checks the .is() states and the data type
65                 // of the sequence. What i need here is detection of equality of the whole
66                 // sequence content, thus i need to use the arePrimitive2DSequencesEqual helper
67                 // here instead of the operator== which lead to always returning false and thus
68                 // always re-decompositions of the subcontent.
69                 if(arePrimitive2DSequencesEqual(getOLEContent(), rCompare.getOLEContent())
70                     && getTransform() == rCompare.getTransform()
71                     && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute())
72                 {
73                     return true;
74                 }
75             }
76 
77             return false;
78         }
79 
80         Primitive2DSequence SdrOle2Primitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
81         {
82             // to take care of getSdrLFSTAttribute() later, the same as in SdrGrafPrimitive2D::create2DDecomposition
83             // should happen. For the moment we only need the OLE itself
84             // Added complete primitive preparation using getSdrLFSTAttribute() now. To not do stuff which is not needed now, it
85             // may be supressed by using a static bool. The paint version only supported text.
86             static bool bBehaveCompatibleToPaintVersion(false);
87             Primitive2DSequence  aRetval;
88 
89             // create unit outline polygon
90             const basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon());
91 
92             // add fill
93             if(!bBehaveCompatibleToPaintVersion
94                 && !getSdrLFSTAttribute().getFill().isDefault())
95             {
96                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
97                     createPolyPolygonFillPrimitive(
98                         basegfx::B2DPolyPolygon(aUnitOutline),
99                         getTransform(),
100                         getSdrLFSTAttribute().getFill(),
101                         getSdrLFSTAttribute().getFillFloatTransGradient()));
102             }
103 
104             // add line
105             // #i97981# condition was inverse to purpose. When being compatible to paint version,
106             // border needs to be suppressed
107             if(!bBehaveCompatibleToPaintVersion
108                 && !getSdrLFSTAttribute().getLine().isDefault())
109             {
110                 // if line width is given, polygon needs to be grown by half of it to make the
111                 // outline to be outside of the bitmap
112                 if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
113                 {
114                     // decompose to get scale
115                     basegfx::B2DVector aScale, aTranslate;
116                     double fRotate, fShearX;
117                     getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
118 
119                     // create expanded range (add relative half line width to unit rectangle)
120                     double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
121                     double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
122                     double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
123                     const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
124                     basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange));
125 
126                     appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
127                         createPolygonLinePrimitive(
128                             aExpandedUnitOutline,
129                             getTransform(),
130                             getSdrLFSTAttribute().getLine(),
131                             attribute::SdrLineStartEndAttribute()));
132                 }
133                 else
134                 {
135                     appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
136                         createPolygonLinePrimitive(
137                             aUnitOutline,
138                             getTransform(),
139                             getSdrLFSTAttribute().getLine(),
140                             attribute::SdrLineStartEndAttribute()));
141                 }
142             }
143             else
144             {
145                 // if initially no line is defined, create one for HitTest and BoundRect
146                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
147                     createHiddenGeometryPrimitives2D(
148                         false,
149                         basegfx::B2DPolyPolygon(aUnitOutline),
150                         getTransform()));
151             }
152 
153             // add graphic content
154             appendPrimitive2DSequenceToPrimitive2DSequence(aRetval, getOLEContent());
155 
156             // add text, no need to supress to stay compatible since text was
157             // always supported by the old paints, too
158             if(!getSdrLFSTAttribute().getText().isDefault())
159             {
160                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
161                     createTextPrimitive(
162                         basegfx::B2DPolyPolygon(aUnitOutline),
163                         getTransform(),
164                         getSdrLFSTAttribute().getText(),
165                         getSdrLFSTAttribute().getLine(),
166                         false,
167                         false,
168                         false));
169             }
170 
171             // add shadow
172             if(!bBehaveCompatibleToPaintVersion
173                 && !getSdrLFSTAttribute().getShadow().isDefault())
174             {
175                 aRetval = createEmbeddedShadowPrimitive(
176                     aRetval,
177                     getSdrLFSTAttribute().getShadow());
178             }
179 
180             return aRetval;
181         }
182 
183         // provide unique ID
184         ImplPrimitrive2DIDBlock(SdrOle2Primitive2D, PRIMITIVE2D_ID_SDROLE2PRIMITIVE2D)
185 
186     } // end of namespace primitive2d
187 } // end of namespace drawinglayer
188 
189 //////////////////////////////////////////////////////////////////////////////
190 // eof
191