1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: fillhatchprimitive2d.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/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
58 Primitive2DSequence
FillHatchPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
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
:
71 texture::GeoTexSvxHatch
aHatch(getObjectRange(), maFillHatch
.getDistance(), fAngle
+ F_PI4
);
72 aHatch
.appendTransformations(aMatrices
);
74 // fall-through by purpose
76 case attribute::HATCHSTYLE_DOUBLE
:
79 texture::GeoTexSvxHatch
aHatch(getObjectRange(), maFillHatch
.getDistance(), fAngle
+ F_PI2
);
80 aHatch
.appendTransformations(aMatrices
);
82 // fall-through by purpose
84 case attribute::HATCHSTYLE_SINGLE
:
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
99 // create primitive for background
100 const Primitive2DReference
xRef(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(getObjectRange())), maBColor
));
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
);
117 const Primitive2DReference
xRef(new PolygonHairlinePrimitive2D(aNewLine
, aHatchColor
));
118 aRetval
[bFillBackground
? (a
+ 1L) : a
] = xRef
;
124 FillHatchPrimitive2D::FillHatchPrimitive2D(
125 const basegfx::B2DRange
& rObjectRange
,
126 const basegfx::BColor
& rBColor
,
127 const attribute::FillHatchAttribute
& rFillHatch
)
129 maObjectRange(rObjectRange
),
130 maFillHatch(rFillHatch
),
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
);
149 basegfx::B2DRange
FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
151 // return ObjectRange
152 return getObjectRange();
156 ImplPrimitrive2DIDBlock(FillHatchPrimitive2D
, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D
)
158 } // end of namespace primitive2d
159 } // end of namespace drawinglayer
161 //////////////////////////////////////////////////////////////////////////////