1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolypolygontools.hxx>
22 #include <basegfx/tools/canvastools.hxx>
23 #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
24 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
25 #include <drawinglayer/primitive2d/fillhatchprimitive2d.hxx>
26 #include <basegfx/matrix/b2dhommatrix.hxx>
27 #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
28 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
29 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
31 //////////////////////////////////////////////////////////////////////////////
33 using namespace com::sun::star
;
35 //////////////////////////////////////////////////////////////////////////////
37 namespace drawinglayer
41 Primitive2DSequence
PolyPolygonHairlinePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
43 const basegfx::B2DPolyPolygon
aPolyPolygon(getB2DPolyPolygon());
44 const sal_uInt32
nCount(aPolyPolygon
.count());
48 Primitive2DSequence
aRetval(nCount
);
50 for(sal_uInt32
a(0L); a
< nCount
; a
++)
52 aRetval
[a
] = Primitive2DReference(new PolygonHairlinePrimitive2D(aPolyPolygon
.getB2DPolygon(a
), getBColor()));
59 return Primitive2DSequence();
63 PolyPolygonHairlinePrimitive2D::PolyPolygonHairlinePrimitive2D(const basegfx::B2DPolyPolygon
& rPolyPolygon
, const basegfx::BColor
& rBColor
)
64 : BufferedDecompositionPrimitive2D(),
65 maPolyPolygon(rPolyPolygon
),
70 bool PolyPolygonHairlinePrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
72 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
74 const PolyPolygonHairlinePrimitive2D
& rCompare
= (PolyPolygonHairlinePrimitive2D
&)rPrimitive
;
76 return (getB2DPolyPolygon() == rCompare
.getB2DPolyPolygon()
77 && getBColor() == rCompare
.getBColor());
83 basegfx::B2DRange
PolyPolygonHairlinePrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
86 return basegfx::tools::getRange(getB2DPolyPolygon());
90 ImplPrimitive2DIDBlock(PolyPolygonHairlinePrimitive2D
, PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D
)
92 } // end of namespace primitive2d
93 } // end of namespace drawinglayer
95 //////////////////////////////////////////////////////////////////////////////
97 namespace drawinglayer
101 Primitive2DSequence
PolyPolygonMarkerPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
103 const basegfx::B2DPolyPolygon
aPolyPolygon(getB2DPolyPolygon());
104 const sal_uInt32
nCount(aPolyPolygon
.count());
108 Primitive2DSequence
aRetval(nCount
);
110 for(sal_uInt32
a(0L); a
< nCount
; a
++)
112 aRetval
[a
] = Primitive2DReference(new PolygonMarkerPrimitive2D(aPolyPolygon
.getB2DPolygon(a
), getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
119 return Primitive2DSequence();
123 PolyPolygonMarkerPrimitive2D::PolyPolygonMarkerPrimitive2D(
124 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
125 const basegfx::BColor
& rRGBColorA
,
126 const basegfx::BColor
& rRGBColorB
,
127 double fDiscreteDashLength
)
128 : BufferedDecompositionPrimitive2D(),
129 maPolyPolygon(rPolyPolygon
),
130 maRGBColorA(rRGBColorA
),
131 maRGBColorB(rRGBColorB
),
132 mfDiscreteDashLength(fDiscreteDashLength
)
136 bool PolyPolygonMarkerPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
138 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
140 const PolyPolygonMarkerPrimitive2D
& rCompare
= (PolyPolygonMarkerPrimitive2D
&)rPrimitive
;
142 return (getB2DPolyPolygon() == rCompare
.getB2DPolyPolygon()
143 && getRGBColorA() == rCompare
.getRGBColorA()
144 && getRGBColorB() == rCompare
.getRGBColorB()
145 && getDiscreteDashLength() == rCompare
.getDiscreteDashLength());
151 basegfx::B2DRange
PolyPolygonMarkerPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
154 return basegfx::tools::getRange(getB2DPolyPolygon());
158 ImplPrimitive2DIDBlock(PolyPolygonMarkerPrimitive2D
, PRIMITIVE2D_ID_POLYPOLYGONMARKERPRIMITIVE2D
)
160 } // end of namespace primitive2d
161 } // end of namespace drawinglayer
163 //////////////////////////////////////////////////////////////////////////////
165 namespace drawinglayer
167 namespace primitive2d
169 Primitive2DSequence
PolyPolygonStrokePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
171 const basegfx::B2DPolyPolygon
aPolyPolygon(getB2DPolyPolygon());
172 const sal_uInt32
nCount(aPolyPolygon
.count());
176 Primitive2DSequence
aRetval(nCount
);
178 for(sal_uInt32
a(0L); a
< nCount
; a
++)
180 aRetval
[a
] = Primitive2DReference(
181 new PolygonStrokePrimitive2D(
182 aPolyPolygon
.getB2DPolygon(a
), getLineAttribute(), getStrokeAttribute()));
189 return Primitive2DSequence();
193 PolyPolygonStrokePrimitive2D::PolyPolygonStrokePrimitive2D(
194 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
195 const attribute::LineAttribute
& rLineAttribute
,
196 const attribute::StrokeAttribute
& rStrokeAttribute
)
197 : BufferedDecompositionPrimitive2D(),
198 maPolyPolygon(rPolyPolygon
),
199 maLineAttribute(rLineAttribute
),
200 maStrokeAttribute(rStrokeAttribute
)
204 PolyPolygonStrokePrimitive2D::PolyPolygonStrokePrimitive2D(
205 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
206 const attribute::LineAttribute
& rLineAttribute
)
207 : BufferedDecompositionPrimitive2D(),
208 maPolyPolygon(rPolyPolygon
),
209 maLineAttribute(rLineAttribute
),
214 bool PolyPolygonStrokePrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
216 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
218 const PolyPolygonStrokePrimitive2D
& rCompare
= (PolyPolygonStrokePrimitive2D
&)rPrimitive
;
220 return (getB2DPolyPolygon() == rCompare
.getB2DPolyPolygon()
221 && getLineAttribute() == rCompare
.getLineAttribute()
222 && getStrokeAttribute() == rCompare
.getStrokeAttribute());
228 basegfx::B2DRange
PolyPolygonStrokePrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
230 // get range of it (subdivided)
231 basegfx::B2DRange
aRetval(basegfx::tools::getRange(getB2DPolyPolygon()));
233 // if width, grow by line width
234 if(getLineAttribute().getWidth())
236 aRetval
.grow(getLineAttribute().getWidth() / 2.0);
243 ImplPrimitive2DIDBlock(PolyPolygonStrokePrimitive2D
, PRIMITIVE2D_ID_POLYPOLYGONSTROKEPRIMITIVE2D
)
245 } // end of namespace primitive2d
246 } // end of namespace drawinglayer
248 //////////////////////////////////////////////////////////////////////////////
250 namespace drawinglayer
252 namespace primitive2d
254 PolyPolygonColorPrimitive2D::PolyPolygonColorPrimitive2D(
255 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
256 const basegfx::BColor
& rBColor
)
258 maPolyPolygon(rPolyPolygon
),
263 bool PolyPolygonColorPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
265 if(BasePrimitive2D::operator==(rPrimitive
))
267 const PolyPolygonColorPrimitive2D
& rCompare
= (PolyPolygonColorPrimitive2D
&)rPrimitive
;
269 return (getB2DPolyPolygon() == rCompare
.getB2DPolyPolygon()
270 && getBColor() == rCompare
.getBColor());
276 basegfx::B2DRange
PolyPolygonColorPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
279 return basegfx::tools::getRange(getB2DPolyPolygon());
283 ImplPrimitive2DIDBlock(PolyPolygonColorPrimitive2D
, PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D
)
285 } // end of namespace primitive2d
286 } // end of namespace drawinglayer
288 //////////////////////////////////////////////////////////////////////////////
290 namespace drawinglayer
292 namespace primitive2d
294 Primitive2DSequence
PolyPolygonGradientPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
296 if(!getFillGradient().isDefault())
298 // create SubSequence with FillGradientPrimitive2D
299 const basegfx::B2DRange
aPolyPolygonRange(getB2DPolyPolygon().getB2DRange());
300 FillGradientPrimitive2D
* pNewGradient
= new FillGradientPrimitive2D(aPolyPolygonRange
, getFillGradient());
301 const Primitive2DReference
xSubRef(pNewGradient
);
302 const Primitive2DSequence
aSubSequence(&xSubRef
, 1L);
304 // create mask primitive
305 MaskPrimitive2D
* pNewMask
= new MaskPrimitive2D(getB2DPolyPolygon(), aSubSequence
);
306 const Primitive2DReference
xRef(pNewMask
);
308 return Primitive2DSequence(&xRef
, 1);
312 return Primitive2DSequence();
316 PolyPolygonGradientPrimitive2D::PolyPolygonGradientPrimitive2D(
317 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
318 const attribute::FillGradientAttribute
& rFillGradient
)
319 : BufferedDecompositionPrimitive2D(),
320 maPolyPolygon(rPolyPolygon
),
321 maFillGradient(rFillGradient
)
325 bool PolyPolygonGradientPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
327 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
329 const PolyPolygonGradientPrimitive2D
& rCompare
= (PolyPolygonGradientPrimitive2D
&)rPrimitive
;
331 return (getFillGradient() == rCompare
.getFillGradient());
338 ImplPrimitive2DIDBlock(PolyPolygonGradientPrimitive2D
, PRIMITIVE2D_ID_POLYPOLYGONGRADIENTPRIMITIVE2D
)
340 } // end of namespace primitive2d
341 } // end of namespace drawinglayer
343 //////////////////////////////////////////////////////////////////////////////
345 namespace drawinglayer
347 namespace primitive2d
349 Primitive2DSequence
PolyPolygonHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
351 if(!getFillHatch().isDefault())
353 // create SubSequence with FillHatchPrimitive2D
354 const basegfx::B2DRange
aPolyPolygonRange(getB2DPolyPolygon().getB2DRange());
355 FillHatchPrimitive2D
* pNewHatch
= new FillHatchPrimitive2D(aPolyPolygonRange
, getBackgroundColor(), getFillHatch());
356 const Primitive2DReference
xSubRef(pNewHatch
);
357 const Primitive2DSequence
aSubSequence(&xSubRef
, 1L);
359 // create mask primitive
360 MaskPrimitive2D
* pNewMask
= new MaskPrimitive2D(getB2DPolyPolygon(), aSubSequence
);
361 const Primitive2DReference
xRef(pNewMask
);
363 return Primitive2DSequence(&xRef
, 1);
367 return Primitive2DSequence();
371 PolyPolygonHatchPrimitive2D::PolyPolygonHatchPrimitive2D(
372 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
373 const basegfx::BColor
& rBackgroundColor
,
374 const attribute::FillHatchAttribute
& rFillHatch
)
375 : BufferedDecompositionPrimitive2D(),
376 maPolyPolygon(rPolyPolygon
),
377 maBackgroundColor(rBackgroundColor
),
378 maFillHatch(rFillHatch
)
382 bool PolyPolygonHatchPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
384 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
386 const PolyPolygonHatchPrimitive2D
& rCompare
= (PolyPolygonHatchPrimitive2D
&)rPrimitive
;
388 return (getBackgroundColor() == rCompare
.getBackgroundColor()
389 && getFillHatch() == rCompare
.getFillHatch());
396 ImplPrimitive2DIDBlock(PolyPolygonHatchPrimitive2D
, PRIMITIVE2D_ID_POLYPOLYGONHATCHPRIMITIVE2D
)
398 } // end of namespace primitive2d
399 } // end of namespace drawinglayer
401 //////////////////////////////////////////////////////////////////////////////
403 namespace drawinglayer
405 namespace primitive2d
407 Primitive2DSequence
PolyPolygonBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
409 if(!getFillBitmap().isDefault())
411 // create SubSequence with FillBitmapPrimitive2D
412 const basegfx::B2DRange
aPolyPolygonRange(getB2DPolyPolygon().getB2DRange());
413 basegfx::B2DHomMatrix aNewObjectTransform
;
414 aNewObjectTransform
.set(0, 0, aPolyPolygonRange
.getWidth());
415 aNewObjectTransform
.set(1, 1, aPolyPolygonRange
.getHeight());
416 aNewObjectTransform
.set(0, 2, aPolyPolygonRange
.getMinX());
417 aNewObjectTransform
.set(1, 2, aPolyPolygonRange
.getMinY());
418 FillBitmapPrimitive2D
* pNewBitmap
= new FillBitmapPrimitive2D(aNewObjectTransform
, getFillBitmap());
419 const Primitive2DReference
xSubRef(pNewBitmap
);
420 const Primitive2DSequence
aSubSequence(&xSubRef
, 1L);
422 // create mask primitive
423 MaskPrimitive2D
* pNewMask
= new MaskPrimitive2D(getB2DPolyPolygon(), aSubSequence
);
424 const Primitive2DReference
xRef(pNewMask
);
426 return Primitive2DSequence(&xRef
, 1);
430 return Primitive2DSequence();
434 PolyPolygonBitmapPrimitive2D::PolyPolygonBitmapPrimitive2D(
435 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
436 const attribute::FillBitmapAttribute
& rFillBitmap
)
437 : BufferedDecompositionPrimitive2D(),
438 maPolyPolygon(rPolyPolygon
),
439 maFillBitmap(rFillBitmap
)
443 bool PolyPolygonBitmapPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
445 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
447 const PolyPolygonBitmapPrimitive2D
& rCompare
= (PolyPolygonBitmapPrimitive2D
&)rPrimitive
;
449 return (getFillBitmap() == rCompare
.getFillBitmap());
456 ImplPrimitive2DIDBlock(PolyPolygonBitmapPrimitive2D
, PRIMITIVE2D_ID_POLYPOLYGONBITMAPPRIMITIVE2D
)
458 } // end of namespace primitive2d
459 } // end of namespace drawinglayer
461 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */