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 .
21 #include <svx/sdr/overlay/overlaytools.hxx>
22 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
23 #include <basegfx/matrix/b2dhommatrix.hxx>
24 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
26 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
27 #include <basegfx/polygon/b2dpolygontools.hxx>
28 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
29 #include <drawinglayer/geometry/viewinformation2d.hxx>
30 #include <basegfx/matrix/b2dhommatrixtools.hxx>
32 //////////////////////////////////////////////////////////////////////////////
34 namespace drawinglayer
38 OverlayBitmapExPrimitive::OverlayBitmapExPrimitive(
39 const BitmapEx
& rBitmapEx
,
40 const basegfx::B2DPoint
& rBasePosition
,
43 : DiscreteMetricDependentPrimitive2D(),
44 maBitmapEx(rBitmapEx
),
45 maBasePosition(rBasePosition
),
50 Primitive2DSequence
OverlayBitmapExPrimitive::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
52 Primitive2DSequence aRetval
;
53 const Size
aBitmapSize(getBitmapEx().GetSizePixel());
55 if(aBitmapSize
.Width() && aBitmapSize
.Height() && basegfx::fTools::more(getDiscreteUnit(), 0.0))
57 // calculate back from internal bitmap's extreme coordinates (the edges)
58 // to logical coordinates. Only use a unified scaling value (getDiscreteUnit(),
59 // the prepared one which expresses how many logic units form a discrete unit)
60 // for this step. This primitive is to be displayed always unscaled (in it's pixel size)
61 // and unrotated, more like a marker
62 const double fLeft(((0.0 - getCenterX()) * getDiscreteUnit()) + getBasePosition().getX());
63 const double fTop(((0.0 - getCenterY()) * getDiscreteUnit()) + getBasePosition().getY());
64 const double fRight(((aBitmapSize
.getWidth() - getCenterX()) * getDiscreteUnit()) + getBasePosition().getX());
65 const double fBottom(((aBitmapSize
.getHeight() - getCenterY()) * getDiscreteUnit()) + getBasePosition().getY());
67 // create a BitmapPrimitive2D using those positions
68 basegfx::B2DHomMatrix aTransform
;
70 aTransform
.set(0, 0, fRight
- fLeft
);
71 aTransform
.set(1, 1, fBottom
- fTop
);
72 aTransform
.set(0, 2, fLeft
);
73 aTransform
.set(1, 2, fTop
);
75 const Primitive2DReference
aPrimitive(new BitmapPrimitive2D(getBitmapEx(), aTransform
));
76 aRetval
= Primitive2DSequence(&aPrimitive
, 1);
82 bool OverlayBitmapExPrimitive::operator==( const BasePrimitive2D
& rPrimitive
) const
84 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive
))
86 const OverlayBitmapExPrimitive
& rCompare
= static_cast< const OverlayBitmapExPrimitive
& >(rPrimitive
);
88 return (getBitmapEx() == rCompare
.getBitmapEx()
89 && getBasePosition() == rCompare
.getBasePosition()
90 && getCenterX() == rCompare
.getCenterX()
91 && getCenterY() == rCompare
.getCenterY());
97 ImplPrimitive2DIDBlock(OverlayBitmapExPrimitive
, PRIMITIVE2D_ID_OVERLAYBITMAPEXPRIMITIVE
)
99 } // end of namespace primitive2d
100 } // end of namespace drawinglayer
102 //////////////////////////////////////////////////////////////////////////////
104 namespace drawinglayer
106 namespace primitive2d
108 OverlayCrosshairPrimitive::OverlayCrosshairPrimitive(
109 const basegfx::B2DPoint
& rBasePosition
,
110 const basegfx::BColor
& rRGBColorA
,
111 const basegfx::BColor
& rRGBColorB
,
112 double fDiscreteDashLength
)
113 : ViewportDependentPrimitive2D(),
114 maBasePosition(rBasePosition
),
115 maRGBColorA(rRGBColorA
),
116 maRGBColorB(rRGBColorB
),
117 mfDiscreteDashLength(fDiscreteDashLength
)
120 Primitive2DSequence
OverlayCrosshairPrimitive::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
122 // use the prepared Viewport information accessible using getViewport()
123 Primitive2DSequence aRetval
;
125 if(!getViewport().isEmpty())
128 basegfx::B2DPolygon aPolygon
;
130 aPolygon
.append(basegfx::B2DPoint(getViewport().getMinX(), getBasePosition().getY()));
131 aPolygon
.append(basegfx::B2DPoint(getViewport().getMaxX(), getBasePosition().getY()));
133 aRetval
[0] = Primitive2DReference(
134 new PolygonMarkerPrimitive2D(
138 getDiscreteDashLength()));
141 aPolygon
.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMinY()));
142 aPolygon
.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMaxY()));
144 aRetval
[1] = Primitive2DReference(
145 new PolygonMarkerPrimitive2D(
149 getDiscreteDashLength()));
155 bool OverlayCrosshairPrimitive::operator==( const BasePrimitive2D
& rPrimitive
) const
157 if(ViewportDependentPrimitive2D::operator==(rPrimitive
))
159 const OverlayCrosshairPrimitive
& rCompare
= static_cast< const OverlayCrosshairPrimitive
& >(rPrimitive
);
161 return (getBasePosition() == rCompare
.getBasePosition()
162 && getRGBColorA() == rCompare
.getRGBColorA()
163 && getRGBColorB() == rCompare
.getRGBColorB()
164 && getDiscreteDashLength() == rCompare
.getDiscreteDashLength());
170 ImplPrimitive2DIDBlock(OverlayCrosshairPrimitive
, PRIMITIVE2D_ID_OVERLAYCROSSHAIRPRIMITIVE
)
172 } // end of namespace primitive2d
173 } // end of namespace drawinglayer
175 //////////////////////////////////////////////////////////////////////////////
177 namespace drawinglayer
179 namespace primitive2d
181 OverlayHatchRectanglePrimitive::OverlayHatchRectanglePrimitive(
182 const basegfx::B2DRange
& rObjectRange
,
183 double fDiscreteHatchDistance
,
184 double fHatchRotation
,
185 const basegfx::BColor
& rHatchColor
,
186 double fDiscreteGrow
,
187 double fDiscreteShrink
,
189 : DiscreteMetricDependentPrimitive2D(),
190 maObjectRange(rObjectRange
),
191 mfDiscreteHatchDistance(fDiscreteHatchDistance
),
192 mfHatchRotation(fHatchRotation
),
193 maHatchColor(rHatchColor
),
194 mfDiscreteGrow(fDiscreteGrow
),
195 mfDiscreteShrink(fDiscreteShrink
),
196 mfRotation(fRotation
)
199 Primitive2DSequence
OverlayHatchRectanglePrimitive::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
201 Primitive2DSequence aRetval
;
203 if(basegfx::fTools::more(getDiscreteUnit(), 0.0))
205 basegfx::B2DRange
aInnerRange(getObjectRange());
206 basegfx::B2DRange
aOuterRange(getObjectRange());
207 basegfx::B2DPolyPolygon aHatchPolyPolygon
;
209 aOuterRange
.grow(getDiscreteUnit() * getDiscreteGrow());
210 aInnerRange
.grow(getDiscreteUnit() * -getDiscreteShrink());
212 aHatchPolyPolygon
.append(basegfx::tools::createPolygonFromRect(aOuterRange
));
214 if(!aInnerRange
.isEmpty())
216 aHatchPolyPolygon
.append(basegfx::tools::createPolygonFromRect(aInnerRange
));
219 if(!basegfx::fTools::equalZero(getRotation()))
221 const basegfx::B2DHomMatrix
aTransform(basegfx::tools::createRotateAroundPoint(
222 getObjectRange().getMinX(), getObjectRange().getMinY(), getRotation()));
224 aHatchPolyPolygon
.transform(aTransform
);
227 const basegfx::BColor
aEmptyColor(0.0, 0.0, 0.0);
228 const drawinglayer::attribute::FillHatchAttribute
aFillHatchAttribute(
229 drawinglayer::attribute::HATCHSTYLE_SINGLE
,
230 getDiscreteHatchDistance() * getDiscreteUnit(),
231 getHatchRotation() - getRotation(),
233 3, // same default as VCL, a minimum of three discrete units (pixels) offset
235 const Primitive2DReference
aPrimitive(
236 new PolyPolygonHatchPrimitive2D(
239 aFillHatchAttribute
));
241 aRetval
= Primitive2DSequence(&aPrimitive
, 1);
247 bool OverlayHatchRectanglePrimitive::operator==( const BasePrimitive2D
& rPrimitive
) const
249 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive
))
251 const OverlayHatchRectanglePrimitive
& rCompare
= static_cast< const OverlayHatchRectanglePrimitive
& >(rPrimitive
);
253 return (getObjectRange() == rCompare
.getObjectRange()
254 && getDiscreteHatchDistance() == rCompare
.getDiscreteHatchDistance()
255 && getHatchRotation() == rCompare
.getHatchRotation()
256 && getHatchColor() == rCompare
.getHatchColor()
257 && getDiscreteGrow() == rCompare
.getDiscreteGrow()
258 && getDiscreteShrink() == rCompare
.getDiscreteShrink()
259 && getRotation() == rCompare
.getRotation());
265 ImplPrimitive2DIDBlock(OverlayHatchRectanglePrimitive
, PRIMITIVE2D_ID_OVERLAYHATCHRECTANGLEPRIMITIVE
)
267 } // end of namespace primitive2d
268 } // end of namespace drawinglayer
270 //////////////////////////////////////////////////////////////////////////////
272 namespace drawinglayer
274 namespace primitive2d
276 OverlayHelplineStripedPrimitive::OverlayHelplineStripedPrimitive(
277 const basegfx::B2DPoint
& rBasePosition
,
278 HelplineStyle eStyle
,
279 const basegfx::BColor
& rRGBColorA
,
280 const basegfx::BColor
& rRGBColorB
,
281 double fDiscreteDashLength
)
282 : ViewportDependentPrimitive2D(),
283 maBasePosition(rBasePosition
),
285 maRGBColorA(rRGBColorA
),
286 maRGBColorB(rRGBColorB
),
287 mfDiscreteDashLength(fDiscreteDashLength
)
290 Primitive2DSequence
OverlayHelplineStripedPrimitive::create2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
292 // use the prepared Viewport information accessible using getViewport()
293 Primitive2DSequence aRetval
;
295 if(!getViewport().isEmpty())
299 case HELPLINESTYLE_VERTICAL
:
302 basegfx::B2DPolygon aLine
;
304 aLine
.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMinY()));
305 aLine
.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMaxY()));
307 aRetval
[0] = Primitive2DReference(
308 new PolygonMarkerPrimitive2D(
312 getDiscreteDashLength()));
316 case HELPLINESTYLE_HORIZONTAL
:
319 basegfx::B2DPolygon aLine
;
321 aLine
.append(basegfx::B2DPoint(getViewport().getMinX(), getBasePosition().getY()));
322 aLine
.append(basegfx::B2DPoint(getViewport().getMaxX(), getBasePosition().getY()));
324 aRetval
[0] = Primitive2DReference(
325 new PolygonMarkerPrimitive2D(
329 getDiscreteDashLength()));
333 default: // case HELPLINESTYLE_POINT :
335 const double fDiscreteUnit((rViewInformation
.getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 0.0)).getLength());
337 basegfx::B2DPolygon aLineA
, aLineB
;
339 aLineA
.append(basegfx::B2DPoint(getBasePosition().getX(), getBasePosition().getY() - fDiscreteUnit
));
340 aLineA
.append(basegfx::B2DPoint(getBasePosition().getX(), getBasePosition().getY() + fDiscreteUnit
));
342 aRetval
[0] = Primitive2DReference(
343 new PolygonMarkerPrimitive2D(
347 getDiscreteDashLength()));
349 aLineB
.append(basegfx::B2DPoint(getBasePosition().getX() - fDiscreteUnit
, getBasePosition().getY()));
350 aLineB
.append(basegfx::B2DPoint(getBasePosition().getX() + fDiscreteUnit
, getBasePosition().getY()));
352 aRetval
[1] = Primitive2DReference(
353 new PolygonMarkerPrimitive2D(
357 getDiscreteDashLength()));
367 bool OverlayHelplineStripedPrimitive::operator==( const BasePrimitive2D
& rPrimitive
) const
369 if(ViewportDependentPrimitive2D::operator==(rPrimitive
))
371 const OverlayHelplineStripedPrimitive
& rCompare
= static_cast< const OverlayHelplineStripedPrimitive
& >(rPrimitive
);
373 return (getBasePosition() == rCompare
.getBasePosition()
374 && getStyle() == rCompare
.getStyle()
375 && getRGBColorA() == rCompare
.getRGBColorA()
376 && getRGBColorB() == rCompare
.getRGBColorB()
377 && getDiscreteDashLength() == rCompare
.getDiscreteDashLength());
383 ImplPrimitive2DIDBlock(OverlayHelplineStripedPrimitive
, PRIMITIVE2D_ID_OVERLAYHELPLINESTRIPEDPRIMITIVE
)
385 } // end of namespace primitive2d
386 } // end of namespace drawinglayer
388 //////////////////////////////////////////////////////////////////////////////
390 namespace drawinglayer
392 namespace primitive2d
394 OverlayRollingRectanglePrimitive::OverlayRollingRectanglePrimitive(
395 const basegfx::B2DRange
& aRollingRectangle
,
396 const basegfx::BColor
& rRGBColorA
,
397 const basegfx::BColor
& rRGBColorB
,
398 double fDiscreteDashLength
)
399 : ViewportDependentPrimitive2D(),
400 maRollingRectangle(aRollingRectangle
),
401 maRGBColorA(rRGBColorA
),
402 maRGBColorB(rRGBColorB
),
403 mfDiscreteDashLength(fDiscreteDashLength
)
406 Primitive2DSequence
OverlayRollingRectanglePrimitive::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
408 // use the prepared Viewport information accessible using getViewport()
409 Primitive2DSequence aRetval
;
411 if(!getViewport().isEmpty())
413 basegfx::B2DPolygon aLine
;
417 aLine
.append(basegfx::B2DPoint(getViewport().getMinX(), getRollingRectangle().getMinY()));
418 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMinY()));
419 aRetval
[0] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
422 aLine
.append(basegfx::B2DPoint(getViewport().getMinX(), getRollingRectangle().getMaxY()));
423 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMaxY()));
424 aRetval
[1] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
428 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMinY()));
429 aLine
.append(basegfx::B2DPoint(getViewport().getMaxX(), getRollingRectangle().getMinY()));
430 aRetval
[2] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
433 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMaxY()));
434 aLine
.append(basegfx::B2DPoint(getViewport().getMaxX(), getRollingRectangle().getMaxY()));
435 aRetval
[3] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
439 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getViewport().getMinY()));
440 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMinY()));
441 aRetval
[4] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
444 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getViewport().getMinY()));
445 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMinY()));
446 aRetval
[5] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
450 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMaxY()));
451 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getViewport().getMaxY()));
452 aRetval
[6] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
455 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMaxY()));
456 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getViewport().getMaxY()));
457 aRetval
[7] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
463 bool OverlayRollingRectanglePrimitive::operator==( const BasePrimitive2D
& rPrimitive
) const
465 if(ViewportDependentPrimitive2D::operator==(rPrimitive
))
467 const OverlayRollingRectanglePrimitive
& rCompare
= static_cast< const OverlayRollingRectanglePrimitive
& >(rPrimitive
);
469 return (getRollingRectangle() == rCompare
.getRollingRectangle()
470 && getRGBColorA() == rCompare
.getRGBColorA()
471 && getRGBColorB() == rCompare
.getRGBColorB()
472 && getDiscreteDashLength() == rCompare
.getDiscreteDashLength());
478 ImplPrimitive2DIDBlock(OverlayRollingRectanglePrimitive
, PRIMITIVE2D_ID_OVERLAYROLLINGRECTANGLEPRIMITIVE
)
480 } // end of namespace primitive2d
481 } // end of namespace drawinglayer
483 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */