1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_drawinglayer.hxx"
30 
31 #include <drawinglayer/primitive2d/fillhatchprimitive2d.hxx>
32 #include <drawinglayer/texture/texture.hxx>
33 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
34 #include <basegfx/polygon/b2dpolygontools.hxx>
35 #include <basegfx/polygon/b2dpolygon.hxx>
36 #include <basegfx/tools/canvastools.hxx>
37 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
38 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
39 
40 //////////////////////////////////////////////////////////////////////////////
41 
42 using namespace com::sun::star;
43 
44 //////////////////////////////////////////////////////////////////////////////
45 
46 namespace drawinglayer
47 {
48 	namespace primitive2d
49 	{
50 		Primitive2DSequence FillHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
51 		{
52 		    Primitive2DSequence aRetval;
53             if(!getFillHatch().isDefault())
54             {
55 			    // create hatch
56 			    const basegfx::BColor aHatchColor(getFillHatch().getColor());
57 			    const double fAngle(getFillHatch().getAngle());
58 			    ::std::vector< basegfx::B2DHomMatrix > aMatrices;
59 
60 			    // get hatch transformations
61 			    switch(getFillHatch().getStyle())
62 			    {
63 				    case attribute::HATCHSTYLE_TRIPLE:
64 				    {
65 					    // rotated 45 degrees
66 					    texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle - F_PI4);
67 					    aHatch.appendTransformations(aMatrices);
68 
69 					    // fall-through by purpose
70 				    }
71 				    case attribute::HATCHSTYLE_DOUBLE:
72 				    {
73 					    // rotated 90 degrees
74 					    texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle - F_PI2);
75 					    aHatch.appendTransformations(aMatrices);
76 
77 					    // fall-through by purpose
78 				    }
79 				    case attribute::HATCHSTYLE_SINGLE:
80 				    {
81 					    // angle as given
82 					    texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle);
83 					    aHatch.appendTransformations(aMatrices);
84 				    }
85 			    }
86 
87 			    // prepare return value
88 			    const bool bFillBackground(getFillHatch().isFillBackground());
89 			    aRetval.realloc(bFillBackground ? aMatrices.size() + 1L : aMatrices.size());
90 
91 			    // evtl. create filled background
92 			    if(bFillBackground)
93 			    {
94 				    // create primitive for background
95 				    const Primitive2DReference xRef(
96                         new PolyPolygonColorPrimitive2D(
97                             basegfx::B2DPolyPolygon(
98                                 basegfx::tools::createPolygonFromRect(getObjectRange())), getBColor()));
99 				    aRetval[0] = xRef;
100 			    }
101 
102 			    // create primitives
103 			    const basegfx::B2DPoint aStart(0.0, 0.0);
104 			    const basegfx::B2DPoint aEnd(1.0, 0.0);
105 
106 			    for(sal_uInt32 a(0L); a < aMatrices.size(); a++)
107 			    {
108 				    const basegfx::B2DHomMatrix& rMatrix = aMatrices[a];
109 				    basegfx::B2DPolygon aNewLine;
110 
111 				    aNewLine.append(rMatrix * aStart);
112 				    aNewLine.append(rMatrix * aEnd);
113 
114 				    // create hairline
115 				    const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aNewLine, aHatchColor));
116 				    aRetval[bFillBackground ? (a + 1) : a] = xRef;
117 			    }
118             }
119 
120             return aRetval;
121 		}
122 
123 		FillHatchPrimitive2D::FillHatchPrimitive2D(
124 			const basegfx::B2DRange& rObjectRange,
125 			const basegfx::BColor& rBColor,
126 			const attribute::FillHatchAttribute& rFillHatch)
127 		:	BufferedDecompositionPrimitive2D(),
128 			maObjectRange(rObjectRange),
129 			maFillHatch(rFillHatch),
130 			maBColor(rBColor)
131 		{
132 		}
133 
134 		bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
135 		{
136 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
137 			{
138 				const FillHatchPrimitive2D& rCompare = (FillHatchPrimitive2D&)rPrimitive;
139 
140 				return (getObjectRange() == rCompare.getObjectRange()
141 					&& getFillHatch() == rCompare.getFillHatch()
142 					&& getBColor() == rCompare.getBColor());
143 			}
144 
145 			return false;
146 		}
147 
148 		basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
149 		{
150 			// return ObjectRange
151 			return getObjectRange();
152 		}
153 
154 		// provide unique ID
155 		ImplPrimitrive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D)
156 
157 	} // end of namespace primitive2d
158 } // end of namespace drawinglayer
159 
160 //////////////////////////////////////////////////////////////////////////////
161 // eof
162