xref: /trunk/main/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*464702f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*464702f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*464702f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*464702f4SAndrew Rist  * distributed with this work for additional information
6*464702f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*464702f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*464702f4SAndrew Rist  * "License"); you may not use this file except in compliance
9*464702f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*464702f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*464702f4SAndrew Rist  * software distributed under the License is distributed on an
15*464702f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*464702f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*464702f4SAndrew Rist  * specific language governing permissions and limitations
18*464702f4SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*464702f4SAndrew Rist  *************************************************************/
21*464702f4SAndrew Rist 
22*464702f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <drawinglayer/primitive2d/borderlineprimitive2d.hxx>
28cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
29cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
30cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
31cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
32cdf0e10cSrcweir #include <numeric>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace drawinglayer
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     namespace primitive2d
39cdf0e10cSrcweir     {
create2DDecomposition(const geometry::ViewInformation2D &) const40cdf0e10cSrcweir         Primitive2DSequence BorderLinePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
41cdf0e10cSrcweir         {
42cdf0e10cSrcweir             Primitive2DSequence xRetval;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir             if(!getStart().equal(getEnd()) && (getCreateInside() || getCreateOutside()))
45cdf0e10cSrcweir             {
46cdf0e10cSrcweir                 if(isInsideUsed())
47cdf0e10cSrcweir                 {
48cdf0e10cSrcweir                     // get data and vectors
49cdf0e10cSrcweir                     const double fWidth(getWidth());
50cdf0e10cSrcweir                     basegfx::B2DVector aVector(getEnd() - getStart());
51cdf0e10cSrcweir                     aVector.normalize();
52cdf0e10cSrcweir                     const basegfx::B2DVector aPerpendicular(basegfx::getPerpendicular(aVector));
53cdf0e10cSrcweir 
54cdf0e10cSrcweir                     if(isOutsideUsed())
55cdf0e10cSrcweir                     {
56cdf0e10cSrcweir                         // both used, double line definition. Create left and right offset
57cdf0e10cSrcweir                         xRetval.realloc(getCreateInside() && getCreateOutside() ? 2 : 1);
58cdf0e10cSrcweir                         sal_uInt32 nInsert(0);
59cdf0e10cSrcweir 
60cdf0e10cSrcweir                         if(getCreateInside())
61cdf0e10cSrcweir                         {
62cdf0e10cSrcweir                             // create geometry for left
63cdf0e10cSrcweir                             const basegfx::B2DVector aLeftOff(aPerpendicular * (0.5 * (getCorrectedLeftWidth() - fWidth)));
64cdf0e10cSrcweir                             const basegfx::B2DPoint aTmpStart(getStart() + aLeftOff - (getExtendInnerStart() * aVector));
65cdf0e10cSrcweir                             const basegfx::B2DPoint aTmpEnd(getEnd() + aLeftOff + (getExtendInnerEnd() * aVector));
66cdf0e10cSrcweir                             basegfx::B2DPolygon aLeft;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir                             if(leftIsHairline())
69cdf0e10cSrcweir                             {
70cdf0e10cSrcweir                                 // create hairline primitive
71cdf0e10cSrcweir                                 aLeft.append(aTmpStart);
72cdf0e10cSrcweir                                 aLeft.append(aTmpEnd);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir                                 xRetval[nInsert++] = Primitive2DReference(new PolygonHairlinePrimitive2D(
75cdf0e10cSrcweir                                     aLeft,
76cdf0e10cSrcweir                                     getRGBColor()));
77cdf0e10cSrcweir                             }
78cdf0e10cSrcweir                             else
79cdf0e10cSrcweir                             {
80cdf0e10cSrcweir                                 // create filled polygon primitive. Already tried to create thick lines
81cdf0e10cSrcweir                                 // with the correct LineWidth, but this leads to problems when no AA
82cdf0e10cSrcweir                                 // is available and fat line special case reductions between 0.5 < x < 2.5 line widths
83cdf0e10cSrcweir                                 // are executed due to the FilledPolygon-do-not-paint-their-bottom-and-right-lines.
84cdf0e10cSrcweir                                 const basegfx::B2DVector aLineWidthOffset((getCorrectedLeftWidth() * 0.5) * aPerpendicular);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir                                 aLeft.append(aTmpStart + aLineWidthOffset);
87cdf0e10cSrcweir                                 aLeft.append(aTmpEnd + aLineWidthOffset);
88cdf0e10cSrcweir                                 aLeft.append(aTmpEnd - aLineWidthOffset);
89cdf0e10cSrcweir                                 aLeft.append(aTmpStart - aLineWidthOffset);
90cdf0e10cSrcweir                                 aLeft.setClosed(true);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir                                 xRetval[nInsert++] = Primitive2DReference(new PolyPolygonColorPrimitive2D(
93cdf0e10cSrcweir                                     basegfx::B2DPolyPolygon(aLeft), getRGBColor()));
94cdf0e10cSrcweir                             }
95cdf0e10cSrcweir                         }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir                         if(getCreateOutside())
98cdf0e10cSrcweir                         {
99cdf0e10cSrcweir                             // create geometry for right
100cdf0e10cSrcweir                             const basegfx::B2DVector aRightOff(aPerpendicular * (0.5 * (fWidth - getCorrectedRightWidth())));
101cdf0e10cSrcweir                             const basegfx::B2DPoint aTmpStart(getStart() + aRightOff - (getExtendOuterStart() * aVector));
102cdf0e10cSrcweir                             const basegfx::B2DPoint aTmpEnd(getEnd() + aRightOff + (getExtendOuterEnd() * aVector));
103cdf0e10cSrcweir                             basegfx::B2DPolygon aRight;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir                             if(rightIsHairline())
106cdf0e10cSrcweir                             {
107cdf0e10cSrcweir                                 // create hairline primitive
108cdf0e10cSrcweir                                 aRight.append(aTmpStart);
109cdf0e10cSrcweir                                 aRight.append(aTmpEnd);
110cdf0e10cSrcweir 
111cdf0e10cSrcweir                                 xRetval[nInsert++] = Primitive2DReference(new PolygonHairlinePrimitive2D(
112cdf0e10cSrcweir                                     aRight,
113cdf0e10cSrcweir                                     getRGBColor()));
114cdf0e10cSrcweir                             }
115cdf0e10cSrcweir                             else
116cdf0e10cSrcweir                             {
117cdf0e10cSrcweir                                 // create filled polygon primitive
118cdf0e10cSrcweir                                 const basegfx::B2DVector aLineWidthOffset((getCorrectedRightWidth() * 0.5) * aPerpendicular);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir                                 aRight.append(aTmpStart + aLineWidthOffset);
121cdf0e10cSrcweir                                 aRight.append(aTmpEnd + aLineWidthOffset);
122cdf0e10cSrcweir                                 aRight.append(aTmpEnd - aLineWidthOffset);
123cdf0e10cSrcweir                                 aRight.append(aTmpStart - aLineWidthOffset);
124cdf0e10cSrcweir                                 aRight.setClosed(true);
125cdf0e10cSrcweir 
126cdf0e10cSrcweir                                 xRetval[nInsert++] = Primitive2DReference(new PolyPolygonColorPrimitive2D(
127cdf0e10cSrcweir                                     basegfx::B2DPolyPolygon(aRight), getRGBColor()));
128cdf0e10cSrcweir                             }
129cdf0e10cSrcweir                         }
130cdf0e10cSrcweir                     }
131cdf0e10cSrcweir                     else
132cdf0e10cSrcweir                     {
133cdf0e10cSrcweir                         // single line, create geometry
134cdf0e10cSrcweir                         basegfx::B2DPolygon aPolygon;
135cdf0e10cSrcweir                         const double fMaxExtStart(::std::max(getExtendInnerStart(), getExtendOuterStart()));
136cdf0e10cSrcweir                         const double fMaxExtEnd(::std::max(getExtendInnerEnd(), getExtendOuterEnd()));
137cdf0e10cSrcweir                         const basegfx::B2DPoint aTmpStart(getStart() - (fMaxExtStart * aVector));
138cdf0e10cSrcweir                         const basegfx::B2DPoint aTmpEnd(getEnd() + (fMaxExtEnd * aVector));
139cdf0e10cSrcweir                         xRetval.realloc(1);
140cdf0e10cSrcweir 
141cdf0e10cSrcweir                         if(leftIsHairline())
142cdf0e10cSrcweir                         {
143cdf0e10cSrcweir                             // create hairline primitive
144cdf0e10cSrcweir                             aPolygon.append(aTmpStart);
145cdf0e10cSrcweir                             aPolygon.append(aTmpEnd);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir                             xRetval[0] = Primitive2DReference(new PolygonHairlinePrimitive2D(
148cdf0e10cSrcweir                                 aPolygon,
149cdf0e10cSrcweir                                 getRGBColor()));
150cdf0e10cSrcweir                         }
151cdf0e10cSrcweir                         else
152cdf0e10cSrcweir                         {
153cdf0e10cSrcweir                             // create filled polygon primitive
154cdf0e10cSrcweir                             const basegfx::B2DVector aLineWidthOffset((getCorrectedLeftWidth() * 0.5) * aPerpendicular);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir                             aPolygon.append(aTmpStart + aLineWidthOffset);
157cdf0e10cSrcweir                             aPolygon.append(aTmpEnd + aLineWidthOffset);
158cdf0e10cSrcweir                             aPolygon.append(aTmpEnd - aLineWidthOffset);
159cdf0e10cSrcweir                             aPolygon.append(aTmpStart - aLineWidthOffset);
160cdf0e10cSrcweir                             aPolygon.setClosed(true);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir                             xRetval[0] = Primitive2DReference(new PolyPolygonColorPrimitive2D(
163cdf0e10cSrcweir                                 basegfx::B2DPolyPolygon(aPolygon), getRGBColor()));
164cdf0e10cSrcweir                         }
165cdf0e10cSrcweir                     }
166cdf0e10cSrcweir                 }
167cdf0e10cSrcweir             }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir             return xRetval;
170cdf0e10cSrcweir         }
171cdf0e10cSrcweir 
BorderLinePrimitive2D(const basegfx::B2DPoint & rStart,const basegfx::B2DPoint & rEnd,double fLeftWidth,double fDistance,double fRightWidth,double fExtendInnerStart,double fExtendInnerEnd,double fExtendOuterStart,double fExtendOuterEnd,bool bCreateInside,bool bCreateOutside,const basegfx::BColor & rRGBColor)172cdf0e10cSrcweir         BorderLinePrimitive2D::BorderLinePrimitive2D(
173cdf0e10cSrcweir             const basegfx::B2DPoint& rStart,
174cdf0e10cSrcweir             const basegfx::B2DPoint& rEnd,
175cdf0e10cSrcweir             double fLeftWidth,
176cdf0e10cSrcweir             double fDistance,
177cdf0e10cSrcweir             double fRightWidth,
178cdf0e10cSrcweir             double fExtendInnerStart,
179cdf0e10cSrcweir             double fExtendInnerEnd,
180cdf0e10cSrcweir             double fExtendOuterStart,
181cdf0e10cSrcweir             double fExtendOuterEnd,
182cdf0e10cSrcweir             bool bCreateInside,
183cdf0e10cSrcweir             bool bCreateOutside,
184cdf0e10cSrcweir             const basegfx::BColor& rRGBColor)
185cdf0e10cSrcweir         :   BufferedDecompositionPrimitive2D(),
186cdf0e10cSrcweir             maStart(rStart),
187cdf0e10cSrcweir             maEnd(rEnd),
188cdf0e10cSrcweir             mfLeftWidth(fLeftWidth),
189cdf0e10cSrcweir             mfDistance(fDistance),
190cdf0e10cSrcweir             mfRightWidth(fRightWidth),
191cdf0e10cSrcweir             mfExtendInnerStart(fExtendInnerStart),
192cdf0e10cSrcweir             mfExtendInnerEnd(fExtendInnerEnd),
193cdf0e10cSrcweir             mfExtendOuterStart(fExtendOuterStart),
194cdf0e10cSrcweir             mfExtendOuterEnd(fExtendOuterEnd),
195cdf0e10cSrcweir             maRGBColor(rRGBColor),
196cdf0e10cSrcweir             mbCreateInside(bCreateInside),
197cdf0e10cSrcweir             mbCreateOutside(bCreateOutside)
198cdf0e10cSrcweir         {
199cdf0e10cSrcweir         }
200cdf0e10cSrcweir 
operator ==(const BasePrimitive2D & rPrimitive) const201cdf0e10cSrcweir         bool BorderLinePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
202cdf0e10cSrcweir         {
203cdf0e10cSrcweir             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
204cdf0e10cSrcweir             {
205cdf0e10cSrcweir                 const BorderLinePrimitive2D& rCompare = (BorderLinePrimitive2D&)rPrimitive;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir                 return (getStart() == rCompare.getStart()
208cdf0e10cSrcweir                     && getEnd() == rCompare.getEnd()
209cdf0e10cSrcweir                     && getLeftWidth() == rCompare.getLeftWidth()
210cdf0e10cSrcweir                     && getDistance() == rCompare.getDistance()
211cdf0e10cSrcweir                     && getRightWidth() == rCompare.getRightWidth()
212cdf0e10cSrcweir                     && getExtendInnerStart() == rCompare.getExtendInnerStart()
213cdf0e10cSrcweir                     && getExtendInnerEnd() == rCompare.getExtendInnerEnd()
214cdf0e10cSrcweir                     && getExtendOuterStart() == rCompare.getExtendOuterStart()
215cdf0e10cSrcweir                     && getExtendOuterEnd() == rCompare.getExtendOuterEnd()
216cdf0e10cSrcweir                     && getCreateInside() == rCompare.getCreateInside()
217cdf0e10cSrcweir                     && getCreateOutside() == rCompare.getCreateOutside()
218cdf0e10cSrcweir                     && getRGBColor() == rCompare.getRGBColor());
219cdf0e10cSrcweir             }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir             return false;
222cdf0e10cSrcweir         }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir         // provide unique ID
225cdf0e10cSrcweir         ImplPrimitrive2DIDBlock(BorderLinePrimitive2D, PRIMITIVE2D_ID_BORDERLINEPRIMITIVE2D)
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     } // end of namespace primitive2d
228cdf0e10cSrcweir } // end of namespace drawinglayer
229cdf0e10cSrcweir 
230cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
231cdf0e10cSrcweir // eof
232