Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrrectangleprimitive2d.cxx
blob0d3387f2ff4fa25da9721d6742d263bf9355c81e
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/sdrrectangleprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygontools.hxx>
22 #include <sdr/primitive2d/sdrdecompositiontools.hxx>
23 #include <svx/sdr/primitive2d/svx_primitivetypes2d.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::primitive2d
34 void SdrRectanglePrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
36 Primitive2DContainer aRetval;
38 // create unit outline polygon
39 const basegfx::B2DPolygon aUnitOutline(basegfx::utils::createPolygonFromRect(
40 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
41 getCornerRadiusX(),
42 getCornerRadiusY()));
44 // add fill
45 if(!getSdrLFSTAttribute().getFill().isDefault())
47 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
49 aTransformed.transform(getTransform());
50 aRetval.push_back(
51 createPolyPolygonFillPrimitive(
52 aTransformed,
53 getSdrLFSTAttribute().getFill(),
54 getSdrLFSTAttribute().getFillFloatTransGradient()));
56 else if(getForceFillForHitTest())
58 // if no fill and it's a text frame, create a fill for HitTest and
59 // BoundRect fallback
60 aRetval.push_back(
61 createHiddenGeometryPrimitives2D(
62 true,
63 basegfx::B2DPolyPolygon(aUnitOutline),
64 getTransform()));
67 // add line
68 if(!getSdrLFSTAttribute().getLine().isDefault())
70 basegfx::B2DPolygon aTransformed(aUnitOutline);
72 aTransformed.transform(getTransform());
73 aRetval.push_back(
74 createPolygonLinePrimitive(
75 aTransformed,
76 getSdrLFSTAttribute().getLine(),
77 attribute::SdrLineStartEndAttribute()));
79 else if(!getForceFillForHitTest())
81 // if initially no line is defined and it's not a text frame, create
82 // a line for HitTest and BoundRect
83 aRetval.push_back(
84 createHiddenGeometryPrimitives2D(
85 false,
86 basegfx::B2DPolyPolygon(aUnitOutline),
87 getTransform()));
90 // add text
91 if(!getSdrLFSTAttribute().getText().isDefault())
93 aRetval.push_back(
94 createTextPrimitive(
95 basegfx::B2DPolyPolygon(aUnitOutline),
96 getTransform(),
97 getSdrLFSTAttribute().getText(),
98 getSdrLFSTAttribute().getLine(),
99 false,
100 false));
103 // add shadow
104 if(!getSdrLFSTAttribute().getShadow().isDefault())
106 aRetval = createEmbeddedShadowPrimitive(
107 aRetval,
108 getSdrLFSTAttribute().getShadow());
111 rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end());
114 SdrRectanglePrimitive2D::SdrRectanglePrimitive2D(
115 const basegfx::B2DHomMatrix& rTransform,
116 const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute,
117 double fCornerRadiusX,
118 double fCornerRadiusY,
119 bool bForceFillForHitTest)
120 : BufferedDecompositionPrimitive2D(),
121 maTransform(rTransform),
122 maSdrLFSTAttribute(rSdrLFSTAttribute),
123 mfCornerRadiusX(fCornerRadiusX),
124 mfCornerRadiusY(fCornerRadiusY),
125 mbForceFillForHitTest(bForceFillForHitTest)
129 bool SdrRectanglePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
131 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
133 const SdrRectanglePrimitive2D& rCompare = static_cast<const SdrRectanglePrimitive2D&>(rPrimitive);
135 return (getCornerRadiusX() == rCompare.getCornerRadiusX()
136 && getCornerRadiusY() == rCompare.getCornerRadiusY()
137 && getTransform() == rCompare.getTransform()
138 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
139 && getForceFillForHitTest() == rCompare.getForceFillForHitTest());
142 return false;
145 // provide unique ID
146 ImplPrimitive2DIDBlock(SdrRectanglePrimitive2D, PRIMITIVE2D_ID_SDRRECTANGLEPRIMITIVE2D)
148 } // end of namespace
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */