update dev300-m58
[ooovba.git] / drawinglayer / source / primitive2d / borderlineprimitive2d.cxx
bloba2fda82d8f7a74c564469d168659d101cac0a826
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: borderlineprimitive2d.cxx,v $
7 * $Revision: 1.5 $
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/borderlineprimitive2d.hxx>
40 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
41 #include <basegfx/polygon/b2dpolygon.hxx>
42 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
43 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
44 #include <numeric>
46 //////////////////////////////////////////////////////////////////////////////
48 namespace drawinglayer
50 namespace primitive2d
52 Primitive2DSequence BorderLinePrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
54 Primitive2DSequence xRetval;
56 if(!getStart().equal(getEnd()) && (getCreateInside() || getCreateOutside()))
58 if(isInsideUsed())
60 // get data and vectors
61 const double fWidth(getWidth());
62 basegfx::B2DVector aVector(getEnd() - getStart());
63 aVector.normalize();
64 const basegfx::B2DVector aPerpendicular(basegfx::getPerpendicular(aVector));
66 if(isOutsideUsed())
68 // both used, double line definition. Create left and right offset
69 xRetval.realloc(getCreateInside() && getCreateOutside() ? 2 : 1);
70 sal_uInt32 nInsert(0);
72 if(getCreateInside())
74 // create geometry for left
75 const basegfx::B2DVector aLeftOff(aPerpendicular * (0.5 * (getCorrectedLeftWidth() - fWidth)));
76 const basegfx::B2DPoint aTmpStart(getStart() + aLeftOff - (getExtendInnerStart() * aVector));
77 const basegfx::B2DPoint aTmpEnd(getEnd() + aLeftOff + (getExtendInnerEnd() * aVector));
78 basegfx::B2DPolygon aLeft;
80 if(leftIsHairline())
82 // create hairline primitive
83 aLeft.append(aTmpStart);
84 aLeft.append(aTmpEnd);
86 xRetval[nInsert++] = Primitive2DReference(new PolygonHairlinePrimitive2D(
87 aLeft,
88 getRGBColor()));
90 else
92 // create filled polygon primitive. Already tried to create thick lines
93 // with the correct LineWidth, but this leads to problems when no AA
94 // is available and fat line special case reductions between 0.5 < x < 2.5 line widths
95 // are executed due to the FilledPolygon-do-not-paint-their-bottom-and-right-lines.
96 const basegfx::B2DVector aLineWidthOffset((getCorrectedLeftWidth() * 0.5) * aPerpendicular);
98 aLeft.append(aTmpStart + aLineWidthOffset);
99 aLeft.append(aTmpEnd + aLineWidthOffset);
100 aLeft.append(aTmpEnd - aLineWidthOffset);
101 aLeft.append(aTmpStart - aLineWidthOffset);
102 aLeft.setClosed(true);
104 xRetval[nInsert++] = Primitive2DReference(new PolyPolygonColorPrimitive2D(
105 basegfx::B2DPolyPolygon(aLeft), getRGBColor()));
109 if(getCreateOutside())
111 // create geometry for right
112 const basegfx::B2DVector aRightOff(aPerpendicular * (0.5 * (fWidth - getCorrectedRightWidth())));
113 const basegfx::B2DPoint aTmpStart(getStart() + aRightOff - (getExtendOuterStart() * aVector));
114 const basegfx::B2DPoint aTmpEnd(getEnd() + aRightOff + (getExtendOuterEnd() * aVector));
115 basegfx::B2DPolygon aRight;
117 if(rightIsHairline())
119 // create hairline primitive
120 aRight.append(aTmpStart);
121 aRight.append(aTmpEnd);
123 xRetval[nInsert++] = Primitive2DReference(new PolygonHairlinePrimitive2D(
124 aRight,
125 getRGBColor()));
127 else
129 // create filled polygon primitive
130 const basegfx::B2DVector aLineWidthOffset((getCorrectedRightWidth() * 0.5) * aPerpendicular);
132 aRight.append(aTmpStart + aLineWidthOffset);
133 aRight.append(aTmpEnd + aLineWidthOffset);
134 aRight.append(aTmpEnd - aLineWidthOffset);
135 aRight.append(aTmpStart - aLineWidthOffset);
136 aRight.setClosed(true);
138 xRetval[nInsert++] = Primitive2DReference(new PolyPolygonColorPrimitive2D(
139 basegfx::B2DPolyPolygon(aRight), getRGBColor()));
143 else
145 // single line, create geometry
146 basegfx::B2DPolygon aPolygon;
147 const double fMaxExtStart(::std::max(getExtendInnerStart(), getExtendOuterStart()));
148 const double fMaxExtEnd(::std::max(getExtendInnerEnd(), getExtendOuterEnd()));
149 const basegfx::B2DPoint aTmpStart(getStart() - (fMaxExtStart * aVector));
150 const basegfx::B2DPoint aTmpEnd(getEnd() + (fMaxExtEnd * aVector));
151 xRetval.realloc(1);
153 if(leftIsHairline())
155 // create hairline primitive
156 aPolygon.append(aTmpStart);
157 aPolygon.append(aTmpEnd);
159 xRetval[0] = Primitive2DReference(new PolygonHairlinePrimitive2D(
160 aPolygon,
161 getRGBColor()));
163 else
165 // create filled polygon primitive
166 const basegfx::B2DVector aLineWidthOffset((getCorrectedLeftWidth() * 0.5) * aPerpendicular);
168 aPolygon.append(aTmpStart + aLineWidthOffset);
169 aPolygon.append(aTmpEnd + aLineWidthOffset);
170 aPolygon.append(aTmpEnd - aLineWidthOffset);
171 aPolygon.append(aTmpStart - aLineWidthOffset);
172 aPolygon.setClosed(true);
174 xRetval[0] = Primitive2DReference(new PolyPolygonColorPrimitive2D(
175 basegfx::B2DPolyPolygon(aPolygon), getRGBColor()));
181 return xRetval;
184 BorderLinePrimitive2D::BorderLinePrimitive2D(
185 const basegfx::B2DPoint& rStart,
186 const basegfx::B2DPoint& rEnd,
187 double fLeftWidth,
188 double fDistance,
189 double fRightWidth,
190 double fExtendInnerStart,
191 double fExtendInnerEnd,
192 double fExtendOuterStart,
193 double fExtendOuterEnd,
194 bool bCreateInside,
195 bool bCreateOutside,
196 const basegfx::BColor& rRGBColor)
197 : BasePrimitive2D(),
198 maStart(rStart),
199 maEnd(rEnd),
200 mfLeftWidth(fLeftWidth),
201 mfDistance(fDistance),
202 mfRightWidth(fRightWidth),
203 mfExtendInnerStart(fExtendInnerStart),
204 mfExtendInnerEnd(fExtendInnerEnd),
205 mfExtendOuterStart(fExtendOuterStart),
206 mfExtendOuterEnd(fExtendOuterEnd),
207 maRGBColor(rRGBColor),
208 mbCreateInside(bCreateInside),
209 mbCreateOutside(bCreateOutside)
213 bool BorderLinePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
215 if(BasePrimitive2D::operator==(rPrimitive))
217 const BorderLinePrimitive2D& rCompare = (BorderLinePrimitive2D&)rPrimitive;
219 return (getStart() == rCompare.getStart()
220 && getEnd() == rCompare.getEnd()
221 && getLeftWidth() == rCompare.getLeftWidth()
222 && getDistance() == rCompare.getDistance()
223 && getRightWidth() == rCompare.getRightWidth()
224 && getExtendInnerStart() == rCompare.getExtendInnerStart()
225 && getExtendInnerEnd() == rCompare.getExtendInnerEnd()
226 && getExtendOuterStart() == rCompare.getExtendOuterStart()
227 && getExtendOuterEnd() == rCompare.getExtendOuterEnd()
228 && getCreateInside() == rCompare.getCreateInside()
229 && getCreateOutside() == rCompare.getCreateOutside()
230 && getRGBColor() == rCompare.getRGBColor());
233 return false;
236 // provide unique ID
237 ImplPrimitrive2DIDBlock(BorderLinePrimitive2D, PRIMITIVE2D_ID_BORDERLINEPRIMITIVE2D)
239 } // end of namespace primitive2d
240 } // end of namespace drawinglayer
242 //////////////////////////////////////////////////////////////////////////////
243 // eof