cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrgrafprimitive2d.cxx
blobdadc8d06326e0c74ebfa17f1d9a64744d8cb1833
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/sdrgrafprimitive2d.hxx>
21 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
22 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
23 #include <drawinglayer/primitive2d/exclusiveeditviewprimitive2d.hxx>
24 #include <basegfx/polygon/b2dpolygontools.hxx>
25 #include <sdr/primitive2d/sdrdecompositiontools.hxx>
26 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
27 #include <basegfx/polygon/b2dpolygon.hxx>
28 #include <utility>
30 namespace drawinglayer::primitive2d
32 Primitive2DReference SdrGrafPrimitive2D::create2DDecomposition(
33 const geometry::ViewInformation2D& /*aViewInformation*/) const
35 Primitive2DContainer aRetval;
37 // create unit outline polygon
38 const basegfx::B2DPolygon& aUnitOutline(basegfx::utils::createUnitPolygon());
40 // add fill, but only when graphic is transparent
41 if (!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
43 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
45 aTransformed.transform(getTransform());
46 aRetval.push_back(
47 createPolyPolygonFillPrimitive(aTransformed, getSdrLFSTAttribute().getFill(),
48 getSdrLFSTAttribute().getFillFloatTransGradient()));
51 // add graphic content
52 if (0 != getGraphicAttr().GetAlpha())
54 // standard graphic fill
55 const Primitive2DReference xGraphicContentPrimitive(
56 new GraphicPrimitive2D(getTransform(), getGraphicObject(), getGraphicAttr()));
57 aRetval.push_back(xGraphicContentPrimitive);
60 // add line
61 if (!getSdrLFSTAttribute().getLine().isDefault())
63 // if line width is given, polygon needs to be grown by half of it to make the
64 // outline to be outside of the bitmap
65 if (0.0 != getSdrLFSTAttribute().getLine().getWidth())
67 // decompose to get scale
68 basegfx::B2DVector aScale, aTranslate;
69 double fRotate, fShearX;
70 getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
72 // create expanded range (add relative half line width to unit rectangle)
73 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
74 double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
75 double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
76 const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX,
77 1.0 + fScaleY);
78 basegfx::B2DPolygon aExpandedUnitOutline(
79 basegfx::utils::createPolygonFromRect(aExpandedRange));
81 aExpandedUnitOutline.transform(getTransform());
82 aRetval.push_back(createPolygonLinePrimitive(aExpandedUnitOutline,
83 getSdrLFSTAttribute().getLine(),
84 attribute::SdrLineStartEndAttribute()));
86 else
88 basegfx::B2DPolygon aTransformed(aUnitOutline);
90 aTransformed.transform(getTransform());
91 aRetval.push_back(createPolygonLinePrimitive(aTransformed,
92 getSdrLFSTAttribute().getLine(),
93 attribute::SdrLineStartEndAttribute()));
97 // Soft edges should be before text, since text is not affected by soft edges
98 if (!aRetval.empty() && getSdrLFSTAttribute().getSoftEdgeRadius())
100 aRetval = createEmbeddedSoftEdgePrimitive(std::move(aRetval),
101 getSdrLFSTAttribute().getSoftEdgeRadius());
104 // add text
105 if (!getSdrLFSTAttribute().getText().isDefault())
107 const drawinglayer::primitive2d::Primitive2DReference xReferenceA = createTextPrimitive(
108 basegfx::B2DPolyPolygon(aUnitOutline), getTransform(), getSdrLFSTAttribute().getText(),
109 getSdrLFSTAttribute().getLine(), false, false);
111 if (!mbPlaceholderImage)
113 aRetval.push_back(xReferenceA);
115 else
117 const drawinglayer::primitive2d::Primitive2DReference aEmbedded(
118 new drawinglayer::primitive2d::ExclusiveEditViewPrimitive2D(
119 drawinglayer::primitive2d::Primitive2DContainer{ xReferenceA }));
121 aRetval.push_back(aEmbedded);
125 // tdf#132199: put glow before shadow, to have shadow of the glow, not the opposite
126 if (!aRetval.empty() && !getSdrLFSTAttribute().getGlow().isDefault())
128 // glow
129 aRetval = createEmbeddedGlowPrimitive(std::move(aRetval), getSdrLFSTAttribute().getGlow());
132 // add shadow
133 if (!getSdrLFSTAttribute().getShadow().isDefault())
135 aRetval = createEmbeddedShadowPrimitive(std::move(aRetval),
136 getSdrLFSTAttribute().getShadow(), getTransform());
139 return new GroupPrimitive2D(std::move(aRetval));
142 SdrGrafPrimitive2D::SdrGrafPrimitive2D(
143 basegfx::B2DHomMatrix aTransform,
144 const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute,
145 const GraphicObject& rGraphicObject, const GraphicAttr& rGraphicAttr,
146 bool bPlaceholderImage /* = false */)
147 : maTransform(std::move(aTransform))
148 , maSdrLFSTAttribute(rSdrLFSTAttribute)
149 , maGraphicObject(rGraphicObject)
150 , maGraphicAttr(rGraphicAttr)
151 , mbPlaceholderImage(bPlaceholderImage)
153 // activate callback to flush buffered decomposition content
154 setCallbackSeconds(20);
156 // reset some values from GraphicAttr which are part of transformation already
157 maGraphicAttr.SetRotation(0_deg10);
160 bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
162 if (BufferedDecompositionPrimitive2D::operator==(rPrimitive))
164 const SdrGrafPrimitive2D& rCompare = static_cast<const SdrGrafPrimitive2D&>(rPrimitive);
166 return (getTransform() == rCompare.getTransform()
167 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
168 && getGraphicObject() == rCompare.getGraphicObject()
169 && getGraphicAttr() == rCompare.getGraphicAttr());
172 return false;
175 bool SdrGrafPrimitive2D::isTransparent() const
177 return ((255 != getGraphicAttr().GetAlpha()) || (getGraphicObject().IsTransparent()));
180 // provide unique ID
181 sal_uInt32 SdrGrafPrimitive2D::getPrimitive2DID() const
183 return PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D;
186 } // end of namespace
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */