Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrole2primitive2d.cxx
blob3a4ed80c8166286663b18c810bba5a391a87a256
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sdr/primitive2d/sdrdecompositiontools.hxx>
24 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
27 #include <utility>
30 using namespace com::sun::star;
33 namespace drawinglayer::primitive2d
35 SdrOle2Primitive2D::SdrOle2Primitive2D(
36 Primitive2DContainer&& rOLEContent,
37 basegfx::B2DHomMatrix aTransform,
38 const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute)
39 : maOLEContent(std::move(rOLEContent)),
40 maTransform(std::move(aTransform)),
41 maSdrLFSTAttribute(rSdrLFSTAttribute)
45 bool SdrOle2Primitive2D::operator==(const BasePrimitive2D& rPrimitive) const
47 if(BasePrimitive2D::operator==(rPrimitive))
49 const SdrOle2Primitive2D& rCompare = static_cast<const SdrOle2Primitive2D&>(rPrimitive);
51 // #i108636# The standard operator== on two UNO sequences did not work as i
52 // would have expected; it just checks the .is() states and the data type
53 // of the sequence. What i need here is detection of equality of the whole
54 // sequence content, thus i need to use the arePrimitive2DSequencesEqual helper
55 // here instead of the operator== which lead to always returning false and thus
56 // always re-decompositions of the subcontent.
57 if(getOLEContent() == rCompare.getOLEContent()
58 && getTransform() == rCompare.getTransform()
59 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute())
61 return true;
65 return false;
68 void SdrOle2Primitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& /*aViewInformation*/) const
70 // to take care of getSdrLFSTAttribute() later, the same as in SdrGrafPrimitive2D::create2DDecomposition
71 // should happen. For the moment we only need the OLE itself
72 // Added complete primitive preparation using getSdrLFSTAttribute() now.
73 Primitive2DContainer aRetval;
75 // create unit outline polygon
76 const basegfx::B2DPolygon& aUnitOutline(basegfx::utils::createUnitPolygon());
78 // add fill
79 if(!getSdrLFSTAttribute().getFill().isDefault())
81 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
83 aTransformed.transform(getTransform());
84 aRetval.push_back(
85 createPolyPolygonFillPrimitive(
86 aTransformed,
87 getSdrLFSTAttribute().getFill(),
88 getSdrLFSTAttribute().getFillFloatTransGradient()));
91 // add line
92 // #i97981# condition was inverse to purpose. When being compatible to paint version,
93 // border needs to be suppressed
94 if(!getSdrLFSTAttribute().getLine().isDefault())
96 // if line width is given, polygon needs to be grown by half of it to make the
97 // outline to be outside of the bitmap
98 if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
100 // decompose to get scale
101 basegfx::B2DVector aScale, aTranslate;
102 double fRotate, fShearX;
103 getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
105 // create expanded range (add relative half line width to unit rectangle)
106 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
107 double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
108 double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
109 const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
110 basegfx::B2DPolygon aExpandedUnitOutline(basegfx::utils::createPolygonFromRect(aExpandedRange));
112 aExpandedUnitOutline.transform(getTransform());
113 aRetval.push_back(
114 createPolygonLinePrimitive(
115 aExpandedUnitOutline,
116 getSdrLFSTAttribute().getLine(),
117 attribute::SdrLineStartEndAttribute()));
119 else
121 basegfx::B2DPolygon aTransformed(aUnitOutline);
123 aTransformed.transform(getTransform());
124 aRetval.push_back(
125 createPolygonLinePrimitive(
126 aTransformed,
127 getSdrLFSTAttribute().getLine(),
128 attribute::SdrLineStartEndAttribute()));
131 else
133 // if initially no line is defined, create one for HitTest and BoundRect
134 aRetval.push_back(
135 createHiddenGeometryPrimitives2D(
136 false,
137 basegfx::B2DPolyPolygon(aUnitOutline),
138 getTransform()));
141 // add graphic content
142 aRetval.append(getOLEContent());
144 // add text, no need to suppress to stay compatible since text was
145 // always supported by the old paints, too
146 if(!getSdrLFSTAttribute().getText().isDefault())
148 aRetval.push_back(
149 createTextPrimitive(
150 basegfx::B2DPolyPolygon(aUnitOutline),
151 getTransform(),
152 getSdrLFSTAttribute().getText(),
153 getSdrLFSTAttribute().getLine(),
154 false,
155 false));
158 // add shadow
159 if(!getSdrLFSTAttribute().getShadow().isDefault())
161 aRetval = createEmbeddedShadowPrimitive(
162 std::move(aRetval),
163 getSdrLFSTAttribute().getShadow());
166 rVisitor.visit(std::move(aRetval));
169 // provide unique ID
170 sal_uInt32 SdrOle2Primitive2D::getPrimitive2DID() const
172 return PRIMITIVE2D_ID_SDROLE2PRIMITIVE2D;
175 } // end of namespace
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */