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 <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>
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
29 using namespace com::sun::star
;
32 namespace drawinglayer
36 SdrOle2Primitive2D::SdrOle2Primitive2D(
37 const Primitive2DContainer
& rOLEContent
,
38 const basegfx::B2DHomMatrix
& rTransform
,
39 const attribute::SdrLineFillShadowTextAttribute
& rSdrLFSTAttribute
)
41 maOLEContent(rOLEContent
),
42 maTransform(rTransform
),
43 maSdrLFSTAttribute(rSdrLFSTAttribute
)
47 bool SdrOle2Primitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
49 if(BasePrimitive2D::operator==(rPrimitive
))
51 const SdrOle2Primitive2D
& rCompare
= static_cast<const SdrOle2Primitive2D
&>(rPrimitive
);
53 // #i108636# The standard operator== on two UNO sequences did not work as i
54 // would have expected; it just checks the .is() states and the data type
55 // of the sequence. What i need here is detection of equality of the whole
56 // sequence content, thus i need to use the arePrimitive2DSequencesEqual helper
57 // here instead of the operator== which lead to always returning false and thus
58 // always re-decompositions of the subcontent.
59 if(getOLEContent() == rCompare
.getOLEContent()
60 && getTransform() == rCompare
.getTransform()
61 && getSdrLFSTAttribute() == rCompare
.getSdrLFSTAttribute())
70 void SdrOle2Primitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& /*aViewInformation*/) const
72 // to take care of getSdrLFSTAttribute() later, the same as in SdrGrafPrimitive2D::create2DDecomposition
73 // should happen. For the moment we only need the OLE itself
74 // Added complete primitive preparation using getSdrLFSTAttribute() now.
75 Primitive2DContainer aRetval
;
77 // create unit outline polygon
78 const basegfx::B2DPolygon
& aUnitOutline(basegfx::utils::createUnitPolygon());
81 if(!getSdrLFSTAttribute().getFill().isDefault())
83 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
85 aTransformed
.transform(getTransform());
87 createPolyPolygonFillPrimitive(
89 getSdrLFSTAttribute().getFill(),
90 getSdrLFSTAttribute().getFillFloatTransGradient()));
94 // #i97981# condition was inverse to purpose. When being compatible to paint version,
95 // border needs to be suppressed
96 if(!getSdrLFSTAttribute().getLine().isDefault())
98 // if line width is given, polygon needs to be grown by half of it to make the
99 // outline to be outside of the bitmap
100 if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
102 // decompose to get scale
103 basegfx::B2DVector aScale
, aTranslate
;
104 double fRotate
, fShearX
;
105 getTransform().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
107 // create expanded range (add relative half line width to unit rectangle)
108 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
109 double fScaleX(0.0 != aScale
.getX() ? fHalfLineWidth
/ fabs(aScale
.getX()) : 1.0);
110 double fScaleY(0.0 != aScale
.getY() ? fHalfLineWidth
/ fabs(aScale
.getY()) : 1.0);
111 const basegfx::B2DRange
aExpandedRange(-fScaleX
, -fScaleY
, 1.0 + fScaleX
, 1.0 + fScaleY
);
112 basegfx::B2DPolygon
aExpandedUnitOutline(basegfx::utils::createPolygonFromRect(aExpandedRange
));
114 aExpandedUnitOutline
.transform(getTransform());
116 createPolygonLinePrimitive(
117 aExpandedUnitOutline
,
118 getSdrLFSTAttribute().getLine(),
119 attribute::SdrLineStartEndAttribute()));
123 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
125 aTransformed
.transform(getTransform());
127 createPolygonLinePrimitive(
129 getSdrLFSTAttribute().getLine(),
130 attribute::SdrLineStartEndAttribute()));
135 // if initially no line is defined, create one for HitTest and BoundRect
137 createHiddenGeometryPrimitives2D(
139 basegfx::B2DPolyPolygon(aUnitOutline
),
143 // add graphic content
144 aRetval
.append(getOLEContent());
146 // add text, no need to suppress to stay compatible since text was
147 // always supported by the old paints, too
148 if(!getSdrLFSTAttribute().getText().isDefault())
152 basegfx::B2DPolyPolygon(aUnitOutline
),
154 getSdrLFSTAttribute().getText(),
155 getSdrLFSTAttribute().getLine(),
161 if(!getSdrLFSTAttribute().getShadow().isDefault())
163 aRetval
= createEmbeddedShadowPrimitive(
165 getSdrLFSTAttribute().getShadow());
168 rVisitor
.append(aRetval
);
172 ImplPrimitive2DIDBlock(SdrOle2Primitive2D
, PRIMITIVE2D_ID_SDROLE2PRIMITIVE2D
)
174 } // end of namespace primitive2d
175 } // end of namespace drawinglayer
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */