xref: /AOO41X/main/drawinglayer/source/primitive2d/polypolygonprimitive2d.cxx (revision 707fc0d4d52eb4f69d89a98ffec6918ca5de6326)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_drawinglayer.hxx"
26 
27 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
28 #include <basegfx/polygon/b2dpolypolygontools.hxx>
29 #include <basegfx/tools/canvastools.hxx>
30 #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
31 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
32 #include <drawinglayer/primitive2d/fillhatchprimitive2d.hxx>
33 #include <basegfx/matrix/b2dhommatrix.hxx>
34 #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
35 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
36 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 using namespace com::sun::star;
41 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 namespace drawinglayer
45 {
46     namespace primitive2d
47     {
48         Primitive2DSequence PolyPolygonHairlinePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
49         {
50             const basegfx::B2DPolyPolygon aPolyPolygon(getB2DPolyPolygon());
51             const sal_uInt32 nCount(aPolyPolygon.count());
52 
53             if(nCount)
54             {
55                 Primitive2DSequence aRetval(nCount);
56 
57                 for(sal_uInt32 a(0L); a < nCount; a++)
58                 {
59                     aRetval[a] = Primitive2DReference(new PolygonHairlinePrimitive2D(aPolyPolygon.getB2DPolygon(a), getBColor()));
60                 }
61 
62                 return aRetval;
63             }
64             else
65             {
66                 return Primitive2DSequence();
67             }
68         }
69 
70         PolyPolygonHairlinePrimitive2D::PolyPolygonHairlinePrimitive2D(const basegfx::B2DPolyPolygon& rPolyPolygon, const basegfx::BColor& rBColor)
71         :   BufferedDecompositionPrimitive2D(),
72             maPolyPolygon(rPolyPolygon),
73             maBColor(rBColor)
74         {
75         }
76 
77         bool PolyPolygonHairlinePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
78         {
79             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
80             {
81                 const PolyPolygonHairlinePrimitive2D& rCompare = (PolyPolygonHairlinePrimitive2D&)rPrimitive;
82 
83                 return (getB2DPolyPolygon() == rCompare.getB2DPolyPolygon()
84                     && getBColor() == rCompare.getBColor());
85             }
86 
87             return false;
88         }
89 
90         basegfx::B2DRange PolyPolygonHairlinePrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
91         {
92             // return range
93             return basegfx::tools::getRange(getB2DPolyPolygon());
94         }
95 
96         // provide unique ID
97         ImplPrimitrive2DIDBlock(PolyPolygonHairlinePrimitive2D, PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D)
98 
99     } // end of namespace primitive2d
100 } // end of namespace drawinglayer
101 
102 //////////////////////////////////////////////////////////////////////////////
103 
104 namespace drawinglayer
105 {
106     namespace primitive2d
107     {
108         Primitive2DSequence PolyPolygonMarkerPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
109         {
110             const basegfx::B2DPolyPolygon aPolyPolygon(getB2DPolyPolygon());
111             const sal_uInt32 nCount(aPolyPolygon.count());
112 
113             if(nCount)
114             {
115                 Primitive2DSequence aRetval(nCount);
116 
117                 for(sal_uInt32 a(0L); a < nCount; a++)
118                 {
119                     aRetval[a] = Primitive2DReference(new PolygonMarkerPrimitive2D(aPolyPolygon.getB2DPolygon(a), getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
120                 }
121 
122                 return aRetval;
123             }
124             else
125             {
126                 return Primitive2DSequence();
127             }
128         }
129 
130         PolyPolygonMarkerPrimitive2D::PolyPolygonMarkerPrimitive2D(
131             const basegfx::B2DPolyPolygon& rPolyPolygon,
132             const basegfx::BColor& rRGBColorA,
133             const basegfx::BColor& rRGBColorB,
134             double fDiscreteDashLength)
135         :   BufferedDecompositionPrimitive2D(),
136             maPolyPolygon(rPolyPolygon),
137             maRGBColorA(rRGBColorA),
138             maRGBColorB(rRGBColorB),
139             mfDiscreteDashLength(fDiscreteDashLength)
140         {
141         }
142 
143         bool PolyPolygonMarkerPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
144         {
145             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
146             {
147                 const PolyPolygonMarkerPrimitive2D& rCompare = (PolyPolygonMarkerPrimitive2D&)rPrimitive;
148 
149                 return (getB2DPolyPolygon() == rCompare.getB2DPolyPolygon()
150                     && getRGBColorA() == rCompare.getRGBColorA()
151                     && getRGBColorB() == rCompare.getRGBColorB()
152                     && getDiscreteDashLength() == rCompare.getDiscreteDashLength());
153             }
154 
155             return false;
156         }
157 
158         basegfx::B2DRange PolyPolygonMarkerPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
159         {
160             // return range
161             return basegfx::tools::getRange(getB2DPolyPolygon());
162         }
163 
164         // provide unique ID
165         ImplPrimitrive2DIDBlock(PolyPolygonMarkerPrimitive2D, PRIMITIVE2D_ID_POLYPOLYGONMARKERPRIMITIVE2D)
166 
167     } // end of namespace primitive2d
168 } // end of namespace drawinglayer
169 
170 //////////////////////////////////////////////////////////////////////////////
171 
172 namespace drawinglayer
173 {
174     namespace primitive2d
175     {
176         Primitive2DSequence PolyPolygonStrokePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
177         {
178             const basegfx::B2DPolyPolygon aPolyPolygon(getB2DPolyPolygon());
179             const sal_uInt32 nCount(aPolyPolygon.count());
180 
181             if(nCount)
182             {
183                 Primitive2DSequence aRetval(nCount);
184 
185                 for(sal_uInt32 a(0L); a < nCount; a++)
186                 {
187                     aRetval[a] = Primitive2DReference(
188                         new PolygonStrokePrimitive2D(
189                             aPolyPolygon.getB2DPolygon(a), getLineAttribute(), getStrokeAttribute()));
190                 }
191 
192                 return aRetval;
193             }
194             else
195             {
196                 return Primitive2DSequence();
197             }
198         }
199 
200         PolyPolygonStrokePrimitive2D::PolyPolygonStrokePrimitive2D(
201             const basegfx::B2DPolyPolygon& rPolyPolygon,
202             const attribute::LineAttribute& rLineAttribute,
203             const attribute::StrokeAttribute& rStrokeAttribute)
204         :   BufferedDecompositionPrimitive2D(),
205             maPolyPolygon(rPolyPolygon),
206             maLineAttribute(rLineAttribute),
207             maStrokeAttribute(rStrokeAttribute)
208         {
209         }
210 
211         PolyPolygonStrokePrimitive2D::PolyPolygonStrokePrimitive2D(
212             const basegfx::B2DPolyPolygon& rPolyPolygon,
213             const attribute::LineAttribute& rLineAttribute)
214         :   BufferedDecompositionPrimitive2D(),
215             maPolyPolygon(rPolyPolygon),
216             maLineAttribute(rLineAttribute),
217             maStrokeAttribute()
218         {
219         }
220 
221         bool PolyPolygonStrokePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
222         {
223             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
224             {
225                 const PolyPolygonStrokePrimitive2D& rCompare = (PolyPolygonStrokePrimitive2D&)rPrimitive;
226 
227                 return (getB2DPolyPolygon() == rCompare.getB2DPolyPolygon()
228                     && getLineAttribute() == rCompare.getLineAttribute()
229                     && getStrokeAttribute() == rCompare.getStrokeAttribute());
230             }
231 
232             return false;
233         }
234 
235         basegfx::B2DRange PolyPolygonStrokePrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
236         {
237             // get range of it (subdivided)
238             basegfx::B2DRange aRetval(basegfx::tools::getRange(getB2DPolyPolygon()));
239 
240             // if width, grow by line width
241             if(getLineAttribute().getWidth())
242             {
243                 aRetval.grow(getLineAttribute().getWidth() / 2.0);
244             }
245 
246             return aRetval;
247         }
248 
249         // provide unique ID
250         ImplPrimitrive2DIDBlock(PolyPolygonStrokePrimitive2D, PRIMITIVE2D_ID_POLYPOLYGONSTROKEPRIMITIVE2D)
251 
252     } // end of namespace primitive2d
253 } // end of namespace drawinglayer
254 
255 //////////////////////////////////////////////////////////////////////////////
256 
257 namespace drawinglayer
258 {
259     namespace primitive2d
260     {
261         Primitive2DSequence PolyPolygonStrokeArrowPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
262         {
263             const basegfx::B2DPolyPolygon aPolyPolygon(getB2DPolyPolygon());
264             const sal_uInt32 nCount(aPolyPolygon.count());
265 
266             if(nCount)
267             {
268                 Primitive2DSequence aRetval(nCount);
269 
270                 for(sal_uInt32 a(0L); a < nCount; a++)
271                 {
272                     const basegfx::B2DPolygon aPolygon(aPolyPolygon.getB2DPolygon(a));
273 
274                     if(aPolygon.isClosed())
275                     {
276                         // no need for PolygonStrokeArrowPrimitive2D when polygon is closed
277                         aRetval[a] = Primitive2DReference(
278                             new PolygonStrokePrimitive2D(aPolygon, getLineAttribute(), getStrokeAttribute()));
279                     }
280                     else
281                     {
282                         aRetval[a] = Primitive2DReference(
283                             new PolygonStrokeArrowPrimitive2D(aPolygon, getLineAttribute(),
284                                 getStrokeAttribute(), getStart(), getEnd()));
285                     }
286                 }
287 
288                 return aRetval;
289             }
290             else
291             {
292                 return Primitive2DSequence();
293             }
294         }
295 
296         PolyPolygonStrokeArrowPrimitive2D::PolyPolygonStrokeArrowPrimitive2D(
297             const basegfx::B2DPolyPolygon& rPolyPolygon,
298             const attribute::LineAttribute& rLineAttribute,
299             const attribute::StrokeAttribute& rStrokeAttribute,
300             const attribute::LineStartEndAttribute& rStart,
301             const attribute::LineStartEndAttribute& rEnd)
302         :   PolyPolygonStrokePrimitive2D(rPolyPolygon, rLineAttribute, rStrokeAttribute),
303             maStart(rStart),
304             maEnd(rEnd)
305         {
306         }
307 
308         PolyPolygonStrokeArrowPrimitive2D::PolyPolygonStrokeArrowPrimitive2D(
309             const basegfx::B2DPolyPolygon& rPolyPolygon,
310             const attribute::LineAttribute& rLineAttribute,
311             const attribute::LineStartEndAttribute& rStart,
312             const attribute::LineStartEndAttribute& rEnd)
313         :   PolyPolygonStrokePrimitive2D(rPolyPolygon, rLineAttribute),
314             maStart(rStart),
315             maEnd(rEnd)
316         {
317         }
318 
319         bool PolyPolygonStrokeArrowPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
320         {
321             if(PolyPolygonStrokePrimitive2D::operator==(rPrimitive))
322             {
323                 const PolyPolygonStrokeArrowPrimitive2D& rCompare = (PolyPolygonStrokeArrowPrimitive2D&)rPrimitive;
324 
325                 return (getStart() == rCompare.getStart()
326                     && getEnd() == rCompare.getEnd());
327             }
328 
329             return false;
330         }
331 
332         basegfx::B2DRange PolyPolygonStrokeArrowPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
333         {
334             basegfx::B2DRange aRetval;
335 
336             if(getStart().isActive() || getEnd().isActive())
337             {
338                 // use decomposition when line start/end is used
339                 return BufferedDecompositionPrimitive2D::getB2DRange(rViewInformation);
340             }
341             else
342             {
343                 // get range from parent
344                 return PolyPolygonStrokePrimitive2D::getB2DRange(rViewInformation);
345             }
346         }
347 
348         // provide unique ID
349         ImplPrimitrive2DIDBlock(PolyPolygonStrokeArrowPrimitive2D, PRIMITIVE2D_ID_POLYPOLYGONSTROKEARROWPRIMITIVE2D)
350 
351     } // end of namespace primitive2d
352 } // end of namespace drawinglayer
353 
354 //////////////////////////////////////////////////////////////////////////////
355 
356 namespace drawinglayer
357 {
358     namespace primitive2d
359     {
360         PolyPolygonColorPrimitive2D::PolyPolygonColorPrimitive2D(
361             const basegfx::B2DPolyPolygon& rPolyPolygon,
362             const basegfx::BColor& rBColor)
363         :   BasePrimitive2D(),
364             maPolyPolygon(rPolyPolygon),
365             maBColor(rBColor)
366         {
367         }
368 
369         bool PolyPolygonColorPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
370         {
371             if(BasePrimitive2D::operator==(rPrimitive))
372             {
373                 const PolyPolygonColorPrimitive2D& rCompare = (PolyPolygonColorPrimitive2D&)rPrimitive;
374 
375                 return (getB2DPolyPolygon() == rCompare.getB2DPolyPolygon()
376                     && getBColor() == rCompare.getBColor());
377             }
378 
379             return false;
380         }
381 
382         basegfx::B2DRange PolyPolygonColorPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
383         {
384             // return range
385             return basegfx::tools::getRange(getB2DPolyPolygon());
386         }
387 
388         // provide unique ID
389         ImplPrimitrive2DIDBlock(PolyPolygonColorPrimitive2D, PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D)
390 
391     } // end of namespace primitive2d
392 } // end of namespace drawinglayer
393 
394 //////////////////////////////////////////////////////////////////////////////
395 
396 namespace drawinglayer
397 {
398     namespace primitive2d
399     {
400         Primitive2DSequence PolyPolygonGradientPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
401         {
402             if(!getFillGradient().isDefault())
403             {
404                 // create SubSequence with FillGradientPrimitive2D
405                 const basegfx::B2DRange aPolyPolygonRange(getB2DPolyPolygon().getB2DRange());
406                 FillGradientPrimitive2D* pNewGradient = new FillGradientPrimitive2D(aPolyPolygonRange, getFillGradient());
407                 const Primitive2DReference xSubRef(pNewGradient);
408                 const Primitive2DSequence aSubSequence(&xSubRef, 1L);
409 
410                 // create mask primitive
411                 MaskPrimitive2D* pNewMask = new MaskPrimitive2D(getB2DPolyPolygon(), aSubSequence);
412                 const Primitive2DReference xRef(pNewMask);
413 
414                 return Primitive2DSequence(&xRef, 1);
415             }
416             else
417             {
418                 return Primitive2DSequence();
419             }
420         }
421 
422         PolyPolygonGradientPrimitive2D::PolyPolygonGradientPrimitive2D(
423             const basegfx::B2DPolyPolygon& rPolyPolygon,
424             const attribute::FillGradientAttribute& rFillGradient)
425         :   BufferedDecompositionPrimitive2D(),
426             maPolyPolygon(rPolyPolygon),
427             maFillGradient(rFillGradient)
428         {
429         }
430 
431         bool PolyPolygonGradientPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
432         {
433             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
434             {
435                 const PolyPolygonGradientPrimitive2D& rCompare = (PolyPolygonGradientPrimitive2D&)rPrimitive;
436 
437                 return (getFillGradient() == rCompare.getFillGradient());
438             }
439 
440             return false;
441         }
442 
443         // provide unique ID
444         ImplPrimitrive2DIDBlock(PolyPolygonGradientPrimitive2D, PRIMITIVE2D_ID_POLYPOLYGONGRADIENTPRIMITIVE2D)
445 
446     } // end of namespace primitive2d
447 } // end of namespace drawinglayer
448 
449 //////////////////////////////////////////////////////////////////////////////
450 
451 namespace drawinglayer
452 {
453     namespace primitive2d
454     {
455         Primitive2DSequence PolyPolygonHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
456         {
457             if(!getFillHatch().isDefault())
458             {
459                 // create SubSequence with FillHatchPrimitive2D
460                 const basegfx::B2DRange aPolyPolygonRange(getB2DPolyPolygon().getB2DRange());
461                 FillHatchPrimitive2D* pNewHatch = new FillHatchPrimitive2D(aPolyPolygonRange, getBackgroundColor(), getFillHatch());
462                 const Primitive2DReference xSubRef(pNewHatch);
463                 const Primitive2DSequence aSubSequence(&xSubRef, 1L);
464 
465                 // create mask primitive
466                 MaskPrimitive2D* pNewMask = new MaskPrimitive2D(getB2DPolyPolygon(), aSubSequence);
467                 const Primitive2DReference xRef(pNewMask);
468 
469                 return Primitive2DSequence(&xRef, 1);
470             }
471             else
472             {
473                 return Primitive2DSequence();
474             }
475         }
476 
477         PolyPolygonHatchPrimitive2D::PolyPolygonHatchPrimitive2D(
478             const basegfx::B2DPolyPolygon& rPolyPolygon,
479             const basegfx::BColor& rBackgroundColor,
480             const attribute::FillHatchAttribute& rFillHatch)
481         :   BufferedDecompositionPrimitive2D(),
482             maPolyPolygon(rPolyPolygon),
483             maBackgroundColor(rBackgroundColor),
484             maFillHatch(rFillHatch)
485         {
486         }
487 
488         bool PolyPolygonHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
489         {
490             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
491             {
492                 const PolyPolygonHatchPrimitive2D& rCompare = (PolyPolygonHatchPrimitive2D&)rPrimitive;
493 
494                 return (getBackgroundColor() == rCompare.getBackgroundColor()
495                     && getFillHatch() == rCompare.getFillHatch());
496             }
497 
498             return false;
499         }
500 
501         // provide unique ID
502         ImplPrimitrive2DIDBlock(PolyPolygonHatchPrimitive2D, PRIMITIVE2D_ID_POLYPOLYGONHATCHPRIMITIVE2D)
503 
504     } // end of namespace primitive2d
505 } // end of namespace drawinglayer
506 
507 //////////////////////////////////////////////////////////////////////////////
508 
509 namespace drawinglayer
510 {
511     namespace primitive2d
512     {
513         Primitive2DSequence PolyPolygonBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
514         {
515             if(!getFillBitmap().isDefault())
516             {
517                 // create SubSequence with FillBitmapPrimitive2D
518                 const basegfx::B2DRange aPolyPolygonRange(getB2DPolyPolygon().getB2DRange());
519                 basegfx::B2DHomMatrix aNewObjectTransform;
520                 aNewObjectTransform.set(0, 0, aPolyPolygonRange.getWidth());
521                 aNewObjectTransform.set(1, 1, aPolyPolygonRange.getHeight());
522                 aNewObjectTransform.set(0, 2, aPolyPolygonRange.getMinX());
523                 aNewObjectTransform.set(1, 2, aPolyPolygonRange.getMinY());
524                 FillBitmapPrimitive2D* pNewBitmap = new FillBitmapPrimitive2D(aNewObjectTransform, getFillBitmap());
525                 const Primitive2DReference xSubRef(pNewBitmap);
526                 const Primitive2DSequence aSubSequence(&xSubRef, 1L);
527 
528                 // create mask primitive
529                 MaskPrimitive2D* pNewMask = new MaskPrimitive2D(getB2DPolyPolygon(), aSubSequence);
530                 const Primitive2DReference xRef(pNewMask);
531 
532                 return Primitive2DSequence(&xRef, 1);
533             }
534             else
535             {
536                 return Primitive2DSequence();
537             }
538         }
539 
540         PolyPolygonBitmapPrimitive2D::PolyPolygonBitmapPrimitive2D(
541             const basegfx::B2DPolyPolygon& rPolyPolygon,
542             const attribute::FillBitmapAttribute& rFillBitmap)
543         :   BufferedDecompositionPrimitive2D(),
544             maPolyPolygon(rPolyPolygon),
545             maFillBitmap(rFillBitmap)
546         {
547         }
548 
549         bool PolyPolygonBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
550         {
551             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
552             {
553                 const PolyPolygonBitmapPrimitive2D& rCompare = (PolyPolygonBitmapPrimitive2D&)rPrimitive;
554 
555                 return (getFillBitmap() == rCompare.getFillBitmap());
556             }
557 
558             return false;
559         }
560 
561         // provide unique ID
562         ImplPrimitrive2DIDBlock(PolyPolygonBitmapPrimitive2D, PRIMITIVE2D_ID_POLYPOLYGONBITMAPPRIMITIVE2D)
563 
564     } // end of namespace primitive2d
565 } // end of namespace drawinglayer
566 
567 //////////////////////////////////////////////////////////////////////////////
568 // eof
569