bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrgrafprimitive2d.cxx
blob7345867a4316b698cf5ec605955e169e13eba785
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 <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
33 namespace primitive2d
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(
50 aTransformed,
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(
61 getTransform(),
62 getGraphicObject(),
63 getGraphicAttr()));
65 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive);
68 // add line
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(
90 aExpandedUnitOutline,
91 getSdrLFSTAttribute().getLine(),
92 attribute::SdrLineStartEndAttribute()));
94 else
96 basegfx::B2DPolygon aTransformed(aUnitOutline);
98 aTransformed.transform(getTransform());
99 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
100 createPolygonLinePrimitive(
101 aTransformed,
102 getSdrLFSTAttribute().getLine(),
103 attribute::SdrLineStartEndAttribute()));
107 // add text
108 if(!getSdrLFSTAttribute().getText().isDefault())
110 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
111 createTextPrimitive(
112 basegfx::B2DPolyPolygon(aUnitOutline),
113 getTransform(),
114 getSdrLFSTAttribute().getText(),
115 getSdrLFSTAttribute().getLine(),
116 false,
117 false,
118 false));
121 // add shadow
122 if(!getSdrLFSTAttribute().getShadow().isDefault())
124 aRetval = createEmbeddedShadowPrimitive(
125 aRetval,
126 getSdrLFSTAttribute().getShadow());
129 return aRetval;
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());
159 return false;
162 bool SdrGrafPrimitive2D::isTransparent() const
164 return ((0L != getGraphicAttr().GetTransparency())
165 || (getGraphicObject().IsTransparent()));
168 // provide unique ID
169 ImplPrimitive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D)
171 } // end of namespace primitive2d
172 } // end of namespace drawinglayer
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */