merge the formfield patch from ooo-build
[ooovba.git] / svx / source / sdr / primitive2d / sdrgrafprimitive2d.cxx
blobe4183f3e6931fa4ac7cb40cf4e68aa5d78133b43
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdrgrafprimitive2d.cxx,v $
11 * $Revision: 1.2.18.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/primitive2d/sdrgrafprimitive2d.hxx>
34 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
36 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
37 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
38 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
39 #include <drawinglayer/primitive2d/hittestprimitive2d.hxx>
41 //////////////////////////////////////////////////////////////////////////////
43 namespace drawinglayer
45 namespace primitive2d
47 Primitive2DSequence SdrGrafPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
49 Primitive2DSequence aRetval;
51 // create unit outline polygon
52 basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0)));
54 // add fill, but only when graphic ist transparent
55 if(getSdrLFSTAttribute().getFill() && isTransparent())
57 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
58 createPolyPolygonFillPrimitive(basegfx::B2DPolyPolygon(aUnitOutline), getTransform(), *getSdrLFSTAttribute().getFill(), getSdrLFSTAttribute().getFillFloatTransGradient()));
61 // add line
62 if(getSdrLFSTAttribute().getLine())
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::tools::createPolygonFromRect(aExpandedRange));
80 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createPolygonLinePrimitive(aExpandedUnitOutline, getTransform(), *getSdrLFSTAttribute().getLine()));
82 else
84 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createPolygonLinePrimitive(aUnitOutline, getTransform(), *getSdrLFSTAttribute().getLine()));
87 else
89 // if initially no line is defined, create one for HitTest and BoundRect
90 const attribute::SdrLineAttribute aBlackHairline(basegfx::BColor(0.0, 0.0, 0.0));
91 const Primitive2DReference xHiddenLineReference(createPolygonLinePrimitive(aUnitOutline, getTransform(), aBlackHairline));
92 const Primitive2DSequence xHiddenLineSequence(&xHiddenLineReference, 1);
94 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, Primitive2DReference(new HitTestPrimitive2D(xHiddenLineSequence)));
97 // add graphic content
98 if(255L != getGraphicAttr().GetTransparency())
100 Primitive2DReference xGraphicContentPrimitive(new GraphicPrimitive2D(getTransform(), getGraphicObject(), getGraphicAttr()));
101 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive);
104 // add text
105 if(getSdrLFSTAttribute().getText())
107 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createTextPrimitive(basegfx::B2DPolyPolygon(aUnitOutline), getTransform(), *getSdrLFSTAttribute().getText(), getSdrLFSTAttribute().getLine(), false, false));
110 // add shadow
111 if(getSdrLFSTAttribute().getShadow())
113 aRetval = createEmbeddedShadowPrimitive(aRetval, *getSdrLFSTAttribute().getShadow());
116 return aRetval;
119 SdrGrafPrimitive2D::SdrGrafPrimitive2D(
120 const basegfx::B2DHomMatrix& rTransform,
121 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
122 const GraphicObject& rGraphicObject,
123 const GraphicAttr& rGraphicAttr)
124 : BasePrimitive2D(),
125 maTransform(rTransform),
126 maSdrLFSTAttribute(rSdrLFSTAttribute),
127 maGraphicObject(rGraphicObject),
128 maGraphicAttr(rGraphicAttr)
130 // reset some values from GraphicAttr which are part of transformation already
131 maGraphicAttr.SetRotation(0L);
134 bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
136 if(BasePrimitive2D::operator==(rPrimitive))
138 const SdrGrafPrimitive2D& rCompare = (SdrGrafPrimitive2D&)rPrimitive;
140 return (getTransform() == rCompare.getTransform()
141 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
142 && getGraphicObject() == rCompare.getGraphicObject()
143 && getGraphicAttr() == rCompare.getGraphicAttr());
146 return false;
149 bool SdrGrafPrimitive2D::isTransparent() const
151 return ((0L != getGraphicAttr().GetTransparency()) || (getGraphicObject().IsTransparent()));
154 // provide unique ID
155 ImplPrimitrive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D)
157 } // end of namespace primitive2d
158 } // end of namespace drawinglayer
160 //////////////////////////////////////////////////////////////////////////////
161 // eof