1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: fillgradientprimitive2d.cxx,v $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:20 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
40 #include <basegfx/polygon/b2dpolygon.hxx>
41 #include <basegfx/polygon/b2dpolygontools.hxx>
42 #include <drawinglayer/texture/texture.hxx>
43 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
44 #include <basegfx/tools/canvastools.hxx>
45 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
47 //////////////////////////////////////////////////////////////////////////////
49 using namespace com::sun::star
;
51 //////////////////////////////////////////////////////////////////////////////
53 namespace drawinglayer
57 Primitive2DSequence
FillGradientPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
59 const attribute::GradientStyle
aGradientStyle(maFillGradient
.getStyle());
60 ::std::vector
< basegfx::B2DHomMatrix
> aMatrices
;
61 ::std::vector
< basegfx::BColor
> aColors
;
62 basegfx::B2DPolygon aUnitPolygon
;
63 sal_uInt32
nSteps(maFillGradient
.getSteps());
65 if(attribute::GRADIENTSTYLE_RADIAL
== aGradientStyle
|| attribute::GRADIENTSTYLE_ELLIPTICAL
== aGradientStyle
)
67 const basegfx::B2DPoint
aCircleCenter(0.5, 0.5);
68 aUnitPolygon
= basegfx::tools::createPolygonFromEllipse(aCircleCenter
, 0.5, 0.5);
72 aUnitPolygon
= basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0));
75 // make sure steps is not too high/low
76 const basegfx::BColor
aStart(maFillGradient
.getStartColor());
77 const basegfx::BColor
aEnd(maFillGradient
.getEndColor());
78 const sal_uInt32
nMaxSteps(sal_uInt32((aStart
.getMaximumDistance(aEnd
) * 127.5) + 0.5));
90 if(nSteps
> nMaxSteps
)
95 switch(aGradientStyle
)
97 case attribute::GRADIENTSTYLE_LINEAR
:
99 texture::GeoTexSvxGradientLinear
aGradient(getObjectRange(), aStart
, aEnd
, nSteps
, maFillGradient
.getBorder(), -maFillGradient
.getAngle());
100 aGradient
.appendTransformations(aMatrices
);
101 aGradient
.appendColors(aColors
);
104 case attribute::GRADIENTSTYLE_AXIAL
:
106 texture::GeoTexSvxGradientAxial
aGradient(getObjectRange(), aStart
, aEnd
, nSteps
, maFillGradient
.getBorder(), -maFillGradient
.getAngle());
107 aGradient
.appendTransformations(aMatrices
);
108 aGradient
.appendColors(aColors
);
111 case attribute::GRADIENTSTYLE_RADIAL
:
113 texture::GeoTexSvxGradientRadial
aGradient(getObjectRange(), aStart
, aEnd
, nSteps
, maFillGradient
.getBorder(), maFillGradient
.getOffsetX(), maFillGradient
.getOffsetY());
114 aGradient
.appendTransformations(aMatrices
);
115 aGradient
.appendColors(aColors
);
118 case attribute::GRADIENTSTYLE_ELLIPTICAL
:
120 texture::GeoTexSvxGradientElliptical
aGradient(getObjectRange(), aStart
, aEnd
, nSteps
, maFillGradient
.getBorder(), maFillGradient
.getOffsetX(), maFillGradient
.getOffsetY(), -maFillGradient
.getAngle());
121 aGradient
.appendTransformations(aMatrices
);
122 aGradient
.appendColors(aColors
);
125 case attribute::GRADIENTSTYLE_SQUARE
:
127 texture::GeoTexSvxGradientSquare
aGradient(getObjectRange(), aStart
, aEnd
, nSteps
, maFillGradient
.getBorder(), maFillGradient
.getOffsetX(), maFillGradient
.getOffsetY(), -maFillGradient
.getAngle());
128 aGradient
.appendTransformations(aMatrices
);
129 aGradient
.appendColors(aColors
);
132 case attribute::GRADIENTSTYLE_RECT
:
134 texture::GeoTexSvxGradientRect
aGradient(getObjectRange(), aStart
, aEnd
, nSteps
, maFillGradient
.getBorder(), maFillGradient
.getOffsetX(), maFillGradient
.getOffsetY(), -maFillGradient
.getAngle());
135 aGradient
.appendTransformations(aMatrices
);
136 aGradient
.appendColors(aColors
);
141 // prepare return value
142 Primitive2DSequence
aRetval(aColors
.size() ? aMatrices
.size() + 1L : aMatrices
.size());
144 // create solid fill with start color
148 const Primitive2DReference
xRef(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(getObjectRange())), aColors
[0L]));
152 // create solid fill steps
153 for(sal_uInt32
a(0L); a
< aMatrices
.size(); a
++)
155 // create part polygon
156 basegfx::B2DPolygon
aNewPoly(aUnitPolygon
);
157 aNewPoly
.transform(aMatrices
[a
]);
160 const Primitive2DReference
xRef(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aNewPoly
), aColors
[a
+ 1L]));
161 aRetval
[a
+ 1L] = xRef
;
167 FillGradientPrimitive2D::FillGradientPrimitive2D(
168 const basegfx::B2DRange
& rObjectRange
,
169 const attribute::FillGradientAttribute
& rFillGradient
)
171 maObjectRange(rObjectRange
),
172 maFillGradient(rFillGradient
)
176 bool FillGradientPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
178 if(BasePrimitive2D::operator==(rPrimitive
))
180 const FillGradientPrimitive2D
& rCompare
= (FillGradientPrimitive2D
&)rPrimitive
;
182 return (getObjectRange() == rCompare
.getObjectRange()
183 && maFillGradient
== rCompare
.maFillGradient
);
189 basegfx::B2DRange
FillGradientPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
191 // return ObjectRange
192 return getObjectRange();
196 ImplPrimitrive2DIDBlock(FillGradientPrimitive2D
, PRIMITIVE2D_ID_FILLGRADIENTPRIMITIVE2D
)
198 } // end of namespace primitive2d
199 } // end of namespace drawinglayer
201 //////////////////////////////////////////////////////////////////////////////