merge the formfield patch from ooo-build
[ooovba.git] / drawinglayer / source / primitive2d / fillhatchprimitive2d.cxx
blob6749b4bf1835755b4bd32ac82bc810fb8ce40f4a
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: fillhatchprimitive2d.cxx,v $
7 * $Revision: 1.6 $
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,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/primitive2d/fillhatchprimitive2d.hxx>
40 #include <drawinglayer/texture/texture.hxx>
41 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
42 #include <basegfx/polygon/b2dpolygontools.hxx>
43 #include <basegfx/polygon/b2dpolygon.hxx>
44 #include <basegfx/tools/canvastools.hxx>
45 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
46 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
48 //////////////////////////////////////////////////////////////////////////////
50 using namespace com::sun::star;
52 //////////////////////////////////////////////////////////////////////////////
54 namespace drawinglayer
56 namespace primitive2d
58 Primitive2DSequence FillHatchPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
60 // create hatch
61 const basegfx::BColor aHatchColor(maFillHatch.getColor());
62 const double fAngle(-maFillHatch.getAngle());
63 ::std::vector< basegfx::B2DHomMatrix > aMatrices;
65 // get hatch transformations
66 switch(maFillHatch.getStyle())
68 case attribute::HATCHSTYLE_TRIPLE:
70 // rotated 45 degrees
71 texture::GeoTexSvxHatch aHatch(getObjectRange(), maFillHatch.getDistance(), fAngle + F_PI4);
72 aHatch.appendTransformations(aMatrices);
74 // fall-through by purpose
76 case attribute::HATCHSTYLE_DOUBLE:
78 // rotated 90 degrees
79 texture::GeoTexSvxHatch aHatch(getObjectRange(), maFillHatch.getDistance(), fAngle + F_PI2);
80 aHatch.appendTransformations(aMatrices);
82 // fall-through by purpose
84 case attribute::HATCHSTYLE_SINGLE:
86 // angle as given
87 texture::GeoTexSvxHatch aHatch(getObjectRange(), maFillHatch.getDistance(), fAngle);
88 aHatch.appendTransformations(aMatrices);
92 // prepare return value
93 const bool bFillBackground(maFillHatch.isFillBackground());
94 Primitive2DSequence aRetval(bFillBackground ? aMatrices.size() + 1L : aMatrices.size());
96 // evtl. create filled background
97 if(bFillBackground)
99 // create primitive for background
100 const Primitive2DReference xRef(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(getObjectRange())), maBColor));
101 aRetval[0L] = xRef;
104 // create primitives
105 const basegfx::B2DPoint aStart(0.0, 0.0);
106 const basegfx::B2DPoint aEnd(1.0, 0.0);
108 for(sal_uInt32 a(0L); a < aMatrices.size(); a++)
110 const basegfx::B2DHomMatrix& rMatrix = aMatrices[a];
111 basegfx::B2DPolygon aNewLine;
113 aNewLine.append(rMatrix * aStart);
114 aNewLine.append(rMatrix * aEnd);
116 // create hairline
117 const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aNewLine, aHatchColor));
118 aRetval[bFillBackground ? (a + 1L) : a] = xRef;
121 return aRetval;
124 FillHatchPrimitive2D::FillHatchPrimitive2D(
125 const basegfx::B2DRange& rObjectRange,
126 const basegfx::BColor& rBColor,
127 const attribute::FillHatchAttribute& rFillHatch)
128 : BasePrimitive2D(),
129 maObjectRange(rObjectRange),
130 maFillHatch(rFillHatch),
131 maBColor(rBColor)
135 bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
137 if(BasePrimitive2D::operator==(rPrimitive))
139 const FillHatchPrimitive2D& rCompare = (FillHatchPrimitive2D&)rPrimitive;
141 return (getObjectRange() == rCompare.getObjectRange()
142 && maFillHatch == rCompare.maFillHatch
143 && maBColor == rCompare.maBColor);
146 return false;
149 basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
151 // return ObjectRange
152 return getObjectRange();
155 // provide unique ID
156 ImplPrimitrive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D)
158 } // end of namespace primitive2d
159 } // end of namespace drawinglayer
161 //////////////////////////////////////////////////////////////////////////////
162 // eof