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 <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
24 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
25 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
26 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
27 #include <basegfx/polygon/b2dpolygon.hxx>
28 #include <basegfx/matrix/b2dhommatrixtools.hxx>
29 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
31 namespace drawinglayer
35 Primitive2DSequence
SdrGrafPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
37 Primitive2DSequence aRetval
;
39 // create unit outline polygon
40 basegfx::B2DPolygon
aUnitOutline(basegfx::tools::createUnitPolygon());
42 // add fill, but only when graphic ist transparent
43 if(!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
45 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
47 aTransformed
.transform(getTransform());
48 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
49 createPolyPolygonFillPrimitive(
51 getSdrLFSTAttribute().getFill(),
52 getSdrLFSTAttribute().getFillFloatTransGradient()));
55 // add graphic content
56 if(255L != getGraphicAttr().GetTransparency())
58 // standard graphic fill
59 const Primitive2DReference
xGraphicContentPrimitive(
60 new GraphicPrimitive2D(
65 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, xGraphicContentPrimitive
);
69 if(!getSdrLFSTAttribute().getLine().isDefault())
71 // if line width is given, polygon needs to be grown by half of it to make the
72 // outline to be outside of the bitmap
73 if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
75 // decompose to get scale
76 basegfx::B2DVector aScale
, aTranslate
;
77 double fRotate
, fShearX
;
78 getTransform().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
80 // create expanded range (add relative half line width to unit rectangle)
81 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
82 double fScaleX(0.0 != aScale
.getX() ? fHalfLineWidth
/ fabs(aScale
.getX()) : 1.0);
83 double fScaleY(0.0 != aScale
.getY() ? fHalfLineWidth
/ fabs(aScale
.getY()) : 1.0);
84 const basegfx::B2DRange
aExpandedRange(-fScaleX
, -fScaleY
, 1.0 + fScaleX
, 1.0 + fScaleY
);
85 basegfx::B2DPolygon
aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange
));
87 aExpandedUnitOutline
.transform(getTransform());
88 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
89 createPolygonLinePrimitive(
91 getSdrLFSTAttribute().getLine(),
92 attribute::SdrLineStartEndAttribute()));
96 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
98 aTransformed
.transform(getTransform());
99 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
100 createPolygonLinePrimitive(
102 getSdrLFSTAttribute().getLine(),
103 attribute::SdrLineStartEndAttribute()));
108 if(!getSdrLFSTAttribute().getText().isDefault())
110 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
112 basegfx::B2DPolyPolygon(aUnitOutline
),
114 getSdrLFSTAttribute().getText(),
115 getSdrLFSTAttribute().getLine(),
122 if(!getSdrLFSTAttribute().getShadow().isDefault())
124 aRetval
= createEmbeddedShadowPrimitive(
126 getSdrLFSTAttribute().getShadow());
132 SdrGrafPrimitive2D::SdrGrafPrimitive2D(
133 const basegfx::B2DHomMatrix
& rTransform
,
134 const attribute::SdrLineFillShadowTextAttribute
& rSdrLFSTAttribute
,
135 const GraphicObject
& rGraphicObject
,
136 const GraphicAttr
& rGraphicAttr
)
137 : BufferedDecompositionPrimitive2D(),
138 maTransform(rTransform
),
139 maSdrLFSTAttribute(rSdrLFSTAttribute
),
140 maGraphicObject(rGraphicObject
),
141 maGraphicAttr(rGraphicAttr
)
143 // reset some values from GraphicAttr which are part of transformation already
144 maGraphicAttr
.SetRotation(0L);
147 bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
149 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
151 const SdrGrafPrimitive2D
& rCompare
= static_cast<const SdrGrafPrimitive2D
&>(rPrimitive
);
153 return (getTransform() == rCompare
.getTransform()
154 && getSdrLFSTAttribute() == rCompare
.getSdrLFSTAttribute()
155 && getGraphicObject() == rCompare
.getGraphicObject()
156 && getGraphicAttr() == rCompare
.getGraphicAttr());
162 bool SdrGrafPrimitive2D::isTransparent() const
164 return ((0L != getGraphicAttr().GetTransparency())
165 || (getGraphicObject().IsTransparent()));
169 ImplPrimitive2DIDBlock(SdrGrafPrimitive2D
, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D
)
171 } // end of namespace primitive2d
172 } // end of namespace drawinglayer
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */