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/sdrgrafprimitive2d.hxx>
21 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <sdr/primitive2d/sdrdecompositiontools.hxx>
24 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
27 namespace drawinglayer::primitive2d
29 void SdrGrafPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& /*aViewInformation*/) const
31 Primitive2DContainer aRetval
;
33 // create unit outline polygon
34 const basegfx::B2DPolygon
& aUnitOutline(basegfx::utils::createUnitPolygon());
36 // add fill, but only when graphic is transparent
37 if(!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
39 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
41 aTransformed
.transform(getTransform());
43 createPolyPolygonFillPrimitive(
45 getSdrLFSTAttribute().getFill(),
46 getSdrLFSTAttribute().getFillFloatTransGradient()));
49 // add graphic content
50 if(255 != getGraphicAttr().GetTransparency())
52 // standard graphic fill
53 const Primitive2DReference
xGraphicContentPrimitive(
54 new GraphicPrimitive2D(
58 aRetval
.push_back(xGraphicContentPrimitive
);
62 if(!getSdrLFSTAttribute().getLine().isDefault())
64 // if line width is given, polygon needs to be grown by half of it to make the
65 // outline to be outside of the bitmap
66 if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
68 // decompose to get scale
69 basegfx::B2DVector aScale
, aTranslate
;
70 double fRotate
, fShearX
;
71 getTransform().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
73 // create expanded range (add relative half line width to unit rectangle)
74 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
75 double fScaleX(0.0 != aScale
.getX() ? fHalfLineWidth
/ fabs(aScale
.getX()) : 1.0);
76 double fScaleY(0.0 != aScale
.getY() ? fHalfLineWidth
/ fabs(aScale
.getY()) : 1.0);
77 const basegfx::B2DRange
aExpandedRange(-fScaleX
, -fScaleY
, 1.0 + fScaleX
, 1.0 + fScaleY
);
78 basegfx::B2DPolygon
aExpandedUnitOutline(basegfx::utils::createPolygonFromRect(aExpandedRange
));
80 aExpandedUnitOutline
.transform(getTransform());
82 createPolygonLinePrimitive(
84 getSdrLFSTAttribute().getLine(),
85 attribute::SdrLineStartEndAttribute()));
89 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
91 aTransformed
.transform(getTransform());
93 createPolygonLinePrimitive(
95 getSdrLFSTAttribute().getLine(),
96 attribute::SdrLineStartEndAttribute()));
100 // Soft edges should be before text, since text is not affected by soft edges
101 if (!aRetval
.empty() && getSdrLFSTAttribute().getSoftEdgeRadius())
103 aRetval
= createEmbeddedSoftEdgePrimitive(
104 aRetval
, getSdrLFSTAttribute().getSoftEdgeRadius());
108 if(!getSdrLFSTAttribute().getText().isDefault())
112 basegfx::B2DPolyPolygon(aUnitOutline
),
114 getSdrLFSTAttribute().getText(),
115 getSdrLFSTAttribute().getLine(),
120 // tdf#132199: put glow before shadow, to have shadow of the glow, not the opposite
121 if (!aRetval
.empty() && !getSdrLFSTAttribute().getGlow().isDefault())
124 aRetval
= createEmbeddedGlowPrimitive(aRetval
, getSdrLFSTAttribute().getGlow());
128 if(!getSdrLFSTAttribute().getShadow().isDefault())
130 aRetval
= createEmbeddedShadowPrimitive(
132 getSdrLFSTAttribute().getShadow(),
136 rContainer
.insert(rContainer
.end(), aRetval
.begin(), aRetval
.end());
139 SdrGrafPrimitive2D::SdrGrafPrimitive2D(
140 const basegfx::B2DHomMatrix
& rTransform
,
141 const attribute::SdrLineFillEffectsTextAttribute
& rSdrLFSTAttribute
,
142 const GraphicObject
& rGraphicObject
,
143 const GraphicAttr
& rGraphicAttr
)
144 : BufferedDecompositionPrimitive2D(),
145 maTransform(rTransform
),
146 maSdrLFSTAttribute(rSdrLFSTAttribute
),
147 maGraphicObject(rGraphicObject
),
148 maGraphicAttr(rGraphicAttr
)
150 // reset some values from GraphicAttr which are part of transformation already
151 maGraphicAttr
.SetRotation(Degree10(0));
154 bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
156 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
158 const SdrGrafPrimitive2D
& rCompare
= static_cast<const SdrGrafPrimitive2D
&>(rPrimitive
);
160 return (getTransform() == rCompare
.getTransform()
161 && getSdrLFSTAttribute() == rCompare
.getSdrLFSTAttribute()
162 && getGraphicObject() == rCompare
.getGraphicObject()
163 && getGraphicAttr() == rCompare
.getGraphicAttr());
169 bool SdrGrafPrimitive2D::isTransparent() const
171 return ((0 != getGraphicAttr().GetTransparency())
172 || (getGraphicObject().IsTransparent()));
176 ImplPrimitive2DIDBlock(SdrGrafPrimitive2D
, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D
)
178 } // end of namespace
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */