bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrgrafprimitive2d.cxx
blob44ed09dd7fd9c56457bea99ac246b19b6598360d
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 <svx/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 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
46 createPolyPolygonFillPrimitive(
47 basegfx::B2DPolyPolygon(aUnitOutline),
48 getTransform(),
49 getSdrLFSTAttribute().getFill(),
50 getSdrLFSTAttribute().getFillFloatTransGradient()));
53 // add graphic content
54 if(255L != getGraphicAttr().GetTransparency())
56 // standard graphic fill
57 const Primitive2DReference xGraphicContentPrimitive(
58 new GraphicPrimitive2D(
59 getTransform(),
60 getGraphicObject(),
61 getGraphicAttr()));
63 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive);
66 // add line
67 if(!getSdrLFSTAttribute().getLine().isDefault())
69 // if line width is given, polygon needs to be grown by half of it to make the
70 // outline to be outside of the bitmap
71 if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
73 // decompose to get scale
74 basegfx::B2DVector aScale, aTranslate;
75 double fRotate, fShearX;
76 getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
78 // create expanded range (add relative half line width to unit rectangle)
79 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
80 double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
81 double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
82 const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
83 basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange));
85 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
86 createPolygonLinePrimitive(
87 aExpandedUnitOutline,
88 getTransform(),
89 getSdrLFSTAttribute().getLine(),
90 attribute::SdrLineStartEndAttribute()));
92 else
94 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
95 createPolygonLinePrimitive(
96 aUnitOutline, getTransform(),
97 getSdrLFSTAttribute().getLine(),
98 attribute::SdrLineStartEndAttribute()));
102 // add text
103 if(!getSdrLFSTAttribute().getText().isDefault())
105 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
106 createTextPrimitive(
107 basegfx::B2DPolyPolygon(aUnitOutline),
108 getTransform(),
109 getSdrLFSTAttribute().getText(),
110 getSdrLFSTAttribute().getLine(),
111 false,
112 false,
113 false));
116 // add shadow
117 if(!getSdrLFSTAttribute().getShadow().isDefault())
119 aRetval = createEmbeddedShadowPrimitive(
120 aRetval,
121 getSdrLFSTAttribute().getShadow());
124 return aRetval;
127 SdrGrafPrimitive2D::SdrGrafPrimitive2D(
128 const basegfx::B2DHomMatrix& rTransform,
129 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
130 const GraphicObject& rGraphicObject,
131 const GraphicAttr& rGraphicAttr)
132 : BufferedDecompositionPrimitive2D(),
133 maTransform(rTransform),
134 maSdrLFSTAttribute(rSdrLFSTAttribute),
135 maGraphicObject(rGraphicObject),
136 maGraphicAttr(rGraphicAttr)
138 // reset some values from GraphicAttr which are part of transformation already
139 maGraphicAttr.SetRotation(0L);
142 bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
144 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
146 const SdrGrafPrimitive2D& rCompare = (SdrGrafPrimitive2D&)rPrimitive;
148 return (getTransform() == rCompare.getTransform()
149 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
150 && getGraphicObject() == rCompare.getGraphicObject()
151 && getGraphicAttr() == rCompare.getGraphicAttr());
154 return false;
157 bool SdrGrafPrimitive2D::isTransparent() const
159 return ((0L != getGraphicAttr().GetTransparency())
160 || (getGraphicObject().IsTransparent()));
163 // provide unique ID
164 ImplPrimitive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D)
166 } // end of namespace primitive2d
167 } // end of namespace drawinglayer
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */