1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/sdr/primitive2d/sdrole2primitive2d.hxx>
21 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
24 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
27 //////////////////////////////////////////////////////////////////////////////
29 using namespace com::sun::star
;
31 //////////////////////////////////////////////////////////////////////////////
33 namespace drawinglayer
37 SdrOle2Primitive2D::SdrOle2Primitive2D(
38 const Primitive2DSequence
& rOLEContent
,
39 const basegfx::B2DHomMatrix
& rTransform
,
40 const attribute::SdrLineFillShadowTextAttribute
& rSdrLFSTAttribute
)
42 maOLEContent(rOLEContent
),
43 maTransform(rTransform
),
44 maSdrLFSTAttribute(rSdrLFSTAttribute
)
48 bool SdrOle2Primitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
50 if(BasePrimitive2D::operator==(rPrimitive
))
52 const SdrOle2Primitive2D
& rCompare
= (SdrOle2Primitive2D
&)rPrimitive
;
54 // #i108636# The standard operator== on two UNO sequences did not work as i
55 // would have expected; it just checks the .is() states and the data type
56 // of the sequence. What i need here is detection of equality of the whole
57 // sequence content, thus i need to use the arePrimitive2DSequencesEqual helper
58 // here instead of the operator== which lead to always returning false and thus
59 // always re-decompositions of the subcontent.
60 if(arePrimitive2DSequencesEqual(getOLEContent(), rCompare
.getOLEContent())
61 && getTransform() == rCompare
.getTransform()
62 && getSdrLFSTAttribute() == rCompare
.getSdrLFSTAttribute())
71 Primitive2DSequence
SdrOle2Primitive2D::get2DDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
73 // to take care of getSdrLFSTAttribute() later, the same as in SdrGrafPrimitive2D::create2DDecomposition
74 // should happen. For the moment we only need the OLE itself
75 // Added complete primitive preparation using getSdrLFSTAttribute() now. To not do stuff which is not needed now, it
76 // may be supressed by using a static bool. The paint version only supported text.
77 static bool bBehaveCompatibleToPaintVersion(false);
78 Primitive2DSequence aRetval
;
80 // create unit outline polygon
81 const basegfx::B2DPolygon
aUnitOutline(basegfx::tools::createUnitPolygon());
84 if(!bBehaveCompatibleToPaintVersion
85 && !getSdrLFSTAttribute().getFill().isDefault())
87 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
88 createPolyPolygonFillPrimitive(
89 basegfx::B2DPolyPolygon(aUnitOutline
),
91 getSdrLFSTAttribute().getFill(),
92 getSdrLFSTAttribute().getFillFloatTransGradient()));
96 // #i97981# condition was inverse to purpose. When being compatible to paint version,
97 // border needs to be suppressed
98 if(!bBehaveCompatibleToPaintVersion
99 && !getSdrLFSTAttribute().getLine().isDefault())
101 // if line width is given, polygon needs to be grown by half of it to make the
102 // outline to be outside of the bitmap
103 if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
105 // decompose to get scale
106 basegfx::B2DVector aScale
, aTranslate
;
107 double fRotate
, fShearX
;
108 getTransform().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
110 // create expanded range (add relative half line width to unit rectangle)
111 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
112 double fScaleX(0.0 != aScale
.getX() ? fHalfLineWidth
/ fabs(aScale
.getX()) : 1.0);
113 double fScaleY(0.0 != aScale
.getY() ? fHalfLineWidth
/ fabs(aScale
.getY()) : 1.0);
114 const basegfx::B2DRange
aExpandedRange(-fScaleX
, -fScaleY
, 1.0 + fScaleX
, 1.0 + fScaleY
);
115 basegfx::B2DPolygon
aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange
));
117 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
118 createPolygonLinePrimitive(
119 aExpandedUnitOutline
,
121 getSdrLFSTAttribute().getLine(),
122 attribute::SdrLineStartEndAttribute()));
126 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
127 createPolygonLinePrimitive(
130 getSdrLFSTAttribute().getLine(),
131 attribute::SdrLineStartEndAttribute()));
136 // if initially no line is defined, create one for HitTest and BoundRect
137 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
138 createHiddenGeometryPrimitives2D(
140 basegfx::B2DPolyPolygon(aUnitOutline
),
144 // add graphic content
145 appendPrimitive2DSequenceToPrimitive2DSequence(aRetval
, getOLEContent());
147 // add text, no need to supress to stay compatible since text was
148 // always supported by the old paints, too
149 if(!getSdrLFSTAttribute().getText().isDefault())
151 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
153 basegfx::B2DPolyPolygon(aUnitOutline
),
155 getSdrLFSTAttribute().getText(),
156 getSdrLFSTAttribute().getLine(),
163 if(!bBehaveCompatibleToPaintVersion
164 && !getSdrLFSTAttribute().getShadow().isDefault())
166 aRetval
= createEmbeddedShadowPrimitive(
168 getSdrLFSTAttribute().getShadow());
175 ImplPrimitive2DIDBlock(SdrOle2Primitive2D
, PRIMITIVE2D_ID_SDROLE2PRIMITIVE2D
)
177 } // end of namespace primitive2d
178 } // end of namespace drawinglayer
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */